Package org.eclipse.jdt.core.compiler

Examples of org.eclipse.jdt.core.compiler.IScanner


  /**
   * @param template Generated comment
   * @return Is `template' a valid comment?
   */
  protected boolean isValidComment(String template) {
    IScanner scanner = ToolFactory.createScanner(true, false, false, false);
    scanner.setSource(template.toCharArray());
    try {
      int next = scanner.getNextToken();
      while (TokenScanner.isComment(next)) {
        next = scanner.getNextToken();
      }
      return next == ITerminalSymbols.TokenNameEOF;
    } catch (InvalidInputException e) {
    }
    return false;
View Full Code Here


        return null;

    }

    private boolean isValidComment(String template) {
        IScanner scanner = ToolFactory.createScanner(true, false, false, false);
        scanner.setSource(template.toCharArray());
        try {
            int next = scanner.getNextToken();
            while (TokenScanner.isComment(next)) {
                next = scanner.getNextToken();
            }
            return next == ITerminalSymbols.TokenNameEOF;
        } catch (InvalidInputException e) {}
        return false;
    }
View Full Code Here

        return null;

    }

    private boolean isValidComment(String template) {
        IScanner scanner = ToolFactory.createScanner(true, false, false, false);
        scanner.setSource(template.toCharArray());
        try {
            int next = scanner.getNextToken();
            while (TokenScanner.isComment(next)) {
                next = scanner.getNextToken();
            }
            return next == ITerminalSymbols.TokenNameEOF;
        } catch (InvalidInputException e) {}
        return false;
    }
View Full Code Here

    public ISourceRange findIdentifier(ICompilationUnit theCU, int offset, int length) throws JavaModelException {
        return findTokenOfType(theCU, ITerminalSymbols.TokenNameIdentifier, offset, length);
    }
   
    public ISourceRange findTokenOfType(ICompilationUnit theCU, int tokenType, int offset, int length) throws JavaModelException {
        IScanner scanner = ToolFactory.createScanner(false, false, false, false);
        scanner.setSource(theCU.getSource().toCharArray());
        scanner.resetTo(offset, offset + length);
        int token;
        try {
            while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) {
                if (token == tokenType) {
                    return new SourceRange(scanner.getCurrentTokenStartPosition(),
                                           scanner.getCurrentTokenEndPosition() + 1 - scanner.getCurrentTokenStartPosition());
                }
            }
        } catch (InvalidInputException e) {
            throw new RuntimeException("Error finding token: "+e.getMessage(), e);
        }
View Full Code Here

    public static interface FoundToken {
        void found(int tokenType, int offset, int length);
    }
   
    public void scanTokens(ICompilationUnit theCU, int offset, int length, FoundToken callback) throws JavaModelException {
        IScanner scanner = ToolFactory.createScanner(false, false, false, false);
        scanner.setSource(theCU.getSource().toCharArray());
        scanner.resetTo(offset, offset + length);
        int token;
        try {
            while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) {
                callback.found(token, scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition() + 1 - scanner.getCurrentTokenStartPosition());
            }
        } catch (InvalidInputException e) {
            throw new RuntimeException("Error finding token: "+e.getMessage(), e);
        }
    }
View Full Code Here

    }

    private int calculateNumberOfLines(String source) {
      String sourceToAnalyze = source.trim();
      Set<Integer> lineSet = new HashSet<Integer>();
      IScanner scanner = ToolFactory.createScanner(false, false, true,
          true);
      scanner.setSource(sourceToAnalyze.toCharArray());
      try {
        while (true) {
          int token = scanner.getNextToken();
          if (token == ITerminalSymbols.TokenNameEOF)
            break;
          int startPosition = scanner.getCurrentTokenStartPosition();
          int lineNumber = scanner.getLineNumber(startPosition);
          lineSet.add(Integer.valueOf(lineNumber));
        }
      } catch (InvalidInputException e) {
        e.printStackTrace();
      }
View Full Code Here

      try {
        String sourceText = getSource(source).trim();
        Set<Integer> lineSet = new HashSet<Integer>();
        int commentLines = 0;
        int totalLines = 0;
        IScanner scanner = ToolFactory.createScanner(true, false, true,
            true);
        scanner.setSource(sourceText.toCharArray());
        try {
          while (true) {
            int token = scanner.getNextToken();
            if (token == ITerminalSymbols.TokenNameEOF) {
              int startPosition = scanner
                  .getCurrentTokenStartPosition();
              totalLines = scanner.getLineNumber(startPosition);
              break;
            }

            if ((token == ITerminalSymbols.TokenNameCOMMENT_LINE)
                || (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK)
                || (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC)) {
              commentLines++;
            } else {
              int startPosition = scanner
                  .getCurrentTokenStartPosition();
              int lineNumber = scanner
                  .getLineNumber(startPosition);
              lineSet.add(Integer.valueOf(lineNumber));
            }
          }
        } catch (InvalidInputException e) {
View Full Code Here

      for (int i = 0; i < methods.length; i++) {
        String methodName = methods[i].getElementName();
        try {
          if ((countStatics)
              || ((methods[i].getFlags() & Flags.AccStatic) == 0)) {
            IScanner s = ToolFactory.createScanner(false, false,
                false, false);
            s.setSource(methods[i].getSource().toCharArray());
            while (true) {
              int token = s.getNextToken();
              if (token == ITerminalSymbols.TokenNameEOF)
                break;
              if (token == ITerminalSymbols.TokenNameIdentifier) {
                add(new String(s.getCurrentTokenSource()),
                    methodName);
              }
            }
          }
        } catch (JavaModelException e) {
View Full Code Here

            return;
        }

        IField ifield = type.getField(field.getFieldName());
        ISourceRange sourceRange = null;
        IScanner scanner = null;
        JavaModelException ex = null;
        try {
            sourceRange = ifield.getNameRange();
        } catch (JavaModelException e) {
            ex = e;
        }
        try {
            // second try...
            if (sourceRange == null) {
                sourceRange = ifield.getSourceRange();
            }
            scanner = initScanner(type, sourceRange);
        } catch (JavaModelException e) {
            String message = "Can not complete field annotation " + field + " for the field: " + ifield + " in class: "
                    + qualifiedClassName + ", type " + type + ", bug " + bug;
            if (ex != null) {
                // report only first one
                e = ex;
            }
            FindbugsPlugin.getDefault().logMessage(IStatus.WARNING, message, e);
        }
        if (scanner == null || sourceRange == null) {
            return;
        }
        int lineNbr = scanner.getLineNumber(sourceRange.getOffset());
        lineNbr = lineNbr <= 0 ? 1 : lineNbr;
        String sourceFileStr = getSourceFileHint(type, qualifiedClassName);
        field.setSourceLines(new SourceLineAnnotation(qualifiedClassName, sourceFileStr, lineNbr, lineNbr, 0, 0));
    }
View Full Code Here

    private static int getLineStart(IType source) throws JavaModelException {
        ISourceRange range = source.getNameRange();
        if (range == null) {
            range = source.getSourceRange();
        }
        IScanner scanner = initScanner(source, range);
        if (scanner != null && range != null) {
            return scanner.getLineNumber(range.getOffset());
        }
        return START_LINE_OF_ENCLOSING_TYPE;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.compiler.IScanner

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.