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

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

Introduction

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

Prototype

public final boolean isSynthetic() 

Source Link

Usage

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) {/*from   www  .  ja va 2 s  .c om*/
    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);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

private void selectFrom(Binding binding, CompilationUnitDeclaration parsedUnit, ICompilationUnit unit,
        boolean isDeclaration) {
    if (binding instanceof TypeVariableBinding) {
        TypeVariableBinding typeVariableBinding = (TypeVariableBinding) binding;
        Binding enclosingElement = typeVariableBinding.declaringElement;
        this.noProposal = false;

        if (enclosingElement instanceof SourceTypeBinding) {
            SourceTypeBinding enclosingType = (SourceTypeBinding) enclosingElement;
            if (isLocal(enclosingType) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalTypeParameter(typeVariableBinding);
            } else {
                this.requestor.acceptTypeParameter(enclosingType.qualifiedPackageName(),
                        enclosingType.qualifiedSourceName(), typeVariableBinding.sourceName(), false,
                        this.actualSelectionStart, this.actualSelectionEnd);
            }//w  w  w  .j a va  2s . co  m
        } else if (enclosingElement instanceof MethodBinding) {
            MethodBinding enclosingMethod = (MethodBinding) enclosingElement;
            if (isLocal(enclosingMethod.declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalMethodTypeParameter(typeVariableBinding);
            } else {
                this.requestor.acceptMethodTypeParameter(enclosingMethod.declaringClass.qualifiedPackageName(),
                        enclosingMethod.declaringClass.qualifiedSourceName(),
                        enclosingMethod.isConstructor() ? enclosingMethod.declaringClass.sourceName()
                                : enclosingMethod.selector,
                        enclosingMethod.sourceStart(), enclosingMethod.sourceEnd(),
                        typeVariableBinding.sourceName(), false, this.actualSelectionStart,
                        this.actualSelectionEnd);
            }
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof ReferenceBinding) {
        ReferenceBinding typeBinding = (ReferenceBinding) binding;
        if (typeBinding instanceof ProblemReferenceBinding) {
            TypeBinding closestMatch = typeBinding.closestMatch();
            if (closestMatch instanceof ReferenceBinding) {
                typeBinding = (ReferenceBinding) closestMatch;
            } else {
                typeBinding = null;
            }
        }
        if (typeBinding == null)
            return;
        if (isLocal(typeBinding) && this.requestor instanceof SelectionRequestor) {
            this.noProposal = false;
            ((SelectionRequestor) this.requestor).acceptLocalType(typeBinding);
        } else {
            this.noProposal = false;

            this.requestor.acceptType(typeBinding.qualifiedPackageName(), typeBinding.qualifiedSourceName(),
                    typeBinding.modifiers, false, typeBinding.computeUniqueKey(), this.actualSelectionStart,
                    this.actualSelectionEnd);
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof MethodBinding) {
        MethodBinding methodBinding = getCorrectMethodBinding((MethodBinding) binding);
        this.noProposal = false;

        boolean isValuesOrValueOf = false;
        if (binding instanceof SyntheticMethodBinding) {
            SyntheticMethodBinding syntheticMethodBinding = (SyntheticMethodBinding) binding;
            if (syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValues
                    || syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValueOf) {
                isValuesOrValueOf = true;
            }
        }

        if (!isValuesOrValueOf && !methodBinding.isSynthetic()) {
            TypeBinding[] parameterTypes = methodBinding.original().parameters;
            int length = parameterTypes.length;
            char[][] parameterPackageNames = new char[length][];
            char[][] parameterTypeNames = new char[length][];
            String[] parameterSignatures = new String[length];
            for (int i = 0; i < length; i++) {
                parameterPackageNames[i] = parameterTypes[i].qualifiedPackageName();
                parameterTypeNames[i] = parameterTypes[i].qualifiedSourceName();
                parameterSignatures[i] = new String(getSignature(parameterTypes[i])).replace('/', '.');
            }

            TypeVariableBinding[] typeVariables = methodBinding.original().typeVariables;
            length = typeVariables == null ? 0 : typeVariables.length;
            char[][] typeParameterNames = new char[length][];
            char[][][] typeParameterBoundNames = new char[length][][];
            for (int i = 0; i < length; i++) {
                TypeVariableBinding typeVariable = typeVariables[i];
                typeParameterNames[i] = typeVariable.sourceName;
                if (typeVariable.firstBound == null) {
                    typeParameterBoundNames[i] = new char[0][];
                } else if (TypeBinding.equalsEquals(typeVariable.firstBound, typeVariable.superclass)) {
                    int boundCount = 1
                            + (typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length);
                    typeParameterBoundNames[i] = new char[boundCount][];
                    typeParameterBoundNames[i][0] = typeVariable.superclass.sourceName;
                    for (int j = 1; j < boundCount; j++) {
                        typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j - 1].sourceName;
                    }
                } else {
                    int boundCount = typeVariable.superInterfaces == null ? 0
                            : typeVariable.superInterfaces.length;
                    typeParameterBoundNames[i] = new char[boundCount][];
                    for (int j = 0; j < boundCount; j++) {
                        typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j].sourceName;
                    }
                }
            }

            ReferenceBinding declaringClass = methodBinding.declaringClass;
            if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalMethod(methodBinding);
            } else {
                this.requestor.acceptMethod(declaringClass.qualifiedPackageName(),
                        declaringClass.qualifiedSourceName(),
                        declaringClass.enclosingType() == null ? null
                                : new String(getSignature(declaringClass.enclosingType())),
                        methodBinding.isConstructor() ? declaringClass.sourceName() : methodBinding.selector,
                        parameterPackageNames, parameterTypeNames, parameterSignatures, typeParameterNames,
                        typeParameterBoundNames, methodBinding.isConstructor(), isDeclaration,
                        methodBinding.computeUniqueKey(), this.actualSelectionStart, this.actualSelectionEnd);
            }
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof FieldBinding) {
        FieldBinding fieldBinding = (FieldBinding) binding;
        ReferenceBinding declaringClass = fieldBinding.declaringClass;
        if (declaringClass != null) { // arraylength
            this.noProposal = false;
            if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalField(fieldBinding);
            } else {
                // if the binding is a problem field binding, we want to make sure
                // we can retrieve the closestMatch if the problem reason is NotVisible
                FieldBinding currentFieldBinding = fieldBinding;
                while (currentFieldBinding instanceof ProblemFieldBinding) {
                    ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) currentFieldBinding;
                    if (problemFieldBinding.problemId() == ProblemReasons.NotVisible) {
                        currentFieldBinding = problemFieldBinding.closestMatch;
                    } else {
                        currentFieldBinding = null;
                    }
                }
                char[] fieldName = null;
                char[] key = null;
                if (currentFieldBinding != null) {
                    fieldName = currentFieldBinding.name;
                    key = currentFieldBinding.computeUniqueKey();
                } else {
                    fieldName = fieldBinding.name;
                    key = fieldBinding.computeUniqueKey();
                }
                this.requestor.acceptField(declaringClass.qualifiedPackageName(),
                        declaringClass.qualifiedSourceName(), fieldName, false, key, this.actualSelectionStart,
                        this.actualSelectionEnd);
            }
            this.acceptedAnswer = true;
        }
    } else if (binding instanceof LocalVariableBinding) {
        if (this.requestor instanceof SelectionRequestor) {
            ((SelectionRequestor) this.requestor).acceptLocalVariable((LocalVariableBinding) binding, unit);
            this.acceptedAnswer = true;
        } else {
            // open on the type of the variable
            selectFrom(((LocalVariableBinding) binding).type, parsedUnit, false);
        }
    } else if (binding instanceof ArrayBinding) {
        selectFrom(((ArrayBinding) binding).leafComponentType, parsedUnit, false);
        // open on the type of the array
    } else if (binding instanceof PackageBinding) {
        PackageBinding packageBinding = (PackageBinding) binding;
        this.noProposal = false;
        this.requestor.acceptPackage(packageBinding.readableName());
        this.acceptedAnswer = true;
    } else if (binding instanceof BaseTypeBinding) {
        this.acceptedAnswer = true;
    }
}

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  w  w.j a v a 2 s.  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;/*from w  w  w.j  av a2s.c o  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 createConstructor(SourceInfo info, MethodBinding b) {
    JDeclaredType enclosingType = (JDeclaredType) get(b.declaringClass);
    JMethod method = new JConstructor(info, (JClassType) enclosingType);
    enclosingType.addMethod(method);/*from  ww  w .j  a v a 2s . c o m*/

    /*
     * Don't need to synthesize enum intrinsic args because enum ctors can only
     * be called locally.
     */

    int argPosition = 0;

    ReferenceBinding declaringClass = b.declaringClass;
    if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
        // add synthetic args for outer this
        if (declaringClass.syntheticEnclosingInstanceTypes() != null) {
            for (ReferenceBinding argType : declaringClass.syntheticEnclosingInstanceTypes()) {
                createParameter(info, argType, method, argPosition++);
            }
        }
    }

    // User args.
    argPosition = mapParameters(info, method, b, argPosition);

    if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
        // add synthetic args for locals
        if (declaringClass.syntheticOuterLocalVariables() != null) {
            for (SyntheticArgumentBinding arg : declaringClass.syntheticOuterLocalVariables()) {
                createParameter(info, arg.type, method, argPosition++);
            }
        }
    }

    mapExceptions(method, b);
    if (b.isSynthetic()) {
        method.setSynthetic();
    }
    return 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  ww w. ja va  2s.c  om
    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.UnknownClassMirror.java

