Example usage for org.eclipse.jdt.internal.compiler.ast ASTNode IgnoreRawTypeCheck

List of usage examples for org.eclipse.jdt.internal.compiler.ast ASTNode IgnoreRawTypeCheck

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ASTNode IgnoreRawTypeCheck.

Prototype

int IgnoreRawTypeCheck

To view the source code for org.eclipse.jdt.internal.compiler.ast ASTNode IgnoreRawTypeCheck.

Click Source Link

Usage

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

License:Open Source License

void reportRawReferences() {
    CompilerOptions compilerOptions = this.type.scope.compilerOptions();
    if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5 // shouldn't whine at all
            || compilerOptions.reportUnavoidableGenericTypeProblems) { // must have already whined 
        return;//from   w ww  .  j  a v a2s  .  c o m
    }
    /* Code below is only for a method that does not override/implement a super type method. If it were to,
       it would have been handled in checkAgainstInheritedMethods.
    */
    Object[] methodArray = this.currentMethods.valueTable;
    for (int s = methodArray.length; --s >= 0;) {
        if (methodArray[s] == null)
            continue;
        MethodBinding[] current = (MethodBinding[]) methodArray[s];
        for (int i = 0, length = current.length; i < length; i++) {
            MethodBinding currentMethod = current[i];
            if ((currentMethod.modifiers
                    & (ExtraCompilerModifiers.AccImplementing | ExtraCompilerModifiers.AccOverriding)) == 0) {
                AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod();
                if (methodDecl == null)
                    return;
                TypeBinding[] parameterTypes = currentMethod.parameters;
                Argument[] arguments = methodDecl.arguments;
                for (int j = 0, size = currentMethod.parameters.length; j < size; j++) {
                    TypeBinding parameterType = parameterTypes[j];
                    Argument arg = arguments[j];
                    if (parameterType.leafComponentType().isRawType()
                            && compilerOptions
                                    .getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore
                            && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0) {
                        methodDecl.scope.problemReporter().rawTypeReference(arg.type, parameterType);
                    }
                }
                if (!methodDecl.isConstructor() && methodDecl instanceof MethodDeclaration) {
                    TypeReference returnType = ((MethodDeclaration) methodDecl).returnType;
                    TypeBinding methodType = currentMethod.returnType;
                    if (returnType != null) {
                        if (methodType.leafComponentType().isRawType()
                                && compilerOptions.getSeverity(
                                        CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore
                                && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0) {
                            methodDecl.scope.problemReporter().rawTypeReference(returnType, methodType);
                        }
                    }
                }
            }
        }
    }
}

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

License:Open Source License

public void reportRawReferences(MethodBinding currentMethod, MethodBinding inheritedMethod) {
    CompilerOptions compilerOptions = this.type.scope.compilerOptions();
    if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5 // shouldn't whine at all
            || compilerOptions.reportUnavoidableGenericTypeProblems) { // must have already whined 
        return;/*from   w w  w .  ja  v  a  2  s .co m*/
    }
    AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod();
    if (methodDecl == null)
        return;
    TypeBinding[] parameterTypes = currentMethod.parameters;
    TypeBinding[] inheritedParameterTypes = inheritedMethod.parameters;
    Argument[] arguments = methodDecl.arguments;
    for (int j = 0, size = currentMethod.parameters.length; j < size; j++) {
        TypeBinding parameterType = parameterTypes[j];
        TypeBinding inheritedParameterType = inheritedParameterTypes[j];
        Argument arg = arguments[j];
        if (parameterType.leafComponentType().isRawType()) {
            if (inheritedParameterType.leafComponentType().isRawType()) {
                arg.binding.tagBits |= TagBits.ForcedToBeRawType;
            } else {
                if (compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore
                        && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0) {
                    methodDecl.scope.problemReporter().rawTypeReference(arg.type, parameterType);
                }
            }
        }
    }
    TypeReference returnType = null;
    if (!methodDecl.isConstructor() && methodDecl instanceof MethodDeclaration
            && (returnType = ((MethodDeclaration) methodDecl).returnType) != null) {
        final TypeBinding inheritedMethodType = inheritedMethod.returnType;
        final TypeBinding methodType = currentMethod.returnType;
        if (methodType.leafComponentType().isRawType()) {
            if (inheritedMethodType.leafComponentType().isRawType()) {
                // 
            } else {
                if ((returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0 && compilerOptions
                        .getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
                    methodDecl.scope.problemReporter().rawTypeReference(returnType, methodType);
                }
            }
        }
    }
}

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;
    }/* ww w . j  a  v a2  s  .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.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeArrayCreationExpressionWithInitializer() {
    // ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer
    // ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer

    int length;//from   w w w. ja  va  2  s  . c o  m
    ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression();
    this.expressionLengthPtr--;
    arrayAllocation.initializer = (ArrayInitializer) this.expressionStack[this.expressionPtr--];

    arrayAllocation.type = getTypeReference(0);
    arrayAllocation.type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage
    length = (this.expressionLengthStack[this.expressionLengthPtr--]);
    this.expressionPtr -= length;
    System.arraycopy(this.expressionStack, this.expressionPtr + 1,
            arrayAllocation.dimensions = new Expression[length], 0, length);
    arrayAllocation.sourceStart = this.intStack[this.intPtr--];
    if (arrayAllocation.initializer == null) {
        arrayAllocation.sourceEnd = this.endStatementPosition;
    } else {
        arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd;
    }
    pushOnExpressionStack(arrayAllocation);
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeArrayCreationExpressionWithoutInitializer() {
    // ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs
    // ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs

    int length;/*from  w  w w  . j a  va2  s  .  c om*/
    ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression();
    arrayAllocation.type = getTypeReference(0);
    arrayAllocation.type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage
    length = (this.expressionLengthStack[this.expressionLengthPtr--]);
    this.expressionPtr -= length;
    System.arraycopy(this.expressionStack, this.expressionPtr + 1,
            arrayAllocation.dimensions = new Expression[length], 0, length);
    arrayAllocation.sourceStart = this.intStack[this.intPtr--];
    if (arrayAllocation.initializer == null) {
        arrayAllocation.sourceEnd = this.endStatementPosition;
    } else {
        arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd;
    }
    pushOnExpressionStack(arrayAllocation);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

