Example usage for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccGenericSignature

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccGenericSignature

Introduction

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

Prototype

int AccGenericSignature

To view the source code for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccGenericSignature.

Click Source Link

Usage

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

License:Open Source License

public static char[] getSignature(MethodBinding methodBinding) {
    char[] result = null;

    int oldMod = methodBinding.modifiers;
    //TODO remove the next line when method from binary type will be able to generate generic signature
    methodBinding.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
    result = methodBinding.genericSignature();
    if (result == null) {
        result = methodBinding.signature();
    }//from   w ww  .j  a v  a2  s.com
    methodBinding.modifiers = oldMod;

    if (result != null) {
        result = CharOperation.replaceOnCopy(result, '/', '.');
    }
    return result;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15.java

License:Open Source License

boolean hasGenericParameter(MethodBinding method) {
    if (method.genericSignature() == null)
        return false;

    // may be only the return type that is generic, need to check parameters
    TypeBinding[] params = method.parameters;
    for (int i = 0, l = params.length; i < l; i++) {
        TypeBinding param = params[i].leafComponentType();
        if (param instanceof ReferenceBinding) {
            int modifiers = ((ReferenceBinding) param).modifiers;
            if ((modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0)
                return true;
        }/*from   w  w  w  .  j a  v a  2s.  c o m*/
    }
    return false;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java

License:Open Source License

public char[] computeGenericTypeSignature(TypeVariableBinding[] typeVariables) {

    boolean isMemberOfGeneric = isMemberType()
            && (enclosingType().modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0;
    if (typeVariables == Binding.NO_TYPE_VARIABLES && !isMemberOfGeneric) {
        return signature();
    }/*from  ww  w  .  ja v a  2 s  .c  om*/
    StringBuffer sig = new StringBuffer(10);
    if (isMemberOfGeneric) {
        char[] typeSig = enclosingType().genericTypeSignature();
        sig.append(typeSig, 0, typeSig.length - 1); // copy all but trailing semicolon
        sig.append('.'); // NOTE: cannot override trailing ';' with '.' in enclosing signature, since shared char[]
        sig.append(this.sourceName);
    } else {
        char[] typeSig = signature();
        sig.append(typeSig, 0, typeSig.length - 1); // copy all but trailing semicolon
    }
    if (typeVariables == Binding.NO_TYPE_VARIABLES) {
        sig.append(';');
    } else {
        sig.append('<');
        for (int i = 0, length = typeVariables.length; i < length; i++) {
            sig.append(typeVariables[i].genericTypeSignature());
        }
        sig.append(">;"); //$NON-NLS-1$
    }
    int sigLength = sig.length();
    char[] result = new char[sigLength];
    sig.getChars(0, sigLength, result, 0);
    return result;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding resolveTypeFor(FieldBinding field) {
    if ((field.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
        return field;

    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
        if ((field.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
            field.modifiers |= ClassFileConstants.AccDeprecated;
    }//from  w  ww . java2  s .c o  m
    if (isViewedAsDeprecated() && !field.isDeprecated())
        field.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
    if (hasRestrictedAccess())
        field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
    FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields;
    int length = fieldDecls == null ? 0 : fieldDecls.length;
    for (int f = 0; f < length; f++) {
        if (fieldDecls[f].binding != field)
            continue;

        MethodScope initializationScope = field.isStatic() ? this.scope.referenceContext.staticInitializerScope
                : this.scope.referenceContext.initializerScope;
        FieldBinding previousField = initializationScope.initializedField;
        try {
            initializationScope.initializedField = field;
            FieldDeclaration fieldDecl = fieldDecls[f];
            TypeBinding fieldType = fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT
                    ? initializationScope.environment().convertToRawType(this,
                            false /*do not force conversion of enclosing types*/) // enum constant is implicitly of declaring enum type
                    : fieldDecl.type.resolveType(initializationScope, true /* check bounds*/);
            field.type = fieldType;
            field.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            if (fieldType == null) {
                fieldDecl.binding = null;
                return null;
            }
            if (fieldType == TypeBinding.VOID) {
                this.scope.problemReporter().variableTypeCannotBeVoid(fieldDecl);
                fieldDecl.binding = null;
                return null;
            }
            if (fieldType.isArrayType() && ((ArrayBinding) fieldType).leafComponentType == TypeBinding.VOID) {
                this.scope.problemReporter().variableTypeCannotBeVoidArray(fieldDecl);
                fieldDecl.binding = null;
                return null;
            }
            if ((fieldType.tagBits & TagBits.HasMissingType) != 0) {
                field.tagBits |= TagBits.HasMissingType;
            }
            TypeBinding leafType = fieldType.leafComponentType();
            if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                    & ExtraCompilerModifiers.AccGenericSignature) != 0) {
                field.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
            }
        } finally {
            initializationScope.initializedField = previousField;
        }
        return field;
    }
    return null; // should never reach this point
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public MethodBinding resolveTypesFor(MethodBinding method) {
    if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
        return method;

    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
        if ((method.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
            method.modifiers |= ClassFileConstants.AccDeprecated;
    }//from  w w  w .ja  v  a  2s  .c  o  m
    if (isViewedAsDeprecated() && !method.isDeprecated())
        method.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
    if (hasRestrictedAccess())
        method.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;

    AbstractMethodDeclaration methodDecl = method.sourceMethod();
    // GROOVY
    /* old {
    if (methodDecl == null) return null; // method could not be resolved in previous iteration
     } new*/
    if (methodDecl == null) {
        if (method instanceof LazilyResolvedMethodBinding) {
            LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method;
            // the rest is a copy of the code below but doesn't depend on the method declaration
            // nothing to do for method type parameters (there are none)
            // nothing to do for method exceptions (there are none)
            TypeBinding ptb = lrMethod.getParameterTypeBinding();
            if (ptb == null) {
                method.parameters = Binding.NO_PARAMETERS;
            } else {
                method.parameters = new TypeBinding[] { ptb };
            }
            method.returnType = lrMethod.getReturnTypeBinding();
            method.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            return method;
        }
        // returning null is what this clause would have done anyway
        return null;
    }
    // FIXASC - end

    TypeParameter[] typeParameters = methodDecl.typeParameters();
    if (typeParameters != null) {
        methodDecl.scope.connectTypeVariables(typeParameters, true);
        // Perform deferred bound checks for type variables (only done after type variable hierarchy is connected)
        for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++)
            typeParameters[i].checkBounds(methodDecl.scope);
    }
    TypeReference[] exceptionTypes = methodDecl.thrownExceptions;
    if (exceptionTypes != null) {
        int size = exceptionTypes.length;
        method.thrownExceptions = new ReferenceBinding[size];
        int count = 0;
        ReferenceBinding resolvedExceptionType;
        for (int i = 0; i < size; i++) {
            resolvedExceptionType = (ReferenceBinding) exceptionTypes[i].resolveType(methodDecl.scope,
                    true /* check bounds*/);
            if (resolvedExceptionType == null)
                continue;
            if (resolvedExceptionType.isBoundParameterizedType()) {
                methodDecl.scope.problemReporter().invalidParameterizedExceptionType(resolvedExceptionType,
                        exceptionTypes[i]);
                continue;
            }
            if (resolvedExceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null) {
                if (resolvedExceptionType.isValidBinding()) {
                    methodDecl.scope.problemReporter().cannotThrowType(exceptionTypes[i],
                            resolvedExceptionType);
                    continue;
                }
            }
            if ((resolvedExceptionType.tagBits & TagBits.HasMissingType) != 0) {
                method.tagBits |= TagBits.HasMissingType;
            }
            method.modifiers |= (resolvedExceptionType.modifiers & ExtraCompilerModifiers.AccGenericSignature);
            method.thrownExceptions[count++] = resolvedExceptionType;
        }
        if (count < size)
            System.arraycopy(method.thrownExceptions, 0, method.thrownExceptions = new ReferenceBinding[count],
                    0, count);
    }
    final boolean reportUnavoidableGenericTypeProblems = this.scope
            .compilerOptions().reportUnavoidableGenericTypeProblems;
    boolean foundArgProblem = false;
    Argument[] arguments = methodDecl.arguments;
    if (arguments != null) {
        int size = arguments.length;
        method.parameters = Binding.NO_PARAMETERS;
        TypeBinding[] newParameters = new TypeBinding[size];
        for (int i = 0; i < size; i++) {
            Argument arg = arguments[i];
            if (arg.annotations != null) {
                method.tagBits |= TagBits.HasParameterAnnotations;
            }
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817
            boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && !method.isConstructor()
                    && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0;
            TypeBinding parameterType;
            if (deferRawTypeCheck) {
                arg.type.bits |= ASTNode.IgnoreRawTypeCheck;
            }
            try {
                parameterType = arg.type.resolveType(methodDecl.scope, true /* check bounds*/);
            } finally {
                if (deferRawTypeCheck) {
                    arg.type.bits &= ~ASTNode.IgnoreRawTypeCheck;
                }
            }

            if (parameterType == null) {
                foundArgProblem = true;
            } else if (parameterType == TypeBinding.VOID) {
                methodDecl.scope.problemReporter().argumentTypeCannotBeVoid(this, methodDecl, arg);
                foundArgProblem = true;
            } else {
                if ((parameterType.tagBits & TagBits.HasMissingType) != 0) {
                    method.tagBits |= TagBits.HasMissingType;
                }
                TypeBinding leafType = parameterType.leafComponentType();
                if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                        & ExtraCompilerModifiers.AccGenericSignature) != 0)
                    method.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
                newParameters[i] = parameterType;
                arg.binding = new LocalVariableBinding(arg, parameterType, arg.modifiers, true);
            }
        }
        // only assign parameters if no problems are found
        if (!foundArgProblem) {
            method.parameters = newParameters;
        }
    }

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337799
    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7) {
        if ((method.tagBits & TagBits.AnnotationSafeVarargs) != 0) {
            if (!method.isVarargs()) {
                methodDecl.scope.problemReporter().safeVarargsOnFixedArityMethod(method);
            } else if (!method.isStatic() && !method.isFinal() && !method.isConstructor()) {
                methodDecl.scope.problemReporter().safeVarargsOnNonFinalInstanceMethod(method);
            }
        } else if (method.parameters != null && method.parameters.length > 0 && method.isVarargs()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795
            if (!method.parameters[method.parameters.length - 1].isReifiable()) {
                methodDecl.scope.problemReporter()
                        .possibleHeapPollutionFromVararg(methodDecl.arguments[methodDecl.arguments.length - 1]);
            }
        }
    }

    boolean foundReturnTypeProblem = false;
    if (!method.isConstructor()) {
        TypeReference returnType = methodDecl instanceof MethodDeclaration
                ? ((MethodDeclaration) methodDecl).returnType
                : null;
        if (returnType == null) {
            methodDecl.scope.problemReporter().missingReturnType(methodDecl);
            method.returnType = null;
            foundReturnTypeProblem = true;
        } else {
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817
            boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems
                    && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0;
            TypeBinding methodType;
            if (deferRawTypeCheck) {
                returnType.bits |= ASTNode.IgnoreRawTypeCheck;
            }
            try {
                methodType = returnType.resolveType(methodDecl.scope, true /* check bounds*/);
            } finally {
                if (deferRawTypeCheck) {
                    returnType.bits &= ~ASTNode.IgnoreRawTypeCheck;
                }
            }
            if (methodType == null) {
                foundReturnTypeProblem = true;
            } else if (methodType.isArrayType()
                    && ((ArrayBinding) methodType).leafComponentType == TypeBinding.VOID) {
                methodDecl.scope.problemReporter().returnTypeCannotBeVoidArray((MethodDeclaration) methodDecl);
                foundReturnTypeProblem = true;
            } else {
                if ((methodType.tagBits & TagBits.HasMissingType) != 0) {
                    method.tagBits |= TagBits.HasMissingType;
                }
                method.returnType = methodType;
                TypeBinding leafType = methodType.leafComponentType();
                if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                        & ExtraCompilerModifiers.AccGenericSignature) != 0)
                    method.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
            }
        }
    }
    if (foundArgProblem) {
        methodDecl.binding = null;
        method.parameters = Binding.NO_PARAMETERS; // see 107004
        // nullify type parameter bindings as well as they have a backpointer to the method binding
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=81134)
        if (typeParameters != null)
            for (int i = 0, length = typeParameters.length; i < length; i++)
                typeParameters[i].binding = null;
        return null;
    }
    if (foundReturnTypeProblem)
        return method; // but its still unresolved with a null return type & is still connected to its method declaration

    method.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
    return method;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

private void initialize(ReferenceBinding roleType, ITeamAnchor teamAnchor) {
    // FIXME(SH): is it OK to strip ParameterizedFields?
    if (teamAnchor instanceof ParameterizedFieldBinding)
        teamAnchor = ((ParameterizedFieldBinding) teamAnchor).original();

    initializeDependentType(teamAnchor, -1); // role type bindings have no explicit value parameters

    // infer argument position.
    ITeamAnchor firstAnchorSegment = teamAnchor.getBestNamePath()[0];
    if (firstAnchorSegment instanceof LocalVariableBinding
            && (((LocalVariableBinding) firstAnchorSegment).tagBits & TagBits.IsArgument) != 0) {
        LocalVariableBinding argumentBinding = (LocalVariableBinding) firstAnchorSegment;
        this._argumentPosition = argumentBinding.resolvedPosition;
        final MethodScope methodScope = argumentBinding.declaringScope.methodScope();
        if (methodScope != null)
            // if scope is a callout, role method may not yet be resolved, defer:
            this._declaringMethod = new IMethodProvider() {
                private MethodBinding binding;

                public MethodBinding getMethod() {
                    if (this.binding == null)
                        this.binding = methodScope.referenceMethodBinding();
                    return this.binding;
                }/* w ww . ja  va  2 s  .c  o  m*/
            };
    }

    // compute the team:
    if (CharOperation.equals(roleType.compoundName, IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED))
        // the following is needed in order to break the circularity
        // of roles extending the predefined Team.__OT__Confined (see class comment)
        this._staticallyKnownTeam = roleType.enclosingType();
    else if (teamAnchor == NoAnchor)
        this._staticallyKnownTeam = roleType.enclosingType();
    else
        teamAnchor.setStaticallyKnownTeam(this);

    assert (this._staticallyKnownTeam.isTeam());

    // compute role class and role interface (by name manipulation):
    if (RoleSplitter.isClassPartName(roleType.sourceName)) {
        this._staticallyKnownRoleClass = roleType.getRealClass();
        char[] typeName = RoleSplitter.getInterfacePartName(roleType.sourceName);
        this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(typeName);
    } else {
        this._staticallyKnownRoleType = roleType.getRealType();
        char[] className = CharOperation.concat(OT_DELIM_NAME, this._staticallyKnownRoleType.sourceName);
        this._staticallyKnownRoleClass = this._staticallyKnownTeam.getMemberType(className);
        this._staticallyKnownRoleClass = transferTypeArguments(this._staticallyKnownRoleClass);
    }
    this._staticallyKnownRoleType = transferTypeArguments(this._staticallyKnownRoleType);

    this._declaredRoleType = this._staticallyKnownRoleType;
    // keep these consistent with _declaredRoleType:
    this.roleModel = this._declaredRoleType.roleModel;
    this._teamModel = this._declaredRoleType.getTeamModel();

    assert TypeBinding.equalsEquals(this._staticallyKnownTeam.getRealClass(),
            roleType.enclosingType()) : "weakening not using WeakenedTypeBinding"; //$NON-NLS-1$
    // some adjustments after all fields are known:
    if (TypeBinding.notEquals(this._staticallyKnownTeam, roleType.enclosingType()))
        this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(roleType.sourceName);
    if (this._staticallyKnownRoleClass != null)
        this.modifiers = this._staticallyKnownRoleClass.modifiers;
    // after we might have overwritten the modifiers restore some bits in the vein of ParameterizedTypeBinding:
    if (this.arguments != null) {
        this.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
    } else if (this.enclosingType() != null) {
        this.modifiers |= (this.enclosingType().modifiers & ExtraCompilerModifiers.AccGenericSignature);
        this.tagBits |= this.enclosingType().tagBits & (TagBits.HasTypeVariable | TagBits.HasMissingType);
    }

    // record as known role type at teamAnchor and in our own cache
    registerAnchor();
}