License:Open Source License

@Override
public List<MethodMirror> getDirectMethods() {
    if (methods == null) {
        doWithBindings(new ActionOnClassBinding() {
            @Override//from   www  .jav  a  2  s.co m
            public void doWithBinding(IType classModel, ReferenceBinding klass) {
                MethodBinding[] directMethods;
                directMethods = klass.methods();
                methods = new ArrayList<MethodMirror>(directMethods.length);
                for (MethodBinding method : directMethods) {
                    if (!method.isBridge() && !method.isSynthetic() && !method.isPrivate())
                        methods.add(new JDTMethod(JDTClass.this, method));
                }
            }
        });
    }
    return methods;
}

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

License:Open Source License

private boolean isOverloadingInType(ReferenceBinding superClass, MethodBinding method) {
    MethodVerifier methodVerifier = superClass.getPackage().environment.methodVerifier();
    for (MethodBinding inheritedMethod : superClass.methods()) {
        if (inheritedMethod.isPrivate() || inheritedMethod.isStatic() || inheritedMethod.isConstructor()
                || inheritedMethod.isBridge() || inheritedMethod.isSynthetic()
                || !Arrays.equals(inheritedMethod.constantPoolName(), method.selector))
            continue;

        // skip ignored methods
        if (ignoreMethodInAncestorSearch(inheritedMethod)) {
            continue;
        }//from w  w  w. j av  a 2 s  .com

        // if it does not override it and has the same name, it's overloading
        if (!methodVerifier.doesMethodOverride(method, inheritedMethod)) {
            return true;
        }
    }
    return false;
}

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;/* ww  w .j  a  v a  2 s .c o 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:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java

License:Open Source License

/**
 * This method realizes the logic of the mapping for methods.
 * @param srcMethod         where to copy from
 * @param refMethodBinding  what to copy/remap
 * @param dstTeam           where to copy to
 * @param addMarkerArgAllowed whether copying is allowed to add a marker arg
 * @return destination method/*from  w  ww  .  j  ava  2  s .  c o  m*/
 */
