Example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isAbstract

List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding isAbstract

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isAbstract.

Prototype

public final boolean isAbstract() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java

License:Open Source License

/**
 * Returns whether the given reference type binding matches or is a subtype of a type
 * that matches the given qualified pattern.
 * Returns ACCURATE_MATCH if it does.//www .  ja v a  2 s  .  co m
 * Returns INACCURATE_MATCH if resolve fails
 * Returns IMPOSSIBLE_MATCH if it doesn't.
 */
protected int resolveLevelAsSubtype(char[] simplePattern, char[] qualifiedPattern, ReferenceBinding type,
        char[] methodName, TypeBinding[] argumentTypes, char[] packageName, boolean isDefault) {
    if (type == null)
        return INACCURATE_MATCH;

    int level = resolveLevelForType(simplePattern, qualifiedPattern, type);
    if (level != IMPOSSIBLE_MATCH) {
        if (isDefault && !CharOperation.equals(packageName, type.qualifiedPackageName())) {
            return IMPOSSIBLE_MATCH;
        }
        MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, methodName, argumentTypes);
        if (((method != null && !method.isAbstract()) || !type.isAbstract()) && !type.isInterface()) { // if concrete, then method is overridden
            level |= OVERRIDDEN_METHOD_FLAVOR;
        }
        return level;
    }

    // matches superclass
    if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
        level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, type.superclass(), methodName,
                argumentTypes, packageName, isDefault);
        if (level != IMPOSSIBLE_MATCH) {
            if (argumentTypes != null) {
                // need to verify if method may be overridden
                MethodBinding method = getMethodBinding(type, methodName, argumentTypes);
                if (method != null) { // one method match in hierarchy
                    if ((level & OVERRIDDEN_METHOD_FLAVOR) != 0) {
                        // this method is already overridden on a super class, current match is impossible
                        return IMPOSSIBLE_MATCH;
                    }
                    if (!method.isAbstract() && !type.isInterface()) {
                        // store the fact that the method is overridden
                        level |= OVERRIDDEN_METHOD_FLAVOR;
                    }
                }
            }
            return level | SUB_INVOCATION_FLAVOR; // add flavor to returned level
        }
    }

    // matches interfaces
    ReferenceBinding[] interfaces = type.superInterfaces();
    if (interfaces == null)
        return INACCURATE_MATCH;
    for (int i = 0; i < interfaces.length; i++) {
        level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, interfaces[i], methodName, null,
                packageName, isDefault);
        if (level != IMPOSSIBLE_MATCH) {
            if (!type.isAbstract() && !type.isInterface()) { // if concrete class, then method is overridden
                level |= OVERRIDDEN_METHOD_FLAVOR;
            }
            return level | SUB_INVOCATION_FLAVOR; // add flavor to returned level
        }
    }
    return IMPOSSIBLE_MATCH;
}

From source file:com.google.gwt.dev.javac.Shared.java

License:Open Source License

public static int bindingToModifierBits(MethodBinding binding) {
    int bits = 0;
    bits |= (binding.isPublic() ? MOD_PUBLIC : 0);
    bits |= (binding.isPrivate() ? MOD_PRIVATE : 0);
    bits |= (binding.isProtected() ? MOD_PROTECTED : 0);
    bits |= (binding.isStatic() ? MOD_STATIC : 0);
    bits |= (binding.isFinal() ? MOD_FINAL : 0);
    bits |= (binding.isNative() ? MOD_NATIVE : 0);
    bits |= (binding.isAbstract() ? MOD_ABSTRACT : 0);
    return bits;/*from  w  w  w . j  ava 2s  . c o m*/
}

From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java

License:Apache License

private JMethod processMethodBinding(MethodBinding b, JDeclaredType enclosingType, SourceInfo info) {
    JType returnType = getType(b.returnType);
    JMethod newMethod = program.createMethod(info, String.valueOf(b.selector), enclosingType, returnType,
            b.isAbstract(), b.isStatic(), b.isFinal(), AccessModifier.fromMethodBinding(b), b.isNative());
    addThrownExceptions(b, newMethod);/*from w ww . jav a  2s . c  o  m*/
    if (b.isSynthetic()) {
        newMethod.setSynthetic();
    }

    if (enclosingType.isExternal()) {
        newMethod.setBody(null);
    }
    typeMap.put(b, newMethod);
    return newMethod;
}

From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java

License:Apache License

