List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding availableMethods
public MethodBinding[] availableMethods()
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
private void selectStaticMethodFromStaticImport(CompilationUnitDeclaration parsedUnit, char[] lastToken, ReferenceBinding ref) { int methodLength = lastToken.length; MethodBinding[] methods = ref.availableMethods(); next: for (int j = 0; j < methods.length; j++) { MethodBinding method = methods[j]; if (method.isSynthetic()) continue next; if (method.isDefaultAbstract()) continue next; if (method.isConstructor()) continue next; if (!method.isStatic()) continue next; if (methodLength > method.selector.length) continue next; if (!CharOperation.equals(lastToken, method.selector, true)) continue next; selectFrom(method, parsedUnit, false); }/*w w w . jav a 2 s.c om*/ }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
protected MethodBinding findOverriddenMethodInType(ReferenceBinding overriddenType, MethodBinding overriding) throws JavaModelException { if (overriddenType == null) return null; MethodBinding[] overriddenMethods = overriddenType.availableMethods(); LookupEnvironment lookupEnv = this.lookupEnvironment; if (lookupEnv != null && overriddenMethods != null) { for (int i = 0; i < overriddenMethods.length; i++) { if (lookupEnv.methodVerifier().isMethodSubsignature(overriding, overriddenMethods[i])) { return overriddenMethods[i]; }/*w w w . j ava2 s.c o m*/ } } return null; }
From source file:lombok.eclipse.agent.PatchDelegate.java
License:Open Source License
private static void addAllMethodBindings0(List<BindingTuple> list, TypeBinding binding, Set<String> banList, char[] fieldName, ASTNode responsible) throws DelegateRecursion { if (binding instanceof SourceTypeBinding) ((SourceTypeBinding) binding).scope.environment().globalOptions.storeAnnotations = true; if (binding == null) return;/*from www . j a v a2 s. co m*/ TypeBinding inner; if (binding instanceof ParameterizedTypeBinding) { inner = ((ParameterizedTypeBinding) binding).genericType(); } else { inner = binding; } if (inner instanceof SourceTypeBinding) { ClassScope cs = ((SourceTypeBinding) inner).scope; if (cs != null) { try { Reflection.classScopeBuildFieldsAndMethodsMethod.invoke(cs); } catch (Exception e) { // See 'Reflection' class for why we ignore this exception. } } } if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); FieldBinding[] availableFields = rb.availableFields(); failIfContainsAnnotation(binding, availableMethods); failIfContainsAnnotation(binding, availableFields); MethodBinding[] parameterizedSigs = availableMethods; MethodBinding[] baseSigs = parameterizedSigs; if (binding instanceof ParameterizedTypeBinding) { baseSigs = ((ParameterizedTypeBinding) binding).genericType().availableMethods(); if (baseSigs.length != parameterizedSigs.length) { // The last known state of eclipse source says this can't happen, so we rely on it, // but if this invariant is broken, better to go with 'arg0' naming instead of crashing. baseSigs = parameterizedSigs; } } for (int i = 0; i < parameterizedSigs.length; i++) { MethodBinding mb = parameterizedSigs[i]; String sig = printSig(mb); if (mb.isStatic()) continue; if (mb.isBridge()) continue; if (mb.isConstructor()) continue; if (mb.isDefaultAbstract()) continue; if (!mb.isPublic()) continue; if (mb.isSynthetic()) continue; if (!banList.add(sig)) continue; // If add returns false, it was already in there. BindingTuple pair = new BindingTuple(mb, baseSigs[i], fieldName, responsible); list.add(pair); } addAllMethodBindings0(list, rb.superclass(), banList, fieldName, responsible); ReferenceBinding[] interfaces = rb.superInterfaces(); if (interfaces != null) { for (ReferenceBinding iface : interfaces) addAllMethodBindings0(list, iface, banList, fieldName, responsible); } } }
From source file:lombok.eclipse.handlers.HandleActionFunctionAndPredicate.java
License:Open Source License
private List<MethodBinding> enclosedMethodsOf(final TypeBinding type) { final List<MethodBinding> enclosedMethods = new ArrayList<MethodBinding>(); if (type instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) type; for (MethodBinding enclosedElement : Each.elementIn(rb.availableMethods())) { if (!enclosedElement.isAbstract()) continue; enclosedMethods.add(enclosedElement); }/*w ww .ja va 2s .com*/ } return enclosedMethods; }
From source file:lombok.eclipse.handlers.HandleBindable.java
License:Apache License
@Override public void handle(final AnnotationValues<Bindable> annotation, final Annotation source, final EclipseNode annotationNode) { new BindableHandler<EclipseType, EclipseField, EclipseNode, ASTNode>(annotationNode, source) { @Override//w ww .j ava2s. c o m protected void addInterface(EclipseType type, String interfaceClassName) { EclipseUtil.addInterface(type.get(), interfaceClassName, source); } @Override protected EclipseType typeOf(EclipseNode node, ASTNode ast) { return EclipseType.typeOf(node, ast); } @Override protected EclipseField fieldOf(EclipseNode node, ASTNode ast) { return EclipseField.fieldOf(node, ast); } @Override protected boolean hasMethodIncludingSupertypes(EclipseType type, String methodName, TypeRef... argumentTypes) { return hasMethod(type.get().binding, methodName, type.editor().build(As.list(argumentTypes))); } private boolean hasMethod(final TypeBinding binding, final String methodName, List<ASTNode> argumentTypes) { if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); for (MethodBinding method : Each.elementIn(availableMethods)) { if (method.isAbstract()) continue; /*if (!method.isPublic()) continue;*/ if (!methodName.equals(As.string(method.selector))) continue; if (argumentTypes.size() != As.list(method.parameters).size()) continue; // TODO check actual types.. return true; } ReferenceBinding superclass = rb.superclass(); ensureAllClassScopeMethodWereBuild(superclass); return hasMethod(superclass, methodName, argumentTypes); } return false; } @Override protected boolean isAnnotatedWith(EclipseType type, Class<? extends java.lang.annotation.Annotation> annotationClass) { Annotation[] annotations = type.get().annotations; if (annotations == null) return false; for (Annotation annotation : annotations) { if (annotation == null || annotation.type == null) continue; String annotationName = resolveAnnotationName(annotation.type.getTypeName()); if (annotationName.equals(annotationClass.getName())) return true; } return false; } @Override protected boolean isAnnotatedWith(final EclipseNode eclipseNode, final Class<? extends java.lang.annotation.Annotation> annotationClass) { final boolean[] result = new boolean[1]; result[0] = false; eclipseNode.traverse(new EclipseASTAdapter() { @Override public void visitAnnotationOnType(TypeDeclaration type, EclipseNode annotationNode, Annotation annotation) { Annotation[] annotations = type.annotations; if (annotations == null) { result[0] = false; } else { for (Annotation a : annotations) { if (a == null || a.type == null) continue; String annotationName = resolveAnnotationName(a.type.getTypeName()); if (annotationName.equals(annotationClass.getName())) { result[0] = true; break; } } } } }); return result[0]; } private String resolveAnnotationName(char[][] typeName) { StringBuilder b = new StringBuilder(); for (int i = 0; i < typeName.length; i++) { b.append(new String(typeName[i])); if (i < typeName.length - 1) b.append("."); } return b.toString(); } }.handle(); }
From source file:lombok.eclipse.handlers.HandleBoundSetter.java
License:Open Source License
@Override public void handle(final AnnotationValues<BoundSetter> annotation, final Annotation ast, final EclipseNode annotationNode) { BoundSetter annotationInstance = annotation.getInstance(); new BoundSetterHandler<EclipseType, EclipseField, EclipseNode, ASTNode>(annotationNode, ast) { @Override/*from w w w . java 2 s . c o m*/ protected EclipseType typeOf(EclipseNode node, ASTNode ast) { return EclipseType.typeOf(node, ast); } @Override protected EclipseField fieldOf(EclipseNode node, ASTNode ast) { return EclipseField.fieldOf(node, ast); } @Override protected boolean hasMethodIncludingSupertypes(final EclipseType type, final String methodName, final lombok.ast.TypeRef... argumentTypes) { return hasMethod(type.get().binding, methodName, type.editor().build(As.list(argumentTypes))); } private boolean hasMethod(final TypeBinding binding, final String methodName, List<ASTNode> argumentTypes) { if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); for (MethodBinding method : Each.elementIn(availableMethods)) { if (method.isAbstract()) continue; if (!method.isPublic()) continue; if (!methodName.equals(As.string(method.selector))) continue; if (argumentTypes.size() != As.list(method.parameters).size()) continue; // TODO check actual types.. return true; } ReferenceBinding superclass = rb.superclass(); ensureAllClassScopeMethodWereBuild(superclass); return hasMethod(superclass, methodName, argumentTypes); } return false; } }.handle(annotationInstance.value(), annotationInstance.vetoable(), annotationInstance.throwVetoException()); }
From source file:lombok.eclipse.handlers.HandleListenerSupport.java
License:Open Source License
private void getInterfaceMethods(final TypeBinding binding, final List<MethodBinding> methods, final Set<String> banList) { if (binding == null) return;/*from w w w .j a v a 2 s. c o m*/ ensureAllClassScopeMethodWereBuild(binding); if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); for (MethodBinding mb : Each.elementIn(availableMethods)) { String sig = As.string(mb.readableName()); if (!banList.add(sig)) continue; methods.add(mb); } ReferenceBinding[] interfaces = rb.superInterfaces(); for (ReferenceBinding iface : Each.elementIn(interfaces)) { getInterfaceMethods(iface, methods, banList); } } }
From source file:lombok.eclipse.handlers.HandleObservable.java
License:Apache License
@Override public void handle(final AnnotationValues<Observable> annotation, final Annotation source, final EclipseNode annotationNode) { new ObservableHandler<EclipseType, EclipseField, EclipseNode, ASTNode>(annotationNode, source) { @Override/*from w w w . ja va 2s. c o m*/ protected void addInterface(EclipseType type, String interfaceClassName) { EclipseUtil.addInterface(type.get(), interfaceClassName, source); } @Override protected EclipseType typeOf(EclipseNode node, ASTNode ast) { return EclipseType.typeOf(node, ast); } @Override protected EclipseField fieldOf(EclipseNode node, ASTNode ast) { return EclipseField.fieldOf(node, ast); } @Override protected boolean hasMethodIncludingSupertypes(EclipseType type, String methodName, TypeRef... argumentTypes) { return hasMethod(type.get().binding, methodName, type.editor().build(As.list(argumentTypes))); } private boolean hasMethod(final TypeBinding binding, final String methodName, List<ASTNode> argumentTypes) { if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); for (MethodBinding method : Each.elementIn(availableMethods)) { if (method.isAbstract()) continue; /*if (!method.isPublic()) continue;*/ if (!methodName.equals(As.string(method.selector))) continue; if (argumentTypes.size() != As.list(method.parameters).size()) continue; // TODO check actual types.. return true; } ReferenceBinding superclass = rb.superclass(); ensureAllClassScopeMethodWereBuild(superclass); return hasMethod(superclass, methodName, argumentTypes); } return false; } @Override protected boolean isAnnotatedWith(EclipseType type, Class<? extends java.lang.annotation.Annotation> annotationClass) { Annotation[] annotations = type.get().annotations; if (annotations == null) return false; for (Annotation annotation : annotations) { if (annotation == null || annotation.type == null) continue; String annotationName = resolveAnnotationName(annotation.type.getTypeName()); if (annotationName.equals(annotationClass.getName())) return true; } return false; } @Override protected boolean isAnnotatedWith(final EclipseNode eclipseNode, final Class<? extends java.lang.annotation.Annotation> annotationClass) { final boolean[] result = new boolean[1]; result[0] = false; eclipseNode.traverse(new EclipseASTAdapter() { @Override public void visitAnnotationOnType(TypeDeclaration type, EclipseNode annotationNode, Annotation annotation) { Annotation[] annotations = type.annotations; if (annotations == null) { result[0] = false; } else { for (Annotation a : annotations) { if (a == null || a.type == null) continue; String annotationName = resolveAnnotationName(a.type.getTypeName()); if (annotationName.equals(annotationClass.getName())) { result[0] = true; break; } } } } }); return result[0]; } private String resolveAnnotationName(char[][] typeName) { StringBuilder b = new StringBuilder(); for (int i = 0; i < typeName.length; i++) { b.append(new String(typeName[i])); if (i < typeName.length - 1) b.append("."); } return b.toString(); } }.handle(); }
From source file:lombok.eclipse.handlers.HandleVetoable.java
License:Apache License
@Override public void handle(final AnnotationValues<Vetoable> annotation, final Annotation source, final EclipseNode annotationNode) { new VetoableHandler<EclipseType, EclipseField, EclipseNode, ASTNode>(annotationNode, source) { @Override/* ww w . j a v a 2 s . c o m*/ protected void addInterface(EclipseType type, String interfaceClassName) { EclipseUtil.addInterface(type.get(), interfaceClassName, source); } @Override protected EclipseType typeOf(EclipseNode node, ASTNode ast) { return EclipseType.typeOf(node, ast); } @Override protected EclipseField fieldOf(EclipseNode node, ASTNode ast) { return EclipseField.fieldOf(node, ast); } @Override protected boolean hasMethodIncludingSupertypes(EclipseType type, String methodName, TypeRef... argumentTypes) { return hasMethod(type.get().binding, methodName, type.editor().build(As.list(argumentTypes))); } private boolean hasMethod(final TypeBinding binding, final String methodName, List<ASTNode> argumentTypes) { if (binding instanceof ReferenceBinding) { ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); for (MethodBinding method : Each.elementIn(availableMethods)) { if (method.isAbstract()) continue; /*if (!method.isPublic()) continue;*/ if (!methodName.equals(As.string(method.selector))) continue; if (argumentTypes.size() != As.list(method.parameters).size()) continue; // TODO check actual types.. return true; } ReferenceBinding superclass = rb.superclass(); ensureAllClassScopeMethodWereBuild(superclass); return hasMethod(superclass, methodName, argumentTypes); } return false; } @Override protected boolean isAnnotatedWith(EclipseType type, Class<? extends java.lang.annotation.Annotation> annotationClass) { Annotation[] annotations = type.get().annotations; if (annotations == null) return false; for (Annotation annotation : annotations) { if (annotation == null || annotation.type == null) continue; String annotationName = resolveAnnotationName(annotation.type.getTypeName()); if (annotationName.equals(annotationClass.getName())) return true; } return false; } @Override protected boolean isAnnotatedWith(final EclipseNode eclipseNode, final Class<? extends java.lang.annotation.Annotation> annotationClass) { final boolean[] result = new boolean[1]; result[0] = false; eclipseNode.traverse(new EclipseASTAdapter() { @Override public void visitAnnotationOnType(TypeDeclaration type, EclipseNode annotationNode, Annotation annotation) { Annotation[] annotations = type.annotations; if (annotations == null) { result[0] = false; } else { for (Annotation a : annotations) { if (a == null || a.type == null) continue; String annotationName = resolveAnnotationName(a.type.getTypeName()); if (annotationName.equals(annotationClass.getName())) { result[0] = true; break; } } } } }); return result[0]; } private String resolveAnnotationName(char[][] typeName) { StringBuilder b = new StringBuilder(); for (int i = 0; i < typeName.length; i++) { b.append(new String(typeName[i])); if (i < typeName.length - 1) b.append("."); } return b.toString(); } }.handle(); }