Java Code Examples for org.eclipse.jdt.core.dom.AnonymousClassDeclaration#resolveBinding()
The following examples show how to use
org.eclipse.jdt.core.dom.AnonymousClassDeclaration#resolveBinding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AstVisitor.java From jdt2famix with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(AnonymousClassDeclaration node) { ITypeBinding binding = node.resolveBinding(); Type type; if (binding != null) type = importer.createTypeFromTypeBinding(binding); else { type = importer.createTypeNamedInUnknownNamespace(""); logNullBinding("anonymous type declaration", node.getParent().toString().replaceAll("\n", " "), ((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition())); } importer.ensureTypeFromAnonymousDeclaration(type, node); type.setIsStub(false); importer.createSourceAnchor(type, node); importer.pushOnContainerStack(type); return true; }
Example 2
Source File: UnimplementedCodeFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean isTypeBindingNull(ASTNode typeNode) { if (typeNode instanceof AbstractTypeDeclaration) { AbstractTypeDeclaration abstractTypeDeclaration= (AbstractTypeDeclaration) typeNode; if (abstractTypeDeclaration.resolveBinding() == null) return true; return false; } else if (typeNode instanceof AnonymousClassDeclaration) { AnonymousClassDeclaration anonymousClassDeclaration= (AnonymousClassDeclaration) typeNode; if (anonymousClassDeclaration.resolveBinding() == null) return true; return false; } else if (typeNode instanceof EnumConstantDeclaration) { return false; } else { return true; } }
Example 3
Source File: DOMFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean visit(AnonymousClassDeclaration node) { ASTNode name; ASTNode parent = node.getParent(); switch (parent.getNodeType()) { case ASTNode.CLASS_INSTANCE_CREATION: name = ((ClassInstanceCreation) parent).getType(); if (name.getNodeType() == ASTNode.PARAMETERIZED_TYPE) { name = ((ParameterizedType) name).getType(); } break; case ASTNode.ENUM_CONSTANT_DECLARATION: name = ((EnumConstantDeclaration) parent).getName(); break; default: return true; } if (found(node, name) && this.resolveBinding) this.foundBinding = node.resolveBinding(); return true; }
Example 4
Source File: LambdaExpressionsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static boolean isFunctionalAnonymous(ClassInstanceCreation node) { ITypeBinding typeBinding= node.resolveTypeBinding(); if (typeBinding == null) return false; ITypeBinding[] interfaces= typeBinding.getInterfaces(); if (interfaces.length != 1) return false; if (interfaces[0].getFunctionalInterfaceMethod() == null) return false; AnonymousClassDeclaration anonymTypeDecl= node.getAnonymousClassDeclaration(); if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) return false; List<BodyDeclaration> bodyDeclarations= anonymTypeDecl.bodyDeclarations(); // cannot convert if there are fields or additional methods if (bodyDeclarations.size() != 1) return false; BodyDeclaration bodyDeclaration= bodyDeclarations.get(0); if (!(bodyDeclaration instanceof MethodDeclaration)) return false; MethodDeclaration methodDecl= (MethodDeclaration) bodyDeclaration; IMethodBinding methodBinding= methodDecl.resolveBinding(); if (methodBinding == null) return false; // generic lambda expressions are not allowed if (methodBinding.isGenericMethod()) return false; // lambda cannot refer to 'this'/'super' literals if (SuperThisReferenceFinder.hasReference(methodDecl)) return false; if (!isInTargetTypeContext(node)) return false; return true; }
Example 5
Source File: RefactorProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static RefactoringCorrectionProposal getConvertAnonymousToNestedProposal(CodeActionParams params, IInvocationContext context, final ASTNode node, boolean returnAsCommand) throws CoreException { String label = CorrectionMessages.QuickAssistProcessor_convert_anonym_to_nested; ASTNode normalized = ASTNodes.getNormalizedNode(node); if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) { return null; } final AnonymousClassDeclaration anonymTypeDecl = ((ClassInstanceCreation) normalized.getParent()).getAnonymousClassDeclaration(); if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) { return null; } final ConvertAnonymousToNestedRefactoring refactoring = new ConvertAnonymousToNestedRefactoring(anonymTypeDecl); if (!refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) { return null; } if (returnAsCommand) { return new RefactoringCorrectionCommandProposal(label, CodeActionKind.Refactor, context.getCompilationUnit(), IProposalRelevance.CONVERT_ANONYMOUS_TO_NESTED, RefactorProposalUtility.APPLY_REFACTORING_COMMAND_ID, Arrays.asList(CONVERT_ANONYMOUS_CLASS_TO_NESTED_COMMAND, params)); } String extTypeName = ASTNodes.getSimpleNameIdentifier((Name) node); ITypeBinding anonymTypeBinding = anonymTypeDecl.resolveBinding(); String className; if (anonymTypeBinding.getInterfaces().length == 0) { className = Messages.format(CorrectionMessages.QuickAssistProcessor_name_extension_from_interface, extTypeName); } else { className = Messages.format(CorrectionMessages.QuickAssistProcessor_name_extension_from_class, extTypeName); } String[][] existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className); int i = 1; while (existingTypes != null) { i++; existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className + i); } refactoring.setClassName(i == 1 ? className : className + i); LinkedProposalModelCore linkedProposalModel = new LinkedProposalModelCore(); refactoring.setLinkedProposalModel(linkedProposalModel); final ICompilationUnit cu = context.getCompilationUnit(); RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, CodeActionKind.Refactor, cu, refactoring, IProposalRelevance.CONVERT_ANONYMOUS_TO_NESTED); proposal.setLinkedProposalModel(linkedProposalModel); return proposal; }
Example 6
Source File: ConvertAnonymousToNestedRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean mustInnerClassBeStatic() { ITypeBinding typeBinding = ((AbstractTypeDeclaration) ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class)).resolveBinding(); ASTNode current = fAnonymousInnerClassNode.getParent(); boolean ans = false; while(current != null) { switch(current.getNodeType()) { case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: case ASTNode.CONSTRUCTOR_INVOCATION: return true; case ASTNode.ANONYMOUS_CLASS_DECLARATION: { AnonymousClassDeclaration enclosingAnonymousClassDeclaration= (AnonymousClassDeclaration)current; ITypeBinding binding= enclosingAnonymousClassDeclaration.resolveBinding(); if (binding != null && Bindings.isSuperType(typeBinding, binding.getSuperclass())) { return false; } break; } case ASTNode.FIELD_DECLARATION: { FieldDeclaration enclosingFieldDeclaration= (FieldDeclaration)current; if (Modifier.isStatic(enclosingFieldDeclaration.getModifiers())) { ans = true; } break; } case ASTNode.METHOD_DECLARATION: { MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration)current; if (Modifier.isStatic(enclosingMethodDeclaration.getModifiers())) { ans = true; } break; } case ASTNode.TYPE_DECLARATION: { return ans; } } current = current.getParent(); } return ans; }
Example 7
Source File: QuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean getConvertAnonymousToNestedProposal(IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals) throws CoreException { if (!(node instanceof Name)) return false; ASTNode normalized= ASTNodes.getNormalizedNode(node); if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) return false; final AnonymousClassDeclaration anonymTypeDecl= ((ClassInstanceCreation) normalized.getParent()).getAnonymousClassDeclaration(); if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) { return false; } if (proposals == null) { return true; } final ICompilationUnit cu= context.getCompilationUnit(); final ConvertAnonymousToNestedRefactoring refactoring= new ConvertAnonymousToNestedRefactoring(anonymTypeDecl); String extTypeName= ASTNodes.getSimpleNameIdentifier((Name) node); ITypeBinding anonymTypeBinding= anonymTypeDecl.resolveBinding(); String className; if (anonymTypeBinding.getInterfaces().length == 0) { className= Messages.format(CorrectionMessages.QuickAssistProcessor_name_extension_from_interface, extTypeName); } else { className= Messages.format(CorrectionMessages.QuickAssistProcessor_name_extension_from_class, extTypeName); } String[][] existingTypes= ((IType) anonymTypeBinding.getJavaElement()).resolveType(className); int i= 1; while (existingTypes != null) { i++; existingTypes= ((IType) anonymTypeBinding.getJavaElement()).resolveType(className + i); } refactoring.setClassName(i == 1 ? className : className + i); if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) { LinkedProposalModel linkedProposalModel= new LinkedProposalModel(); refactoring.setLinkedProposalModel(linkedProposalModel); String label= CorrectionMessages.QuickAssistProcessor_convert_anonym_to_nested; Image image= JavaPlugin.getImageDescriptorRegistry().get(JavaElementImageProvider.getTypeImageDescriptor(true, false, Flags.AccPrivate, false)); RefactoringCorrectionProposal proposal= new RefactoringCorrectionProposal(label, cu, refactoring, IProposalRelevance.CONVERT_ANONYMOUS_TO_NESTED, image); proposal.setLinkedProposalModel(linkedProposalModel); proposal.setCommandId(CONVERT_ANONYMOUS_TO_LOCAL_ID); proposals.add(proposal); } return false; }