Example usage for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameIdentifier

List of usage examples for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameIdentifier

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameIdentifier.

Prototype

int TokenNameIdentifier

To view the source code for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameIdentifier.

Click Source Link

Usage

From source file:net.sourceforge.metrics.calculators.LackOfCohesion.java

License:Open Source License

private void visitMethods(IMethod[] methods) {
    boolean countStatics = getPrefs().countStaticMethods();
    for (IMethod method2 : methods) {
        String methodName = method2.getElementName();
        try {//from  w ww.  ja va 2  s. c o  m
            if ((countStatics) || ((method2.getFlags() & Flags.AccStatic) == 0)) {
                IScanner s = ToolFactory.createScanner(false, false, false, false);
                s.setSource(method2.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) {
            Log.logError("LCOM:Can't get source for method " + methodName, e);
        } catch (InvalidInputException e) {
            Log.logError("LCOM:Invalid scanner input for method" + methodName, e);
        }
    }
}

From source file:org.j2eespider.util.AnnotationUtil.java

License:Open Source License

private static int readName(IScanner scanner, StringBuffer buf) throws InvalidInputException {
    int tok = scanner.getNextToken();
    while (tok == ITerminalSymbols.TokenNameIdentifier) {
        buf.append(scanner.getCurrentTokenSource());
        tok = scanner.getNextToken();/*  www .  j av a 2  s.c  o  m*/
        if (tok != ITerminalSymbols.TokenNameDOT) {
            return tok;
        }
        buf.append('.');
        tok = scanner.getNextToken();
    }
    return tok;
}

From source file:seeit3d.java.modeler.generator.metrics.LCOMCalculator.java

License:Open Source License

private boolean methodUseField(IField field, IMethod method) throws JavaModelException {
    try {//from w w  w. j  a v a2 s. c o m
        String fieldName = field.getElementName();
        String methodSource = method.getSource();

        IScanner scanner = ToolFactory.createScanner(false, false, false, false);
        scanner.setSource(methodSource.toCharArray());
        while (true) {
            int token = scanner.getNextToken();
            if (token == ITerminalSymbols.TokenNameEOF)
                break;
            if (token == ITerminalSymbols.TokenNameIdentifier) {
                String identifier = new String(scanner.getCurrentTokenSource());
                if (identifier.equals(fieldName)) {
                    return true;
                }
            }
        }
    } catch (InvalidInputException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:seeit3d.java.modeler.generator.TypeClassModelGenerator.java

License:Open Source License

@Override
protected void extraOperationsOnContainer(Container createdContainer, IType element,
        boolean analizeDependencies) throws JavaModelException {
    if (analizeDependencies) {
        try {/*from w w w  .j  a  v  a2s.  c o m*/
            List<String> relatedTypesNames = new ArrayList<String>();
            List<String> resolvedTokens = new ArrayList<String>();

            IJavaProject project = element.getJavaProject();

            String source = element.getSource();

            IScanner scanner = ToolFactory.createScanner(false, false, false, false);
            scanner.setSource(source.toCharArray());

            while (true) {
                int token = scanner.getNextToken();
                if (token == ITerminalSymbols.TokenNameEOF) {
                    break;
                }
                if (token == ITerminalSymbols.TokenNameIdentifier) {
                    char[] currentTokenSource = scanner.getCurrentTokenSource();
                    String currentToken = new String(currentTokenSource);
                    if (!resolvedTokens.contains(currentToken)) {
                        String[][] resolveType = element.resolveType(currentToken);
                        if (resolveType != null) {
                            String elementName = resolveType[0][0] + "." + resolveType[0][1];
                            relatedTypesNames.add(elementName);
                        }
                        resolvedTokens.add(currentToken);
                    }
                }
            }

            for (String relatedTypeName : relatedTypesNames) {
                IType type = project.findType(relatedTypeName);
                if (type != null && !type.isBinary()) {
                    Container relatedContainer = this.analize(type, false);
                    createdContainer.addRelatedContainer(relatedContainer);
                }
            }
        } catch (InvalidInputException e) {
            e.printStackTrace();
        }
    }
}