Example usage for org.eclipse.jdt.core.dom Name getLength

List of usage examples for org.eclipse.jdt.core.dom Name getLength

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Name getLength.

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:br.uff.ic.gems.resources.ast.Visitor.java

public boolean visit(Name node) {
    int beginLine = cu.getLineNumber(node.getStartPosition());
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = cu.getColumnNumber(node.getStartPosition());
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    languageConstructs.add(//w  ww  .  ja  v a 2 s.  c  o  m
            new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn));

    return true;
}

From source file:ca.mcgill.cs.swevo.ppa.PPANameVisitor.java

License:Open Source License

public static String getKey(Name node) {
    return node.getFullyQualifiedName() + "" + node.getStartPosition() + "" + node.getLength();
}

From source file:com.google.gwt.eclipse.core.refactoring.regionupdater.NameRegionUpdater.java

License:Open Source License

@Override
protected ReplaceEdit createUpdatedEditForEquivalentNode(Name equivalentNode) throws RefactoringException {
    return new ReplaceEdit(equivalentNode.getStartPosition(), equivalentNode.getLength(),
            getOriginalEdit().getText());
}

From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java

License:Open Source License

public static void addNewTypeProposals(ICompilationUnit cu, Name refNode, int kind, int relevance,
        Map<String, LinkedCorrectionProposal> proposals) throws CoreException {
    Name node = refNode;/*from  w w w  . java 2 s.com*/
    //      do {
    String typeName = ASTNodes.getSimpleNameIdentifier(node);
    Name qualifier = null;
    // only propose to create types for qualifiers when the name starts with upper case
    boolean isPossibleName = isLikelyTypeName(typeName) || node == refNode;
    if (isPossibleName) {
        IPackageFragment enclosingPackage = null;
        IType enclosingType = null;
        if (node.isSimpleName()) {
            enclosingPackage = (IPackageFragment) cu.getParent();
            return;
            // don't suggest member type, user can select it in wizard
        } else {
            Name qualifierName = ((QualifiedName) node).getQualifier();
            IBinding binding = qualifierName.resolveBinding();
            if (binding != null && binding.isRecovered()) {
                binding = null;
            }
            if (binding instanceof ITypeBinding) {
                enclosingType = (IType) binding.getJavaElement();
            } else if (binding instanceof IPackageBinding) {
                qualifier = qualifierName;
                enclosingPackage = (IPackageFragment) binding.getJavaElement();
            } else {
                IJavaElement[] res = cu.codeSelect(qualifierName.getStartPosition(), qualifierName.getLength());
                if (res != null && res.length > 0 && res[0] instanceof IType) {
                    enclosingType = (IType) res[0];
                } else {
                    qualifier = qualifierName;
                    enclosingPackage = JavaModelUtil.getPackageFragmentRoot(cu)
                            .getPackageFragment(ASTResolving.getFullName(qualifierName));
                }
            }
        }
        int rel = relevance;
        if (enclosingPackage != null && isLikelyPackageName(enclosingPackage.getElementName())) {
            rel += 3;
        }

        if (enclosingPackage != null
                && !enclosingPackage.getCompilationUnit(typeName + JavaModelUtil.DEFAULT_CU_SUFFIX).exists()
                || enclosingType != null && !enclosingType.isReadOnly()
                        && !enclosingType.getType(typeName).exists()) { // new member type
            IJavaElement enclosing = enclosingPackage != null ? (IJavaElement) enclosingPackage : enclosingType;

            String name = node.getFullyQualifiedName();

            if ((kind & SimilarElementsRequestor.CLASSES) != 0) {
                proposals.put(name, new NewCUProposal(cu, node, NewCUProposal.K_CLASS, enclosing, rel + 3));
            } else if ((kind & SimilarElementsRequestor.INTERFACES) != 0) {
                proposals.put(name, new NewCUProposal(cu, node, NewCUProposal.K_INTERFACE, enclosing, rel + 2));
            } else if ((kind & SimilarElementsRequestor.ENUMS) != 0) {
                proposals.put(name, new NewCUProposal(cu, node, NewCUProposal.K_ENUM, enclosing, rel));
            }
        }
    }
    node = qualifier;
    //      } while (node != null);
}

From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIContextNodeCreationTest.java

License:Open Source License