private void createMethod(AbstractMethodDeclaration x) {
    if (x instanceof Clinit) {
        return;/* w  w w . ja  va2  s.  co  m*/
    }
    SourceInfo info = makeSourceInfo(x);
    MethodBinding b = x.binding;
    ReferenceBinding declaringClass = (ReferenceBinding) b.declaringClass.erasure();
    Set<String> alreadyNamedVariables = Sets.newHashSet();
    JDeclaredType enclosingType = (JDeclaredType) typeMap.get(declaringClass);
    assert !enclosingType.isExternal();
    JMethod method;
    boolean isNested = JdtUtil.isInnerClass(declaringClass);
    if (x.isConstructor()) {
        method = new JConstructor(info, (JClassType) enclosingType);
        if (x.isDefaultConstructor()) {
            ((JConstructor) method).setDefaultConstructor();
        }
        if (x.binding.declaringClass.isEnum()) {
            // Enums have hidden arguments for name and value
            method.addParam(new JParameter(info, "enum$name", typeMap.get(x.scope.getJavaLangString()), true,
                    false, method));
            method.addParam(new JParameter(info, "enum$ordinal", JPrimitiveType.INT, true, false, method));
        }
        // add synthetic args for outer this
        if (isNested) {
            NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
            if (nestedBinding.enclosingInstances != null) {
                for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
                    SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
                    String argName = String.valueOf(arg.name);
                    if (alreadyNamedVariables.contains(argName)) {
                        argName += "_" + i;
                    }
                    createParameter(info, arg, argName, method);
                    alreadyNamedVariables.add(argName);
                }
            }
        }
    } else {
        method = new JMethod(info, intern(b.selector), enclosingType, typeMap.get(b.returnType), b.isAbstract(),
                b.isStatic(), b.isFinal(), AccessModifier.fromMethodBinding(b));
    }

    // User args.
    createParameters(method, x);

    if (x.isConstructor()) {
        if (isNested) {
            // add synthetic args for locals
            NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
            // add synthetic args for outer this and locals
            if (nestedBinding.outerLocalVariables != null) {
                for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
                    SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
                    String argName = String.valueOf(arg.name);
                    if (alreadyNamedVariables.contains(argName)) {
                        argName += "_" + i;
                    }
                    createParameter(info, arg, argName, method);
                    alreadyNamedVariables.add(argName);
                }
            }
        }
    }

    mapExceptions(method, b);

    if (b.isSynthetic()) {
        method.setSynthetic();
    }

    if (b.isDefaultMethod()) {
        method.setDefaultMethod();
    }

    enclosingType.addMethod(method);
    JsInteropUtil.maybeSetJsinteropMethodProperties(x, method);
    processAnnotations(x, method);
    typeMap.setMethod(b, method);
}

From source file:com.google.gwt.dev.jjs.impl.ReferenceMapper.java

License:Apache License

JMethod createMethod(SourceInfo info, MethodBinding b, String[] paramNames) {
    JDeclaredType enclosingType = (JDeclaredType) get(b.declaringClass);
    JMethod method = new JMethod(info, intern(b.selector), enclosingType, get(b.returnType), b.isAbstract(),
            b.isStatic(), b.isFinal(), AccessModifier.fromMethodBinding(b));
    enclosingType.addMethod(method);//from w w  w . j av  a  2s .  c o  m
    if (paramNames == null) {
        mapParameters(info, method, b, 0);
    } else {
        mapParameters(info, method, b, paramNames);
    }
    mapExceptions(method, b);
    if (b.isSynthetic()) {
        method.setSynthetic();
    }
    return method;
}

From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java

License:Open Source License

public JDTMethod(JDTClass enclosingClass, MethodBinding method) {
    this.enclosingClass = enclosingClass;
    bindingRef = new WeakReference<MethodBinding>(method);
    name = new String(method.selector);
    readableName = new String(method.readableName());
    isStatic = method.isStatic();//from ww w  . jav a 2 s  .c  o  m
    isPublic = method.isPublic();
    isConstructor = method.isConstructor();
    isStaticInit = method.selector == TypeConstants.CLINIT; // TODO : check if it is right
    isAbstract = method.isAbstract();
    isFinal = method.isFinal();
    isProtected = method.isProtected();
    isDefaultAccess = method.isDefault();
    isDeclaredVoid = method.returnType.id == TypeIds.T_void;
    isVariadic = method.isVarargs();
    isDefault = method.getDefaultValue() != null;
    bindingKey = method.computeUniqueKey();
    if (method instanceof ProblemMethodBinding) {
        annotations = new HashMap<>();
        parameters = Collections.emptyList();
        returnType = JDTType.UNKNOWN_TYPE;
        typeParameters = Collections.emptyList();
        isOverriding = false;
        isOverloading = false;
    }
}

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);
        }//from w ww .  jav a  2s  .c om
    }
    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 w  w. j  ava2 s  .com
        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  .ja  v a  2 s .  c  om
        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.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 v a2 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();
}