public static MethodBinding mapMethod(MethodBinding srcMethod, MethodBinding refMethodBinding,
        MethodBinding dstMethod, ReferenceBinding dstTeam, boolean addMarkerArgAllowed) {
    if (dstMethod != null) {
        if (dstMethod.model != null) {
            if (dstMethod.model.oldSelfcall == refMethodBinding)
                return dstMethod.model.adjustedSelfcall;
        }
        if (isConfinedSuperCtor(srcMethod, refMethodBinding))
            return getConfinedSuperCtor(dstMethod);
    }
    // if Binding points at Role-Method of Superteamclass, then mapping must be done
    if (isMappableMethod(refMethodBinding)) {
        if (refMethodBinding.isSynthetic()) {
            RoleModel role = ((ReferenceBinding) mapClass(srcMethod, refMethodBinding.declaringClass,
                    dstTeam)).roleModel;
            if (role != null) {
                MethodBinding foundMethod = role.mapSyntheticMethod(refMethodBinding);
                if (foundMethod != null)
                    return foundMethod;
            }
        }
        boolean isDecapsAccessor = false;
        if (CharOperation.prefixEquals(IOTConstants.OT_DECAPS, refMethodBinding.selector)) {
            // to find a decapsulated method, first strip off the accessor's prefix, then search and ...
            refMethodBinding = new MethodBinding(refMethodBinding, refMethodBinding.declaringClass);
            refMethodBinding.selector = CharOperation.subarray(refMethodBinding.selector,
                    IOTConstants.OT_DECAPS.length, -1);
            isDecapsAccessor = true;
        }
        MethodBinding foundMethod = doMapMethod(srcMethod, refMethodBinding, dstMethod, dstTeam,
                addMarkerArgAllowed);
        if (foundMethod != null && isDecapsAccessor) {
            // .. append the stripped prefix after finding
            foundMethod = new MethodBinding(foundMethod, foundMethod.declaringClass);
            foundMethod.selector = CharOperation.concat(IOTConstants.OT_DECAPS, foundMethod.selector);
        }
        return foundMethod;
    }
    return refMethodBinding;
}