public void testNewName2() throws Exception {
    String source = getSource("original", "NewContactSwingTest.txt");
    WTConvertAPIContext context = new WTConvertAPIContextBuilder().buildContext(source);
    Name actual = context.newName("fully.qualified.TestClass", 83);
    assertTrue(actual instanceof QualifiedName);
    QualifiedName name = (QualifiedName) actual;
    assertEquals(83, name.getStartPosition());
    assertEquals(25, name.getLength());//from   ww  w .j av a  2 s. com
    Name qualifier = name.getQualifier();
    assertEquals(83, qualifier.getStartPosition());
    assertEquals(15, qualifier.getLength());
    assertEquals(99, name.getName().getStartPosition());
    assertEquals(9, name.getName().getLength());
}

From source file:org.bundlemaker.core.ui.editor.sourceviewer.referencedetail.JdtAstVisitor.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww w  . j a  va  2  s.co m
 */
@SuppressWarnings("unchecked")
@Override
public boolean visit(MethodDeclaration node) {

    // declared method return type
    Type returnType = node.getReturnType2();
    if (returnType != null) {
        resolveType(returnType);
    }
    // declared method argument types
    List<SingleVariableDeclaration> variableDeclarations = node.parameters();

    for (SingleVariableDeclaration singleVariableDeclaration : variableDeclarations) {
        resolveType(singleVariableDeclaration.getType());
    }

    // declared method exception types
    List<Name> exceptions = node.thrownExceptions();
    for (Name name : exceptions) {
        resolveTypeName(name, name.getStartPosition(), name.getLength());
    }

    // visit the child nodes
    return true;
}

From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.UnresolvedElementsSubProcessor.java

License:Open Source License

