Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.Document


   * Method processElement.
   * @param unit
   * @param source
   */
  private String processElement(ICompilationUnit unit, char[] source) {
    Document document = new Document(new String(source));
    CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true));
    ASTParser parser = ASTParser.newParser(this.apiLevel);
    parser.setCompilerOptions(options.getMap());
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(false);
    org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit ast = (org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
       
    ASTRewrite rewriter= sortCompilationUnit(ast, null);
    if (rewriter == null)
      return document.get();
   
    TextEdit edits = rewriter.rewriteAST(document, null);
   
    RangeMarker[] markers = null;
    if (this.positions != null) {
      markers = new RangeMarker[this.positions.length];
      for (int i = 0, max = this.positions.length; i < max; i++) {
        markers[i]= new RangeMarker(this.positions[i], 0);
        insert(edits, markers[i]);
      }
    }
    try {
      edits.apply(document, TextEdit.UPDATE_REGIONS);
      if (this.positions != null) {
        for (int i= 0, max = markers.length; i < max; i++) {
          this.positions[i]= markers[i].getOffset();
        }
      }
    } catch (BadLocationException e) {
      // ignore
    }
    return document.get();
  }
View Full Code Here


  /**
   * Format the given Java source file.
   */
  private void formatFile(File file, CodeFormatter codeFormatter) {
    IDocument doc = new Document();
    try {
      // read the file
      if (this.verbose) {
        System.out.println(Messages.bind(Messages.CommandLineFormatting, file.getAbsolutePath()));
      }
      String contents = new String(org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(file, null));
      // format the file (the meat and potatoes)
      doc.set(contents);
      TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, null);
      if (edit != null) {
        edit.apply(doc);
      } else {
        System.err.println(Messages.bind(Messages.FormatProblem, file.getAbsolutePath()));
        return;
      }

      // write the file
      final BufferedWriter out = new BufferedWriter(new FileWriter(file));
      try {
        out.write(doc.get());
        out.flush();
      } finally {
        try {
          out.close();
        } catch (IOException e) {
View Full Code Here

   * @throws IllegalArgumentException if the positions are not inside the
   *                 string
   */
  public static String evaluateFormatterEdit(String string, TextEdit edit, Position[] positions) {
    try {
      Document doc= createDocument(string, positions);
      edit.apply(doc, 0);
      if (positions != null) {
        for (int i= 0; i < positions.length; i++) {
          Assert.isTrue(!positions[i].isDeleted, "Position got deleted"); //$NON-NLS-1$
        }
      }
      return doc.get();
    } catch (BadLocationException e) {
      log(e); // bug in the formatter
      Assert.isTrue(false, "Formatter created edits with wrong positions: " + e.getMessage()); //$NON-NLS-1$
    }
    return null;
View Full Code Here

   * @param positions the positions
   * @return the document
   * @throws IllegalArgumentException
   */
  private static Document createDocument(String content, Position[] positions) throws IllegalArgumentException {
    Document doc= new Document(content);
    try {
      if (positions != null) {
        final String POS_CATEGORY= "myCategory"; //$NON-NLS-1$
       
        doc.addPositionCategory(POS_CATEGORY);
        doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {
          protected boolean notDeleted() {
            if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {
              fPosition.offset= fOffset + fLength; // deleted positions: set to end of remove
              return false;
            }
            return true;
          }
        });
        for (int i= 0; i < positions.length; i++) {
          try {
            doc.addPosition(POS_CATEGORY, positions[i]);
          } catch (BadLocationException e) {
            throw new IllegalArgumentException("Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + content.length());   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
          }
        }
      }
View Full Code Here

        if (file.exists()) {
            InputStream stream = file.getContents();
            byte[] bytes = readFully(stream);

            String string = new String(bytes, file.getCharset());
            return new Document(string);
        }
        return null;
    }
View Full Code Here

        this.document = document;
        this.lineCount = document.getNumberOfLines();
    }

    public PropertiesLineReader(String data) {
        this(new Document(data));
    }
View Full Code Here

        this.document = document;
        this.lineCount = document.getNumberOfLines();
    }

    public PropertiesLineReader(String data) {
        this(new Document(data));
    }
View Full Code Here

    @Override
    protected IDocument createDocument( Object element ) throws CoreException
    {
        input = getEntryEditorInput( element );
        IEntry entry = getEntryEditorInput( element ).getSharedWorkingCopy( editor );
        IDocument document = new Document();
        if ( entry != null )
        {
            setDocumentInput( document, entry );
        }
        setupDocument( document );
View Full Code Here

  protected final boolean updateReplacementString(final IDocument document, final char trigger, final int offset,
      final ImportRewrite importRw) throws CoreException, BadLocationException
  {
    try
    {
      Document recoveredDocument = new Document();
      CompilationUnit unit = getRecoveredAST(document, offset, recoveredDocument);
      initContext(offset, importRw, unit);

      ASTNode node = NodeFinder.perform(unit, offset, 1);
      AST ast = unit.getAST();
View Full Code Here

    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
    options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE);

    CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    TextEdit format = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
    IDocument document = new Document(text);
    format.apply(document);
    return document.get();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.