private boolean addLocalDeclarations(ASTNode node, int offset, int flags, IBindingRequestor requestor) { if (hasFlag(VARIABLES, flags) || hasFlag(TYPES, flags)) { BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(node); if (declaration instanceof MethodDeclaration || declaration instanceof Initializer || declaration instanceof FieldDeclaration) { ScopeAnalyzerVisitor visitor= new ScopeAnalyzerVisitor(offset, flags, requestor); declaration.accept(visitor); return visitor.fBreak; } } return false; }
private boolean addLocalDeclarations(ASTNode node, int offset, int flags, IBindingRequestor requestor) { if (hasFlag(VARIABLES, flags) || hasFlag(TYPES, flags)) { BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(node); if (declaration instanceof MethodDeclaration || declaration instanceof Initializer) { ScopeAnalyzerVisitor visitor= new ScopeAnalyzerVisitor(offset, flags, requestor); declaration.accept(visitor); return visitor.fBreak; } } return false; }
public static boolean isInStaticContext(ASTNode selectedNode) { BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { if (isInsideConstructorInvocation((MethodDeclaration) decl, selectedNode)) { return true; } return Modifier.isStatic(decl.getModifiers()); } else if (decl instanceof Initializer) { return Modifier.isStatic(((Initializer)decl).getModifiers()); } else if (decl instanceof FieldDeclaration) { return JdtFlags.isStatic(decl); } return false; }
public static boolean isInStaticContext(ASTNode selectedNode) { BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { if (isInsideConstructorInvocation((MethodDeclaration) decl, selectedNode)) { return true; } return Modifier.isStatic(decl.getModifiers()); } else if (decl instanceof Initializer) { return Modifier.isStatic(((Initializer)decl).getModifiers()); } else if (decl instanceof FieldDeclaration) { return Modifier.isStatic(((FieldDeclaration)decl).getModifiers()); } return false; }
BodyDeclaration bodyDecl= ASTResolving.findParentBodyDeclaration(node); if (bodyDecl == null || ASTResolving.getParentMethodOrTypeBinding(bodyDecl) == null) { return;
@Override protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params) throws CoreException { AST ast= rewrite.getAST(); List<Expression> arguments= fArguments; ImportRewriteContext context= new ContextSensitiveImportRewriteContext(ASTResolving.findParentBodyDeclaration(getInvocationNode()), getImportRewrite()); for (int i= 0; i < arguments.size(); i++) { Expression elem= arguments.get(i); SingleVariableDeclaration param= ast.newSingleVariableDeclaration(); // argument type String argTypeKey= "arg_type_" + i; //$NON-NLS-1$ Type type= evaluateParameterType(ast, elem, argTypeKey, context); param.setType(type); // argument name String argNameKey= "arg_name_" + i; //$NON-NLS-1$ String name= evaluateParameterName(takenNames, elem, type, argNameKey); param.setName(ast.newSimpleName(name)); params.add(param); addLinkedPosition(rewrite.track(param.getType()), false, argTypeKey); addLinkedPosition(rewrite.track(param.getName()), false, argNameKey); } }
public static void addMethodRetunsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws JavaModelException { CompilationUnit astRoot= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(astRoot); if (!(selectedNode instanceof ReturnStatement)) { return; } ReturnStatement returnStatement= (ReturnStatement) selectedNode; Expression expression= returnStatement.getExpression(); if (expression == null) { return; } BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { MethodDeclaration methDecl= (MethodDeclaration) decl; Type retType= methDecl.getReturnType2(); if (retType == null || retType.resolveBinding() == null) { return; } TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, 4, proposals); } } }
public static void addMethodRetunsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws JavaModelException { CompilationUnit astRoot= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(astRoot); if (!(selectedNode instanceof ReturnStatement)) { return; } ReturnStatement returnStatement= (ReturnStatement) selectedNode; Expression expression= returnStatement.getExpression(); if (expression == null) { return; } BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { MethodDeclaration methDecl= (MethodDeclaration) decl; Type retType= methDecl.getReturnType2(); if (retType == null || retType.resolveBinding() == null) { return; } TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals); } } }
private static boolean getConvertStringConcatenationProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) { ASTNode node= context.getCoveringNode(); BodyDeclaration parentDecl= ASTResolving.findParentBodyDeclaration(node); if (!(parentDecl instanceof MethodDeclaration || parentDecl instanceof Initializer)) return false;
AST ast= rewriter.getAST(); ImportRewriteContext context= null; ASTNode bodyDeclaration= ASTResolving.findParentBodyDeclaration(listRewriter.getParent()); if (bodyDeclaration != null) { context= new ContextSensitiveImportRewriteContext(bodyDeclaration, getImportRewrite());
return; BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDecl= (MethodDeclaration) decl;
BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(node); if (bodyDeclaration == null) { return;
if (binding == fieldBinding && ASTResolving.findParentBodyDeclaration(selectedNode) instanceof MethodDeclaration) { SimpleName simpleName= (SimpleName) ((assignedNode instanceof SimpleName) ? assignedNode : assignExpression); String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createparameter_description, simpleName.getIdentifier());
public static void addConstructorFromSuperclassProposal(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return; } TypeDeclaration typeDeclaration= null; if (selectedNode.getLocationInParent() == TypeDeclaration.NAME_PROPERTY) { typeDeclaration= (TypeDeclaration) selectedNode.getParent(); } else { BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(selectedNode); if (declaration instanceof Initializer && problem.getProblemId() == IProblem.UnhandledExceptionInDefaultConstructor) { addUncaughtExceptionProposals(context, problem, proposals); } return; } ITypeBinding binding= typeDeclaration.resolveBinding(); if (binding == null || binding.getSuperclass() == null) { return; } ICompilationUnit cu= context.getCompilationUnit(); IMethodBinding[] methods= binding.getSuperclass().getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { IMethodBinding curr= methods[i]; if (curr.isConstructor() && !Modifier.isPrivate(curr.getModifiers())) { proposals.add(new ConstructorFromSuperclassProposal(cu, typeDeclaration, curr, 5)); } } }
SimpleName node= fOriginalNode; BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(node); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration= (MethodDeclaration) decl;
SimpleName node= fOriginalNode; BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(node); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration= (MethodDeclaration) decl;
public static void addConstructorFromSuperclassProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return; } TypeDeclaration typeDeclaration= null; if (selectedNode.getLocationInParent() == TypeDeclaration.NAME_PROPERTY) { typeDeclaration= (TypeDeclaration) selectedNode.getParent(); } else { BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(selectedNode); if (declaration instanceof Initializer && problem.getProblemId() == IProblem.UnhandledExceptionInDefaultConstructor) { addUncaughtExceptionProposals(context, problem, proposals); } return; } ITypeBinding binding= typeDeclaration.resolveBinding(); if (binding == null || binding.getSuperclass() == null) { return; } ICompilationUnit cu= context.getCompilationUnit(); IMethodBinding[] methods= binding.getSuperclass().getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { IMethodBinding curr= methods[i]; if (curr.isConstructor() && !Modifier.isPrivate(curr.getModifiers())) { proposals.add(new ConstructorFromSuperclassProposal(cu, typeDeclaration, curr, IProposalRelevance.ADD_CONSTRUCTOR_FROM_SUPER_CLASS)); } } }
private static void addNewVariableProposals(ICompilationUnit cu, Name node, SimpleName simpleName, Collection proposals) { String name= simpleName.getIdentifier(); BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(node, true); int type= bodyDeclaration.getNodeType(); if (type == ASTNode.METHOD_DECLARATION) {
private static void addNewVariableProposals(ICompilationUnit cu, Name node, SimpleName simpleName, Collection<ICommandAccess> proposals) { String name= simpleName.getIdentifier(); BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(node, true); int type= bodyDeclaration.getNodeType(); if (type == ASTNode.METHOD_DECLARATION) {
private static void addNewVariableProposals(ICompilationUnit cu, Name node, SimpleName simpleName, Collection proposals) { String name= simpleName.getIdentifier(); BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(node, true); int type= bodyDeclaration.getNodeType(); if (type == ASTNode.METHOD_DECLARATION) {