/**
 * Note: only use this if you are positively sure that compoundName contains no '$'!
 *//*from ww  w .  j av  a  2 s. c o  m*/
public QualifiedTypeReference qualifiedTypeReference(char[][] compoundName) {
    long[] poss = new long[compoundName.length];
    Arrays.fill(poss, this.pos);
    QualifiedTypeReference reference = new QualifiedTypeReference(compoundName, poss);
    reference.bits |= ASTNode.IgnoreRawTypeCheck;
    reference.isGenerated = true;
    return reference;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

public QualifiedTypeReference qualifiedArrayTypeReference(char[][] compoundName, int dims) {
    long[] poss = new long[compoundName.length];
    Arrays.fill(poss, this.pos);
    ArrayQualifiedTypeReference reference = new ArrayQualifiedTypeReference(compoundName, dims, poss);
    reference.bits |= ASTNode.IgnoreRawTypeCheck;
    reference.isGenerated = true;// www .j  a  v a  2s . co m
    return reference;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

public TypeReference typeReference(TypeBinding type, boolean makeGeneric) {
    int dims = 0;
    TypeBinding elementType = type;/*  w  ww  .jav a2s  .  c  om*/

    if (type instanceof ArrayBinding) {
        ArrayBinding ab = (ArrayBinding) type;
        dims = ab.dimensions;
        elementType = ab.leafComponentType;
    }
    TypeReference typeReference = createArrayTypeReference(elementType, dims, makeGeneric);
    typeReference.bits |= ASTNode.IgnoreRawTypeCheck;
    typeReference.isGenerated = true;
    typeReference.deprecationProblemId = 0;
    if (!type.isValidBinding())
        typeReference.bits |= ASTNode.IsGeneratedWithProblem;
    return typeReference;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

public TypeReference baseclassReference(TypeBinding type, boolean erase) {
    erase &= type.isParameterizedType();
    if (erase)//from w w  w .  jav  a 2  s . c o m
        type = type.erasure();
    TypeReference result = typeReference(type);
    result.setBaseclassDecapsulation(DecapsulationState.REPORTED);
    TypeReference[] parameters = null;
    if (result instanceof ParameterizedSingleTypeReference)
        parameters = ((ParameterizedSingleTypeReference) result).typeArguments;
    else if (result instanceof ParameterizedQualifiedTypeReference) {
        TypeReference[][] allParams = ((ParameterizedQualifiedTypeReference) result).typeArguments;
        if (allParams != null)
            parameters = allParams[allParams.length - 1]; // TODO for now only treat the last set of params
    }
    if (parameters != null)
        for (TypeReference parameter : parameters)
            parameter.setBaseclassDecapsulation(DecapsulationState.REPORTED);

    if (erase)
        result.bits |= ASTNode.IgnoreRawTypeCheck;
    return result;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

public TypeReference createArrayTypeReference(TypeBinding elementType, int dims) {
    TypeReference typeReference = createArrayTypeReference(elementType, dims, true);
    typeReference.deprecationProblemId = 0;
    typeReference.bits |= ASTNode.IgnoreRawTypeCheck;
    typeReference.isGenerated = true;/*from  w  w  w . java2  s  .  c  o  m*/
    return typeReference;
}