private static void addNewTypeProposals(ICompilationUnit cu, Name refNode, int kind, int relevance,
        Collection proposals) throws JavaModelException {
    Name node = refNode;//from ww w .  ja  v a 2 s. c o m
    do {
        String typeName = ASTNodes.getSimpleNameIdentifier(node);
        Name qualifier = null;
        // only propose to create types for qualifiers when the name starts with upper case
        boolean isPossibleName = isLikelyTypeName(typeName) || (node == refNode);
        if (isPossibleName) {
            IPackageFragment enclosingPackage = null;
            IType enclosingType = null;
            if (node.isSimpleName()) {
                enclosingPackage = (IPackageFragment) cu.getParent();
                // don't suggest member type, user can select it in wizard
            } else {
                Name qualifierName = ((QualifiedName) node).getQualifier();
                IBinding binding = qualifierName.resolveBinding();
                if (binding instanceof ITypeBinding) {
                    enclosingType = (IType) binding.getJavaElement();
                } else if (binding instanceof IPackageBinding) {
                    qualifier = qualifierName;
                    enclosingPackage = (IPackageFragment) binding.getJavaElement();
                } else {
                    IJavaElement[] res = cu.codeSelect(qualifierName.getStartPosition(),
                            qualifierName.getLength());
                    if (res != null && res.length > 0 && res[0] instanceof IType) {
                        enclosingType = (IType) res[0];
                    } else {
                        qualifier = qualifierName;
                        enclosingPackage = JavaModelUtil.getPackageFragmentRoot(cu)
                                .getPackageFragment(ASTResolving.getFullName(qualifierName));
                    }
                }
            }
            int rel = relevance;
            if (enclosingPackage != null && isLikelyPackageName(enclosingPackage.getElementName())) {
                rel += 3;
            }

            if ((enclosingPackage != null && !enclosingPackage
                    .getCompilationUnit(typeName + JavaModelUtil.DEFAULT_CU_SUFFIX).exists()) // new top level type
                    || (enclosingType != null && !enclosingType.isReadOnly()
                            && !enclosingType.getType(typeName).exists())) { // new member type
                IJavaElement enclosing = enclosingPackage != null ? (IJavaElement) enclosingPackage
                        : enclosingType;

                if ((kind & SimilarElementsRequestor.CLASSES) != 0) {
                    proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_CLASS,
                            enclosing, rel + 2));
                }
                if ((kind & SimilarElementsRequestor.INTERFACES) != 0) {
                    proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_INTERFACE,
                            enclosing, rel + 1));
                }
                if ((kind & SimilarElementsRequestor.ENUMS) != 0) {
                    proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_ENUM,
                            enclosing, rel));
                }
                if (kind == SimilarElementsRequestor.ANNOTATIONS) { // only when in annotation
                    proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_ANNOTATION,
                            enclosing, rel + 4));
                }
            }
        }
        node = qualifier;
    } while (node != null);

    // type parameter proposals
    if (refNode.isSimpleName() && ((kind & SimilarElementsRequestor.VARIABLES) != 0)) {
        CompilationUnit root = (CompilationUnit) refNode.getRoot();
        String name = ((SimpleName) refNode).getIdentifier();
        BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(refNode);
        int baseRel = relevance;
        if (isLikelyTypeParameterName(name)) {
            baseRel += 4;
        }
        while (declaration != null) {
            IBinding binding = null;
            int rel = baseRel;
            if (declaration instanceof MethodDeclaration) {
                binding = ((MethodDeclaration) declaration).resolveBinding();
            } else if (declaration instanceof TypeDeclaration) {
                binding = ((TypeDeclaration) declaration).resolveBinding();
                rel++;
            }
            if (binding != null) {
                AddTypeParameterProposal proposal = new AddTypeParameterProposal(cu, binding, root, name, null,
                        rel);
                proposals.add(proposal);
            }
            if (!Modifier.isStatic(declaration.getModifiers())) {
                declaration = ASTResolving.findParentBodyDeclaration(declaration.getParent());
            } else {
                declaration = null;
            }
        }
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public ASTNode convert(boolean isInterface,
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) {
    checkCanceled();//  ww  w.j  av a2s.  co m
    if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) {
        return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
    }
    MethodDeclaration methodDecl = new MethodDeclaration(this.ast);
    setModifiers(methodDecl, methodDeclaration);
    boolean isConstructor = methodDeclaration.isConstructor();
    methodDecl.setConstructor(isConstructor);
    final SimpleName methodName = new SimpleName(this.ast);
    methodName.internalSetIdentifier(new String(methodDeclaration.selector));
    int start = methodDeclaration.sourceStart;
    // GROOVY start
    // why does this do what it does?
    /* old {
    int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
    } new */
    int end = (scannerAvailable(methodDeclaration.scope)
            ? retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd)
            : methodDeclaration.sourceEnd);
    // GROOVY end
    methodName.setSourceRange(start, end - start + 1);
    methodDecl.setName(methodName);
    org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
    int methodHeaderEnd = methodDeclaration.sourceEnd;
    int thrownExceptionsLength = thrownExceptions == null ? 0 : thrownExceptions.length;
    if (thrownExceptionsLength > 0) {
        Name thrownException;
        int i = 0;
        do {
            thrownException = convert(thrownExceptions[i++]);
            methodDecl.thrownExceptions().add(thrownException);
        } while (i < thrownExceptionsLength);
        methodHeaderEnd = thrownException.getStartPosition() + thrownException.getLength();
    }
    org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments;
    int parametersLength = parameters == null ? 0 : parameters.length;
    if (parametersLength > 0) {
        SingleVariableDeclaration parameter;
        int i = 0;
        do {
            // GROOVY start
            // make sure the scope is available just in case it is necessary for varargs
            // new code
            BlockScope origScope = null;
            if (parameters[i].binding != null) {
                origScope = parameters[i].binding.declaringScope;
                parameters[i].binding.declaringScope = methodDeclaration.scope;
            }
            // GROOVY end

            parameter = convert(parameters[i++]);

            // GROOVY start
            // unset the scope
            // new code
            if (parameters[i - 1].binding != null) {
                parameters[i - 1].binding.declaringScope = origScope;
            }
            // GROOVY end
            methodDecl.parameters().add(parameter);
        } while (i < parametersLength);
        if (thrownExceptionsLength == 0) {
            methodHeaderEnd = parameter.getStartPosition() + parameter.getLength();
        }
    }
    org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null;
    if (isConstructor) {
        if (isInterface) {
            // interface cannot have a constructor
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
        }
        org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration;
        explicitConstructorCall = constructorDeclaration.constructorCall;
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            // set the return type to VOID
            PrimitiveType returnType = new PrimitiveType(this.ast);
            returnType.setPrimitiveTypeCode(PrimitiveType.VOID);
            returnType.setSourceRange(methodDeclaration.sourceStart, 0);
            methodDecl.internalSetReturnType(returnType);
            break;
        default:
            methodDecl.setReturnType2(null);
        }
    } else if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) {
        org.eclipse.jdt.internal.compiler.ast.MethodDeclaration method = (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) methodDeclaration;
        org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = method.returnType;
        if (typeReference != null) {
            Type returnType = convertType(typeReference);
            // get the positions of the right parenthesis
            int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd);
            int extraDimensions = retrieveExtraDimension(rightParenthesisPosition, method.bodyEnd);
            methodDecl.setExtraDimensions(extraDimensions);
            setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions);
        } else {
            // no return type for a method that is not a constructor
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                break;
            default:
                methodDecl.setReturnType2(null);
            }
        }
    }
    int declarationSourceStart = methodDeclaration.declarationSourceStart;
    int bodyEnd = methodDeclaration.bodyEnd;
    methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1);
    int declarationSourceEnd = methodDeclaration.declarationSourceEnd;
    int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1;
    int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart,
            declarationSourceEnd);
    if (closingPosition != -1) {
        int startPosition = methodDecl.getStartPosition();
        methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);

        org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements;

        start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart);
        if (start == -1)
            start = methodDeclaration.bodyStart; // use recovery position for body start
        end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd);
        Block block = null;
        if (start != -1 && end != -1) {
            /*
             * start or end can be equal to -1 if we have an interface's method.
             */
            block = new Block(this.ast);
            block.setSourceRange(start, closingPosition - start + 1);
            methodDecl.setBody(block);
        }
        if (block != null && (statements != null || explicitConstructorCall != null)) {
            if (explicitConstructorCall != null
                    && explicitConstructorCall.accessMode != org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.ImplicitSuper) {
                block.statements().add(convert(explicitConstructorCall));
            }
            int statementsLength = statements == null ? 0 : statements.length;
            for (int i = 0; i < statementsLength; i++) {
                if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
                    checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
                } else {
                    final Statement statement = convert(statements[i]);
                    if (statement != null) {
                        block.statements().add(statement);
                    }
                }
            }
        }
        if (block != null && (Modifier.isAbstract(methodDecl.getModifiers())
                || Modifier.isNative(methodDecl.getModifiers()) || isInterface)) {
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
        }
    } else {
        // syntax error in this method declaration
        methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
        if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
            start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd);
            if (start == -1)
                start = methodDeclaration.bodyStart; // use recovery position for body start
            end = methodDeclaration.bodyEnd;
            // try to get the best end position
            CategorizedProblem[] problems = methodDeclaration.compilationResult().problems;
            if (problems != null) {
                for (int i = 0, max = methodDeclaration.compilationResult().problemCount; i < max; i++) {
                    CategorizedProblem currentProblem = problems[i];
                    if (currentProblem.getSourceStart() == start
                            && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) {
                        end = currentProblem.getSourceEnd();
                        break;
                    }
                }
            }
            int startPosition = methodDecl.getStartPosition();
            methodDecl.setSourceRange(startPosition, end - startPosition + 1);
            if (start != -1 && end != -1) {
                /*
                 * start or end can be equal to -1 if we have an interface's method.
                 */
                Block block = new Block(this.ast);
                block.setSourceRange(start, end - start + 1);
                methodDecl.setBody(block);
            }
        }
    }

    org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters();
    if (typeParameters != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = typeParameters.length; i < max; i++) {
                methodDecl.typeParameters().add(convert(typeParameters[i]));
            }
        }
    }

    // The javadoc comment is now got from list store in compilation unit declaration
    convert(methodDeclaration.javadoc, methodDecl);
    if (this.resolveBindings) {
        recordNodes(methodDecl, methodDeclaration);
        recordNodes(methodName, methodDeclaration);
        methodDecl.resolveBinding();
    }
    return methodDecl;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void recordNodes(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, TagElement tagElement) {
    Iterator fragments = tagElement.fragments().listIterator();
    while (fragments.hasNext()) {
        ASTNode node = (ASTNode) fragments.next();
        if (node.getNodeType() == ASTNode.MEMBER_REF) {
            MemberRef memberRef = (MemberRef) node;
            Name name = memberRef.getName();
            // get compiler node and record nodes
            int start = name.getStartPosition();
            org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode = javadoc.getNodeStartingAt(start);
            if (compilerNode != null) {
                recordNodes(name, compilerNode);
                recordNodes(node, compilerNode);
            }//from   w ww. j  av  a 2  s .  co m
            // Replace qualifier to have all nodes recorded
            if (memberRef.getQualifier() != null) {
                org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = null;
                if (compilerNode instanceof JavadocFieldReference) {
                    org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocFieldReference) compilerNode).receiver;
                    if (expression instanceof org.eclipse.jdt.internal.compiler.ast.TypeReference) {
                        typeRef = (org.eclipse.jdt.internal.compiler.ast.TypeReference) expression;
                    }
                } else if (compilerNode instanceof JavadocMessageSend) {
                    org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver;
                    if (expression instanceof org.eclipse.jdt.internal.compiler.ast.TypeReference) {
                        typeRef = (org.eclipse.jdt.internal.compiler.ast.TypeReference) expression;
                    }
                }
                if (typeRef != null) {
                    recordName(memberRef.getQualifier(), typeRef);
                }
            }
        } else if (node.getNodeType() == ASTNode.METHOD_REF) {
            MethodRef methodRef = (MethodRef) node;
            Name name = methodRef.getName();
            // get method name start position
            int start = methodRef.getStartPosition();
            this.scanner.resetTo(start, start + name.getStartPosition() + name.getLength());
            int token;
            try {
                nextToken: while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF
                        && token != TerminalTokens.TokenNameLPAREN) {
                    if (token == TerminalTokens.TokenNameERROR && this.scanner.currentCharacter == '#') {
                        start = this.scanner.getCurrentTokenEndPosition() + 1;
                        break nextToken;
                    }
                }
            } catch (InvalidInputException e) {
                // ignore
            }
            // get compiler node and record nodes
            org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode = javadoc.getNodeStartingAt(start);
            // record nodes
            if (compilerNode != null) {
                recordNodes(methodRef, compilerNode);
                // get type ref
                org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = null;
                if (compilerNode instanceof org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) {
                    typeRef = ((org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) compilerNode).type;
                    if (typeRef != null)
                        recordNodes(name, compilerNode);
                } else if (compilerNode instanceof org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend) {
                    org.eclipse.jdt.internal.compiler.ast.Expression expression = ((org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend) compilerNode).receiver;
                    if (expression instanceof org.eclipse.jdt.internal.compiler.ast.TypeReference) {
                        typeRef = (org.eclipse.jdt.internal.compiler.ast.TypeReference) expression;
                    }
                    recordNodes(name, compilerNode);
                }
                // record name and qualifier
                if (typeRef != null && methodRef.getQualifier() != null) {
                    recordName(methodRef.getQualifier(), typeRef);
                }
            }
            // Resolve parameters
            Iterator parameters = methodRef.parameters().listIterator();
            while (parameters.hasNext()) {
                MethodRefParameter param = (MethodRefParameter) parameters.next();
                org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.eclipse.jdt.internal.compiler.ast.Expression) javadoc
                        .getNodeStartingAt(param.getStartPosition());
                if (expression != null) {
                    recordNodes(param, expression);
                    if (expression instanceof JavadocArgumentExpression) {
                        JavadocArgumentExpression argExpr = (JavadocArgumentExpression) expression;
                        org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = argExpr.argument.type;
                        if (this.ast.apiLevel >= AST.JLS3) {
                            param.setVarargs(argExpr.argument.isVarArgs());
                        }
                        recordNodes(param.getType(), typeRef);
                        if (param.getType().isSimpleType()) {
                            recordName(((SimpleType) param.getType()).getName(), typeRef);
                        } else if (param.getType().isArrayType()) {
                            Type type = ((ArrayType) param.getType()).getElementType();
                            recordNodes(type, typeRef);
                            if (type.isSimpleType()) {
                                recordName(((SimpleType) type).getName(), typeRef);
                            }
                        }
                    }
                }
            }
        } else if (node.getNodeType() == ASTNode.SIMPLE_NAME || node.getNodeType() == ASTNode.QUALIFIED_NAME) {
            org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode = javadoc
                    .getNodeStartingAt(node.getStartPosition());
            recordName((Name) node, compilerNode);
        } else if (node.getNodeType() == ASTNode.TAG_ELEMENT) {
            // resolve member and method references binding
            recordNodes(javadoc, (TagElement) node);
        }
    }
}

