Java 类org.eclipse.jdt.core.dom.SimpleName 实例源码

项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static SimpleName getLeftMostSimpleName(Name name) {
    if (name instanceof SimpleName) {
        return (SimpleName)name;
    } else {
        final SimpleName[] result= new SimpleName[1];
        ASTVisitor visitor= new ASTVisitor() {
            @Override
            public boolean visit(QualifiedName qualifiedName) {
                Name left= qualifiedName.getQualifier();
                if (left instanceof SimpleName) {
                    result[0]= (SimpleName)left;
                } else {
                    left.accept(this);
                }
                return false;
            }
        };
        name.accept(visitor);
        return result[0];
    }
}
项目:eclipse.jdt.ls    文件:ExtractMethodRefactoring.java   
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) {
    VariableDeclaration original = ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
    VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
    fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
    fragment.setInitializer(intilizer);
    VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
    result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
    result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
    return result;
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
public boolean visit(SimpleName node) {
    if (mtbStack.isEmpty() && !itbStack.isEmpty()) { // not part of a method
        return false;
        /*
         * try { return visitName(node.resolveBinding(),
         * anonClassName.equals("")?getQualifiedName(itb):anonClassName); }
         * catch (Exception e) {
         * System.err.println("Cannot resolve simple name \""
         * +node.getFullyQualifiedName().toString()+"\""); return false; }
         */
    } else if (!mtbStack.isEmpty()) {
        if (node.getIdentifier().equals("length"))
            return false;
        try {
            return visitName(node.resolveBinding(), mtbStack.peek());
        } catch (Exception e) {
            System.err.println("Cannot resolve simple name \""
                    + node.getFullyQualifiedName().toString() + "\"");
            return false;
        }
    }
    return false;
}
项目:pandionj    文件:VarParser.java   
private void handleVarDeclaration(VariableDeclarationFragment var, boolean isField) {
    String varName = var.getName().getIdentifier();
    VariableInfo varInfo = current.addVar(varName, isField);
    Expression init = var.getInitializer();
    if(init instanceof SimpleName) {
        String initVar = ((SimpleName) init).getIdentifier();
        varInfo.addOperation(new VariableOperation(varName, VariableOperation.Type.INIT, initVar));
    }

}
项目:pandionj    文件:VarParser.java   
@Override
public boolean visit(PostfixExpression exp) {
    if(exp.getOperand() instanceof SimpleName) {
        String varName = exp.getOperand().toString(); 
        VariableOperation op = null;
        if(exp.getOperator() == PostfixExpression.Operator.INCREMENT)
            op = new VariableOperation(varName, VariableOperation.Type.INC);

        else if(exp.getOperator() == PostfixExpression.Operator.DECREMENT)
            op = new VariableOperation(varName, VariableOperation.Type.DEC);

        if(op != null)
            current.addOperation(op);
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
@Override
public boolean visit(PrefixExpression exp) {
    if(exp.getOperand() instanceof SimpleName) {
        String varName = exp.getOperand().toString(); 
        VariableOperation op = null;
        if(exp.getOperator() == PrefixExpression.Operator.INCREMENT)
            op = new VariableOperation(varName, VariableOperation.Type.INC);

        else if(exp.getOperator() == PrefixExpression.Operator.DECREMENT)
            op = new VariableOperation(varName, VariableOperation.Type.DEC);

        if(op != null)
            current.addOperation(op);
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
public boolean visit(InfixExpression exp) {
    Operator op = exp.getOperator();
    if(isCompareOperator(op)) {
        String leftExp = exp.getLeftOperand().toString();
        String rightExp = exp.getRightOperand().toString();

        Set<String> incVars = current.getOperations(VariableOperation.Type.INC, VariableOperation.Type.DEC);

        if(exp.getLeftOperand() instanceof SimpleName && incVars.contains(leftExp))
            aux(leftExp, op, exp.getRightOperand());

        if(exp.getRightOperand() instanceof SimpleName && incVars.contains(rightExp))
            aux(rightExp, op, exp.getLeftOperand());
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
private Object[] accessExpressions(ArrayAccess node) {
    Object[] exp = new Object[indexDepth(node)+1];
    ArrayAccess a = node;
    int i = exp.length-1;
    do {
        Expression indexExp = a.getIndex();
        if(!(indexExp instanceof SimpleName)) // TODO no modifiers
            return null;

        exp[i] = indexExp.toString();
        Expression temp = a.getArray();
        a = temp instanceof ArrayAccess ? (ArrayAccess) temp : null;
        i--;            
    }
    while(i >= 0);
    return exp;
}
项目:pandionj    文件:VarParser.java   
@Override
public boolean visit(MethodInvocation node) {
    List<?> arguments = node.arguments();
    for(int i = 0; i < arguments.size(); i++) {
        Object arg = arguments.get(i);
        if(arg instanceof SimpleName) {
            VariableInfo varInfo = current.getVariable(arg.toString());
            if(varInfo != null)
                varInfo.addOperation(VariableOperation.Type.PARAM, node.getName().toString(), arguments.size(), i);
        }
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
private static boolean isAcumulationAssign(Assignment assignment, InfixExpression.Operator op, Predicate<Expression> acceptExpression) {
    if(!(
            assignment.getRightHandSide() instanceof InfixExpression && 
            assignment.getLeftHandSide() instanceof SimpleName &&
            assignment.getOperator() == Assignment.Operator.ASSIGN))
        return false;

    InfixExpression exp = (InfixExpression) assignment.getRightHandSide();
    if(exp.getOperator() != op)
        return false;

    String assignVar = assignment.getLeftHandSide().toString();
    if( exp.getLeftOperand() instanceof SimpleName &&
            exp.getLeftOperand().toString().equals(assignVar) &&
            acceptExpression.test(exp.getRightOperand()))
        return true;

    if( exp.getRightOperand() instanceof SimpleName && 
            exp.getRightOperand().toString().equals(assignVar) &&
            acceptExpression.test(exp.getLeftOperand()))
        return true;

    return false;
}
项目:o3smeasures-tool    文件:LooseClassCohesionVisitor.java   
/**
 * Method to get the number of methods with indirect connections.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param methodsWithDirectConn
 * @param itMethods
 */
private void getNumberOfIndirectConnections(List<MethodDeclaration> methodsWithDirectConn,
        Iterator<MethodDeclaration> itMethods){

    int i=0;
    while (itMethods.hasNext()){

        MethodDeclaration firstMethod = itMethods.next();
        if (firstMethod != null){
            Block firstMethodBody = firstMethod.getBody();

            if (firstMethodBody != null){
                SimpleName methodDeclaration = methodsWithDirectConn.get(i).getName();

                if (firstMethodBody.toString().contains(methodDeclaration.toString())){
                    numIndirectConnections++;
                }
            }
        }
    }
}
项目:SparkBuilderGenerator    文件:StaticMethodInvocationFragment.java   
public MethodInvocation createStaticMethodInvocation(AST ast, String className, String methodName) {
    SimpleName typeName = ast.newSimpleName(className);

    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setName(ast.newSimpleName(methodName));
    methodInvocation.setExpression(typeName);

    return methodInvocation;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Returns the binding of the variable written in an Assignment.
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
    Expression leftHand = assignment.getLeftHandSide();
    switch (leftHand.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
        return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
    case ASTNode.QUALIFIED_NAME:
        return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
    case ASTNode.FIELD_ACCESS:
        return ((FieldAccess) leftHand).resolveFieldBinding();
    case ASTNode.SUPER_FIELD_ACCESS:
        return ((SuperFieldAccess) leftHand).resolveFieldBinding();
    default:
        return null;
    }
}
项目:code    文件:Utils.java   
/**
 * for an assignment x = y returns the variable binding of x
 * 
 * @param varBinding
 * @param assignment
 * @return
 */
private static IVariableBinding getLeftHandSideVarBinding(Assignment assignment) {
    Expression leftHnsd = assignment.getLeftHandSide();
    if (leftHnsd instanceof SimpleName) {
        IBinding bind = ((SimpleName) leftHnsd).resolveBinding();
        if (bind instanceof IVariableBinding) {
            return ((IVariableBinding) bind).getVariableDeclaration();
        }
    }
    if (leftHnsd instanceof FieldAccess) {
        FieldAccess fa = (FieldAccess) leftHnsd;
        return fa.resolveFieldBinding();
    }
    // Leave it null - cannot determine actual domains for arrays
    // workaround for bugs related to objects created in complex expression
    // if (leftHnsd instanceof ArrayAccess) {
    // ArrayAccess aa = (ArrayAccess) leftHnsd;
    // return getArrayAccessVarBinding(aa);
    // }
    return null;
}
项目:eclipse.jdt.ls    文件:CodeScopeBuilder.java   
@Override
public boolean visit(MethodInvocation node) {
    Expression receiver = node.getExpression();
    if (receiver == null) {
        SimpleName name = node.getName();
        if (fIgnoreBinding == null || !Bindings.equals(fIgnoreBinding, name.resolveBinding())) {
            node.getName().accept(this);
        }
    } else {
        receiver.accept(this);
    }
    accept(node.arguments());
    return false;
}
项目:eclipse.jdt.ls    文件:LinkedNodeFinder.java   
@Override
public boolean visit(SimpleName node) {
    IBinding binding= node.resolveBinding();
    if (binding == null) {
        return false;
    }
    binding= getDeclaration(binding);

    if (fBinding == binding) {
        fResult.add(node);
    } else if (binding.getKind() != fBinding.getKind()) {
        return false;
    } else if (binding.getKind() == IBinding.METHOD) {
        IMethodBinding curr= (IMethodBinding) binding;
        IMethodBinding methodBinding= (IMethodBinding) fBinding;
        if (methodBinding.overrides(curr) || curr.overrides(methodBinding)) {
            fResult.add(node);
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:OrganizeImportsOperation.java   
private void addStaticImports(
        Collection<SimpleName> staticReferences,
        ImportRewrite importRewrite,
        UnresolvableImportMatcher unresolvableImportMatcher) {
    for (SimpleName name : staticReferences) {
        IBinding binding= name.resolveBinding();
        if (binding != null) {
            importRewrite.addStaticImport(binding);
        } else {
            // This could be an unresolvable reference to a static member.
            String identifier= name.getIdentifier();
            Set<String> unresolvableImports= unresolvableImportMatcher.matchStaticImports(identifier);
            for (String unresolvableImport : unresolvableImports) {
                int lastDotIndex= unresolvableImport.lastIndexOf('.');
                // It's OK to skip invalid imports.
                if (lastDotIndex != -1) {
                    String declaringTypeName= unresolvableImport.substring(0, lastDotIndex);
                    String simpleName= unresolvableImport.substring(lastDotIndex + 1);
                    // Whether name refers to a field or to a method is unknown.
                    boolean isField= false;
                    importRewrite.addStaticImport(declaringTypeName, simpleName, isField, UNRESOLVABLE_IMPORT_CONTEXT);
                }
            }
        }
    }
}
项目:Sparrow    文件:OutCodeVisitor.java   
@Override
public boolean visit(SimpleName node) {
    if (currentMethod == null)
        return false;
    IBinding binding = node.resolveBinding();
    if (binding == null)
        return false;
    if (node.isDeclaration())
        return true;
    if (node.resolveBinding() instanceof IVariableBinding) {
        IVariableBinding iVariableBinding = (IVariableBinding) node.resolveBinding();
        if (iVariableBinding.isField()) {
            IVariableBinding variableDeclarationBinding = iVariableBinding.getVariableDeclaration();
            if (variableDeclarationBinding.getDeclaringClass() != null) {
                IJavaElement accessedField = variableDeclarationBinding.getJavaElement();
                if (accessedField instanceof IField) {
                    if (!((IField) accessedField).isReadOnly())
                        methodDetails.addAccess((IField) accessedField);
                }
            }
        }
    }
    return true;
}
项目:eclipse.jdt.ls    文件:PotentialProgrammingProblemsFix.java   
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name
 *            the name of the node
 *
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
    ASTNode parent = name.getParent();
    if (!(parent instanceof AbstractTypeDeclaration)) {

        parent = parent.getParent();
        if (parent instanceof ParameterizedType || parent instanceof Type) {
            parent = parent.getParent();
        }
        if (parent instanceof ClassInstanceCreation) {

            final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
            parent = creation.getAnonymousClassDeclaration();
        }
    }
    return parent;
}
项目:eclipse.jdt.ls    文件:UnusedCodeFix.java   
public static UnusedCodeFix createUnusedMemberFix(CompilationUnit compilationUnit, IProblemLocation problem, boolean removeAllAssignements) {
    if (isUnusedMember(problem)) {
        SimpleName name= getUnusedName(compilationUnit, problem);
        if (name != null) {
            IBinding binding= name.resolveBinding();
            if (binding != null) {
                if (isFormalParameterInEnhancedForStatement(name)) {
                    return null;
                }

                String label= getDisplayString(name, binding, removeAllAssignements);
                RemoveUnusedMemberOperation operation= new RemoveUnusedMemberOperation(new SimpleName[] { name }, removeAllAssignements);
                return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, removeAllAssignements));
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:UnusedCodeFix.java   
private static String getDisplayString(SimpleName simpleName, IBinding binding, boolean removeAllAssignements) {
    String name= BasicElementLabels.getJavaElementName(simpleName.getIdentifier());
    switch (binding.getKind()) {
    case IBinding.TYPE:
        return Messages.format(FixMessages.UnusedCodeFix_RemoveType_description, name);
    case IBinding.METHOD:
        if (((IMethodBinding) binding).isConstructor()) {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveConstructor_description, name);
        } else {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveMethod_description, name);
        }
    case IBinding.VARIABLE:
        if (removeAllAssignements) {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveFieldOrLocalWithInitializer_description, name);
        } else {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveFieldOrLocal_description, name);
        }
    default:
        return ""; //$NON-NLS-1$
    }
}
项目:eclipse.jdt.ls    文件:ImportRemover.java   
public IBinding[] getImportsToRemove() {
    ArrayList<SimpleName> importNames= new ArrayList<>();
    ArrayList<SimpleName> staticNames= new ArrayList<>();

    ImportReferencesCollector.collect(fRoot, fProject, null, importNames, staticNames);

    List<SimpleName> removedRefs= new ArrayList<>();
    List<SimpleName> unremovedRefs= new ArrayList<>();
    divideTypeRefs(importNames, staticNames, removedRefs, unremovedRefs);
    if (removedRefs.size() == 0) {
        return new IBinding[0];
    }

    HashMap<String, IBinding> potentialRemoves= getPotentialRemoves(removedRefs);
    for (Iterator<SimpleName> iterator= unremovedRefs.iterator(); iterator.hasNext();) {
        SimpleName name= iterator.next();
        potentialRemoves.remove(name.getIdentifier());
    }

    Collection<IBinding> importsToRemove= potentialRemoves.values();
    return importsToRemove.toArray(new IBinding[importsToRemove.size()]);
}
项目:code    文件:Utils.java   
/**
 * returns the name associated with an assignment instruction
 * 
 * @param instr
 * @return
 */
public static String getSimpleAssignName(AssignmentInstruction instr) {
    if (instr instanceof LoadLiteralInstruction)
        return ((LoadLiteralInstruction) instr).getLiteral().toString();
    ASTNode parentInstr = instr.getNode().getParent();

    if (parentInstr instanceof VariableDeclarationFragment) {
        return ((VariableDeclarationFragment) parentInstr).getName().getFullyQualifiedName();
    }
    if (parentInstr instanceof Assignment) {
        Expression leftHnsd = ((Assignment) parentInstr).getLeftHandSide();
        if (leftHnsd instanceof SimpleName) {
            return ((SimpleName) leftHnsd).getFullyQualifiedName();
        }
        else if (leftHnsd instanceof FieldAccess) {
            return ((FieldAccess) leftHnsd).getName().getFullyQualifiedName();
        }
    }
    throw new IllegalStateException("cannot find local variable associated with " + instr);
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(SimpleName node) {
    if (skipNode(node) || node.isDeclaration()) {
        return;
    }
    IBinding binding = node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        IVariableBinding variable = (IVariableBinding) binding;
        if (!variable.isField()) {
            setFlowInfo(node, new LocalFlowInfo(variable, FlowInfo.READ, fFlowContext));
        }
    } else if (binding instanceof ITypeBinding) {
        ITypeBinding type = (ITypeBinding) binding;
        if (type.isTypeVariable()) {
            setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext));
        }
    }
}
项目:eclipse.jdt.ls    文件:RenameNodeCorrectionProposal.java   
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
    super.addEdits(doc, root);

    // build a full AST
    CompilationUnit unit = SharedASTProvider.getInstance().getAST(getCompilationUnit(), null);

    ASTNode name= NodeFinder.perform(unit, fOffset, fLength);
    if (name instanceof SimpleName) {

        SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
        if (names != null) {
            for (int i= 0; i < names.length; i++) {
                SimpleName curr= names[i];
                root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
            }
            return;
        }
    }
    root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
项目:eclipse.jdt.ls    文件:GetterSetterCorrectionSubProcessor.java   
private static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, Collection<CUCorrectionProposal> proposals) {
    if (!(coveringNode instanceof SimpleName)) {
        return false;
    }
    SimpleName sn = (SimpleName) coveringNode;

    IBinding binding = sn.resolveBinding();
    if (!(binding instanceof IVariableBinding)) {
        return false;
    }
    IVariableBinding variableBinding = (IVariableBinding) binding;
    if (!variableBinding.isField()) {
        return false;
    }

    if (proposals == null) {
        return true;
    }

    CUCorrectionProposal proposal = getProposal(context.getCompilationUnit(), sn, variableBinding);
    if (proposal != null) {
        proposals.add(proposal);
    }
    return true;
}
项目:eclipse.jdt.ls    文件:NewVariableCorrectionProposal.java   
private ASTNode getDominantNode(SimpleName[] names) {
    ASTNode dominator= names[0]; //ASTResolvingUtil.findParentStatement(names[0]);
    for (int i= 1; i < names.length; i++) {
        ASTNode curr= names[i];// ASTResolvingUtil.findParentStatement(names[i]);
        if (curr != dominator) {
            ASTNode parent= getCommonParent(curr, dominator);

            if (curr.getStartPosition() < dominator.getStartPosition()) {
                dominator= curr;
            }
            while (dominator.getParent() != parent) {
                dominator= dominator.getParent();
            }
        }
    }
    int parentKind= dominator.getParent().getNodeType();
    if (parentKind != ASTNode.BLOCK && parentKind != ASTNode.FOR_STATEMENT) {
        return dominator.getParent();
    }
    return dominator;
}
项目:eclipse.jdt.ls    文件:NewVariableCorrectionProposal.java   
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
    SimpleName node= fOriginalNode;

    ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
    if (newTypeDecl == null) {
        astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
        newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
    }

    if (newTypeDecl != null) {
        AST ast= newTypeDecl.getAST();

        ASTRewrite rewrite= ASTRewrite.create(ast);

        EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration();
        constDecl.setName(ast.newSimpleName(node.getIdentifier()));

        ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
        listRewriter.insertLast(constDecl, null);

        return rewrite;
    }
    return null;
}
项目:eclipse.jdt.ls    文件:UnresolvedElementsSubProcessor.java   
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode,
        Collection<CUCorrectionProposal> proposals) {
    if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
        ASTNode type= selectedNode.getParent();
        if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
            SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
            if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
                if (svd.getName().getLength() == 0) {
                    SimpleName simpleName= (SimpleName) selectedNode;
                    String name= simpleName.getIdentifier();
                    int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
                    String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));

                    proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL,
                            simpleName, null, relevance));
                }
            }
        }
    }
}
项目:eclipse.jdt.ls    文件:UnresolvedElementsSubProcessor.java   
private static String getExpressionBaseName(Expression expr) {
    IBinding argBinding= Bindings.resolveExpressionBinding(expr, true);
    if (argBinding instanceof IVariableBinding) {
        IJavaProject project= null;
        ASTNode root= expr.getRoot();
        if (root instanceof CompilationUnit) {
            ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot();
            if (typeRoot != null) {
                project= typeRoot.getJavaProject();
            }
        }
        return StubUtility.getBaseName((IVariableBinding)argBinding, project);
    }
    if (expr instanceof SimpleName) {
        return ((SimpleName) expr).getIdentifier();
    }
    return null;
}
项目:gw4e.project    文件:JDTManager.java   
public boolean visit(MethodInvocation node) {
    try {
        SimpleName simpleName = node.getName();
        IBinding bding = simpleName.resolveBinding();
        if (bding instanceof IMethodBinding) {
            IMethodBinding imb = (IMethodBinding) bding;
            if (isContext(imb.getReturnType())) {
                this.value = imb.getReturnType().getQualifiedName().toString();
            }
        }
    } catch (Throwable e) {
    }
    return false;
}
项目:gw4e.project    文件:JDTManager.java   
public boolean visit(SimpleName node) {
    try {
        this.value = variables.get(node.getFullyQualifiedName());
    } catch (Throwable e) {
    }
    return true;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param project
 * @param itype
 * @return
 * @throws JavaModelException
 */
private static IPath findPathInStaticField(IProject project, IType itype) throws JavaModelException {
    List<IPath> wrapper = new ArrayList<IPath>();
    ICompilationUnit cu = itype.getCompilationUnit();
    CompilationUnit ast = parse(cu);
    ast.accept(new ASTVisitor() {
        public boolean visit(VariableDeclarationFragment node) {
            SimpleName simpleName = node.getName();
            IBinding bding = simpleName.resolveBinding();
            if (bding instanceof IVariableBinding) {
                IVariableBinding binding = (IVariableBinding) bding;
                String type = binding.getType().getBinaryName(); //
                String name = simpleName.getFullyQualifiedName();
                if ("MODEL_PATH".equals(name) && "java.nio.file.Path".equals(type)) {
                    Expression expression = node.getInitializer();
                    if (expression instanceof MethodInvocation) {
                        MethodInvocation mi = (MethodInvocation) expression;
                        if ("get".equals(mi.resolveMethodBinding().getName())
                                && "java.nio.file.Path".equals(mi.resolveTypeBinding().getBinaryName())) {
                            StringLiteral sl = (StringLiteral) mi.arguments().get(0);
                            String argument = sl.getLiteralValue();
                            try {
                                IPath p = ResourceManager.find(project, argument);
                                wrapper.add(p);
                            } catch (CoreException e) {
                                ResourceManager.logException(e);
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
    if (wrapper.size() > 0)
        return wrapper.get(0);
    return null;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * Rename a class name into another name
 * 
 * @param file
 * @param oldClassname
 * @param newName
 * @param monitor
 * @return
 * @throws MalformedTreeException
 * @throws BadLocationException
 * @throws CoreException
 */
public static IFile renameClass(IFile file, String oldClassname, String newName, IProgressMonitor monitor)
        throws MalformedTreeException, BadLocationException, CoreException {
    Display.getDefault().syncExec(new Runnable() {

        @Override
        public void run() {
            try {

                ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
                CompilationUnit cu = parse(unit);
                AST ast = cu.getAST();
                ASTRewrite rewrite = ASTRewrite.create(ast);

                String classname = file.getName();
                classname = classname.substring(0, classname.indexOf("."));
                final String clazz = classname;
                ASTVisitor visitor = new ASTVisitor() {
                    public boolean visit(SimpleName node) {
                        String s = node.getIdentifier();
                        if (oldClassname.equalsIgnoreCase(s)) {
                            rewrite.replace(node, ast.newSimpleName(newName), null);
                        }
                        return true;
                    }
                };
                cu.accept(visitor);

                addPackageDeclarationIfNeeded(file, cu, rewrite, ast);
                file.refreshLocal(IResource.DEPTH_ZERO, monitor);
                cu = parse(JavaCore.createCompilationUnitFrom(file));
                save(cu, rewrite);
            } catch (Exception e) {
                ResourceManager.logException(e);
            }
        }
    });
    return file;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
public static String getDomString(Object arg) {
    if (arg instanceof SimpleName) {
        return ((SimpleName) arg).getIdentifier();
    }
    if (arg instanceof StringLiteral) {
        return ((StringLiteral) arg).getLiteralValue();
    }
    return null;
}
项目:pandionj    文件:ArrayParser.java   
@Override
public boolean visit(ArrayAccess node) {
    Expression indexExp = node.getIndex();
    if(indexExp instanceof SimpleName) {
        SimpleName varName = (SimpleName) indexExp;
        System.out.println(node + " : " + varName.getIdentifier());
    }
    return super.visit(node);
}
项目:lombok-ianchiu    文件:PatchFixesHider.java   
public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception {
    Field f = SimpleName.class.getField("$isGenerated");

    int count = 0;
    for (int i = 0; i < in.length; i++) {
        if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) count++;
    }
    if (count == in.length) return in;
    SimpleName[] newSimpleNames = new SimpleName[count];
    count = 0;
    for (int i = 0; i < in.length; i++) {
        if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) newSimpleNames[count++] = in[i];
    }
    return newSimpleNames;
}
项目:eclipse.jdt.ls    文件:QuickAssistProcessor.java   
private static SimpleName getMethodInvocationName(MethodReference methodReference) {
    SimpleName name = null;
    if (methodReference instanceof ExpressionMethodReference) {
        name = ((ExpressionMethodReference) methodReference).getName();
    } else if (methodReference instanceof TypeMethodReference) {
        name = ((TypeMethodReference) methodReference).getName();
    } else if (methodReference instanceof SuperMethodReference) {
        name = ((SuperMethodReference) methodReference).getName();
    }
    return name;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static String getSimpleNameIdentifier(Name name) {
    if (name.isQualifiedName()) {
        return ((QualifiedName) name).getName().getIdentifier();
    } else {
        return ((SimpleName) name).getIdentifier();
    }
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static boolean isDeclaration(Name name) {
    if (name.isQualifiedName()) {
        return ((QualifiedName) name).getName().isDeclaration();
    } else {
        return ((SimpleName) name).isDeclaration();
    }
}