From source file:org.jboss.windup.rules.apps.java.scan.ast.VariableResolvingASTVisitor.java

License:Open Source License

@Override
public boolean visit(MethodDeclaration node) {
    // get a method's return type.
    Type returnType = node.getReturnType2();
    if (returnType != null) {
        processType(returnType, TypeReferenceLocation.RETURN_TYPE);
    }/*from w w  w. j av  a2  s . c o  m*/

    @SuppressWarnings("unchecked")
    List<SingleVariableDeclaration> parameters = (List<SingleVariableDeclaration>) node.parameters();
    if (parameters != null) {
        for (SingleVariableDeclaration type : parameters) {
            // make it fully qualified.
            String typeName = type.getType().toString();
            typeName = resolveClassname(typeName);
            // now add it as a local variable.
            this.names.add(type.getName().toString());
            this.nameInstance.put(type.getName().toString(), typeName);

            processType(type.getType(), TypeReferenceLocation.METHOD_PARAMETER);
        }
    }

    @SuppressWarnings("unchecked")
    List<Name> throwsTypes = node.thrownExceptions();
    if (throwsTypes != null) {
        for (Name name : throwsTypes) {
            processName(name, TypeReferenceLocation.THROWS_METHOD_DECLARATION,
                    cu.getLineNumber(node.getStartPosition()), cu.getColumnNumber(name.getStartPosition()),
                    name.getLength());
        }
    }

    return super.visit(node);
}