Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.TypeBinding#isValidBinding()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.TypeBinding#isValidBinding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASTNode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static TypeBinding mergeAnnotationsIntoType(BlockScope scope, AnnotationBinding[] se8Annotations, long se8nullBits, Annotation se8NullAnnotation, TypeReference typeRef, TypeBinding existingType) { if (existingType == null || !existingType.isValidBinding()) return existingType; TypeReference unionRef = typeRef.isUnionType() ? ((UnionTypeReference) typeRef).typeReferences[0] : null; // for arrays: @T X[] SE7 associates @T to the type, but in SE8 it affects the leaf component type long prevNullBits = existingType.leafComponentType().tagBits & TagBits.AnnotationNullMASK; if (se8nullBits != 0 && prevNullBits != se8nullBits && ((prevNullBits | se8nullBits) == TagBits.AnnotationNullMASK)) { scope.problemReporter().contradictoryNullAnnotations(se8NullAnnotation); } TypeBinding oldLeafType = (unionRef == null) ? existingType.leafComponentType() : unionRef.resolvedType; AnnotationBinding [][] goodies = new AnnotationBinding[typeRef.getAnnotatableLevels()][]; goodies[0] = se8Annotations; // @T X.Y.Z local; ==> @T should annotate X TypeBinding newLeafType = scope.environment().createAnnotatedType(oldLeafType, goodies); if (unionRef == null) { typeRef.resolvedType = existingType.isArrayType() ? scope.environment().createArrayType(newLeafType, existingType.dimensions(), existingType.getTypeAnnotations()) : newLeafType; } else { unionRef.resolvedType = newLeafType; unionRef.bits |= HasTypeAnnotations; } return typeRef.resolvedType; }
Example 2
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean canUseDiamond(String[] parameterTypes, char[] fullyQualifiedTypeName) { TypeBinding guessedType = null; char[][] cn = CharOperation.splitOn('.', fullyQualifiedTypeName); Scope scope = this.assistScope; if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_7) return false; // If no LHS or return type expected, then we can safely use diamond char[][] expectedTypekeys= this.completionContext.getExpectedTypesKeys(); if (expectedTypekeys == null || expectedTypekeys.length == 0) return true; // Next, find out whether any of the constructor parameters are the same as one of the // class type variables. If yes, diamond cannot be used. TypeReference ref; if (cn.length == 1) { ref = new SingleTypeReference(cn[0], 0); } else { ref = new QualifiedTypeReference(cn,new long[cn.length]); } switch (scope.kind) { case Scope.METHOD_SCOPE : case Scope.BLOCK_SCOPE : guessedType = ref.resolveType((BlockScope)scope); break; case Scope.CLASS_SCOPE : guessedType = ref.resolveType((ClassScope)scope); break; } if (guessedType != null && guessedType.isValidBinding()) { // the erasure must be used because guessedType can be a RawTypeBinding guessedType = guessedType.erasure(); TypeVariableBinding[] typeVars = guessedType.typeVariables(); for (int i = 0; i < parameterTypes.length; i++) { for (int j = 0; j < typeVars.length; j++) { if (CharOperation.equals(parameterTypes[i].toCharArray(), typeVars[j].sourceName)) return false; } } return true; } return false; }
Example 3
Source File: SelectionOnQualifiedSuperReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeBinding resolveType(BlockScope scope) { TypeBinding binding = super.resolveType(scope); if (binding == null || !binding.isValidBinding()) throw new SelectionNodeFound(); else throw new SelectionNodeFound(binding); }
Example 4
Source File: SelectionOnSuperReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeBinding resolveType(BlockScope scope) { TypeBinding binding = super.resolveType(scope); if (binding == null || !binding.isValidBinding()) throw new SelectionNodeFound(); else throw new SelectionNodeFound(binding); }
Example 5
Source File: CompletionOnReferenceExpressionName.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public TypeBinding resolveType(BlockScope scope) { final CompilerOptions compilerOptions = scope.compilerOptions(); TypeBinding lhsType; boolean typeArgumentsHaveErrors; this.constant = Constant.NotAConstant; lhsType = this.lhs.resolveType(scope); if (this.typeArguments != null) { int length = this.typeArguments.length; typeArgumentsHaveErrors = compilerOptions.sourceLevel < ClassFileConstants.JDK1_5; this.resolvedTypeArguments = new TypeBinding[length]; for (int i = 0; i < length; i++) { TypeReference typeReference = this.typeArguments[i]; if ((this.resolvedTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) { typeArgumentsHaveErrors = true; } if (typeArgumentsHaveErrors && typeReference instanceof Wildcard) { // resolveType on wildcard always return null above, resolveTypeArgument is the real workhorse. scope.problemReporter().illegalUsageOfWildcard(typeReference); } } if (typeArgumentsHaveErrors || lhsType == null) throw new CompletionNodeFound(); } if (lhsType != null && lhsType.isValidBinding()) throw new CompletionNodeFound(this, lhsType, scope); throw new CompletionNodeFound(); }
Example 6
Source File: CodeSnippetReturnStatement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void resolve(BlockScope scope) { if (this.expression != null) { if (this.expression.resolveType(scope) != null) { TypeBinding javaLangClass = scope.getJavaLangClass(); if (!javaLangClass.isValidBinding()) { scope.problemReporter().codeSnippetMissingClass("java.lang.Class", this.sourceStart, this.sourceEnd); //$NON-NLS-1$ return; } TypeBinding javaLangObject = scope.getJavaLangObject(); if (!javaLangObject.isValidBinding()) { scope.problemReporter().codeSnippetMissingClass("java.lang.Object", this.sourceStart, this.sourceEnd); //$NON-NLS-1$ return; } TypeBinding[] argumentTypes = new TypeBinding[] {javaLangObject, javaLangClass}; this.setResultMethod = scope.getImplicitMethod(SETRESULT_SELECTOR, argumentTypes, this); if (!this.setResultMethod.isValidBinding()) { scope.problemReporter().codeSnippetMissingMethod(ROOT_FULL_CLASS_NAME, new String(SETRESULT_SELECTOR), new String(SETRESULT_ARGUMENTS), this.sourceStart, this.sourceEnd); return; } // in constant case, the implicit conversion cannot be left uninitialized if (this.expression.constant != Constant.NotAConstant) { // fake 'no implicit conversion' (the return type is always void) this.expression.implicitConversion = this.expression.constant.typeID() << 4; } } } }
Example 7
Source File: JavadocQualifiedTypeReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private TypeBinding internalResolveType(Scope scope, boolean checkBounds) { // handle the error here this.constant = Constant.NotAConstant; if (this.resolvedType != null) // is a shared type reference which was already resolved return this.resolvedType.isValidBinding() ? this.resolvedType : this.resolvedType.closestMatch(); // already reported error TypeBinding type = this.resolvedType = getTypeBinding(scope); // End resolution when getTypeBinding(scope) returns null. This may happen in // certain circumstances, typically when an illegal access is done on a type // variable (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=204749) if (type == null) return null; if (!type.isValidBinding()) { Binding binding = scope.getTypeOrPackage(this.tokens); if (binding instanceof PackageBinding) { this.packageBinding = (PackageBinding) binding; // Valid package references are allowed in Javadoc (https://bugs.eclipse.org/bugs/show_bug.cgi?id=281609) } else { reportInvalidType(scope); } return null; } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=209936 // raw convert all enclosing types when dealing with Javadoc references if (type.isGenericType() || type.isParameterizedType()) { this.resolvedType = scope.environment().convertToRawType(type, true /*force the conversion of enclosing types*/); } return this.resolvedType; }
Example 8
Source File: ThrownExceptionFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void removeCaughtExceptions(TryStatement tryStatement, boolean recordUncheckedCaughtExceptions) { Argument[] catchArguments = tryStatement.catchArguments; int length = catchArguments == null ? 0 : catchArguments.length; for (int i = 0; i < length; i++) { if (catchArguments[i].type instanceof UnionTypeReference) { UnionTypeReference unionTypeReference = (UnionTypeReference) catchArguments[i].type; TypeBinding caughtException; for (int j = 0; j < unionTypeReference.typeReferences.length; j++) { caughtException = unionTypeReference.typeReferences[j].resolvedType; if ((caughtException instanceof ReferenceBinding) && caughtException.isValidBinding()) { // might be null when its the completion node if (recordUncheckedCaughtExceptions) { // is in outermost try-catch. Remove all caught exceptions, unchecked or checked removeCaughtException((ReferenceBinding)caughtException); this.caughtExceptions.add(caughtException); } else { // is in some inner try-catch. Discourage already caught checked exceptions // from being proposed in an outer catch. if (!caughtException.isUncheckedException(true)) { this.discouragedExceptions.add(caughtException); } } } } } else { TypeBinding exception = catchArguments[i].type.resolvedType; if ((exception instanceof ReferenceBinding) && exception.isValidBinding()) { if (recordUncheckedCaughtExceptions) { // is in outermost try-catch. Remove all caught exceptions, unchecked or checked removeCaughtException((ReferenceBinding)exception); this.caughtExceptions.add(exception); } else { // is in some inner try-catch. Discourage already caught checked exceptions // from being proposed in an outer catch if (!exception.isUncheckedException(true)) { this.discouragedExceptions.add(exception); } } } } } }
Example 9
Source File: LambdaExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Get a resolved copy of this lambda for use by type inference, as to avoid spilling any premature * type results into the original lambda. * * @param targetType the target functional type against which inference is attempted, must be a non-null valid functional type * @return a resolved copy of 'this' or null if significant errors where encountered */ public LambdaExpression getResolvedCopyForInferenceTargeting(TypeBinding targetType) { // note: this is essentially a simplified extract from isCompatibleWith(TypeBinding,Scope). if (this.shapeAnalysisComplete && this.binding != null) return this; targetType = targetType.uncapture(this.enclosingScope); // TODO: caching IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy); final CompilerOptions compilerOptions = this.enclosingScope.compilerOptions(); boolean analyzeNPE = compilerOptions.isAnnotationBasedNullAnalysisEnabled; final LambdaExpression copy = copy(); if (copy == null) { return null; } try { compilerOptions.isAnnotationBasedNullAnalysisEnabled = false; copy.setExpressionContext(this.expressionContext); copy.setExpectedType(targetType); this.hasIgnoredMandatoryErrors = false; TypeBinding type = copy.resolveType(this.enclosingScope); if (type == null || !type.isValidBinding()) return null; if (this.body instanceof Block) { if (copy.returnsVoid) { copy.shapeAnalysisComplete = true; } else { copy.valueCompatible = this.returnsValue; } } else { copy.voidCompatible = ((Expression) this.body).statementExpression(); TypeBinding resultType = ((Expression) this.body).resolvedType; if (resultType == null) // case of a yet-unresolved poly expression? copy.valueCompatible = true; else copy.valueCompatible = (resultType != TypeBinding.VOID); copy.shapeAnalysisComplete = true; } // Do not proceed with data/control flow analysis if resolve encountered errors. if (!this.hasIgnoredMandatoryErrors && !enclosingScopesHaveErrors()) { // value compatibility of block lambda's is the only open question. if (!copy.shapeAnalysisComplete) copy.valueCompatible = copy.doesNotCompleteNormally(); } else { if (!copy.returnsVoid) copy.valueCompatible = true; // optimistically, TODO: is this OK?? } copy.shapeAnalysisComplete = true; copy.resultExpressions = this.resultExpressions; this.resultExpressions = NO_EXPRESSIONS; } finally { compilerOptions.isAnnotationBasedNullAnalysisEnabled = analyzeNPE; this.hasIgnoredMandatoryErrors = false; this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy); } return copy; }
Example 10
Source File: UnionTypeReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope, boolean checkBounds, int location) { // return the lub (least upper bound of all type binding) int length = this.typeReferences.length; TypeBinding[] allExceptionTypes = new TypeBinding[length]; boolean hasError = false; for (int i = 0; i < length; i++) { TypeBinding exceptionType = this.typeReferences[i].resolveType(scope, checkBounds, location); if (exceptionType == null) { return null; } switch(exceptionType.kind()) { case Binding.PARAMETERIZED_TYPE : if (exceptionType.isBoundParameterizedType()) { hasError = true; scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this.typeReferences[i]); // fall thru to create the variable - avoids additional errors because the variable is missing } break; case Binding.TYPE_PARAMETER : scope.problemReporter().invalidTypeVariableAsException(exceptionType, this.typeReferences[i]); hasError = true; // fall thru to create the variable - avoids additional errors because the variable is missing break; } if (exceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null && exceptionType.isValidBinding()) { scope.problemReporter().cannotThrowType(this.typeReferences[i], exceptionType); hasError = true; } allExceptionTypes[i] = exceptionType; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=340486, ensure types are of union type. for (int j = 0; j < i; j++) { if (allExceptionTypes[j].isCompatibleWith(exceptionType)) { scope.problemReporter().wrongSequenceOfExceptionTypes( this.typeReferences[j], allExceptionTypes[j], exceptionType); hasError = true; } else if (exceptionType.isCompatibleWith(allExceptionTypes[j])) { scope.problemReporter().wrongSequenceOfExceptionTypes( this.typeReferences[i], exceptionType, allExceptionTypes[j]); hasError = true; } } } if (hasError) { return null; } // compute lub return (this.resolvedType = scope.lowerUpperBound(allExceptionTypes)); }
Example 11
Source File: MessageSend.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Find the method binding; * if this.innersNeedUpdate allow for two attempts where the first round may stop * after applicability checking (18.5.1) to include more information into the final * invocation type inference (18.5.2). */ protected void findMethodBinding(BlockScope scope, TypeBinding[] argumentTypes) { this.binding = this.receiver.isImplicitThis() ? scope.getImplicitMethod(this.selector, argumentTypes, this) : scope.getMethod(this.actualReceiverType, this.selector, argumentTypes, this); resolvePolyExpressionArguments(this, this.binding, argumentTypes, scope); /* There are embedded assumptions in the JLS8 type inference scheme that a successful solution of the type equations results in an applicable method. This appears to be a tenuous assumption, at least one not made by the JLS7 engine or the reference compiler and there are cases where this assumption would appear invalid: See https://bugs.eclipse.org/bugs/show_bug.cgi?id=426537, where we allow certain compatibility constrains around raw types to be violated. Here, we filter out such inapplicable methods with raw type usage that may have sneaked past overload resolution and type inference, playing the devils advocate, blaming the invocations with raw arguments that should not go blameless. At this time this is in the nature of a point fix and is not a general solution which needs to come later (that also includes AE, QAE and ECC) */ final CompilerOptions compilerOptions = scope.compilerOptions(); if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8 && this.binding instanceof ParameterizedGenericMethodBinding && this.binding.isValidBinding()) { if (!compilerOptions.postResolutionRawTypeCompatibilityCheck) return; ParameterizedGenericMethodBinding pgmb = (ParameterizedGenericMethodBinding) this.binding; InferenceContext18 ctx = getInferenceContext(pgmb); if (ctx == null || ctx.stepCompleted < InferenceContext18.BINDINGS_UPDATED) return; int length = pgmb.typeArguments == null ? 0 : pgmb.typeArguments.length; boolean sawRawType = false; for (int i = 0; i < length; i++) { /* Must check compatibility against capture free method. Formal parameters cannot have captures, but our machinery is not up to snuff to construct a PGMB without captures at the moment - for one thing ITCB does not support uncapture() yet, for another, INTERSECTION_CAST_TYPE does not appear fully hooked up into isCompatibleWith and isEquivalent to everywhere. At the moment, bail out if we see capture. */ if (pgmb.typeArguments[i].isCapture()) return; if (pgmb.typeArguments[i].isRawType()) sawRawType = true; } if (!sawRawType) return; length = this.arguments == null ? 0 : this.arguments.length; if (length == 0) return; TypeBinding [] finalArgumentTypes = new TypeBinding[length]; for (int i = 0; i < length; i++) { TypeBinding finalArgumentType = this.arguments[i].resolvedType; if (finalArgumentType == null || !finalArgumentType.isValidBinding()) // already sided with the devil. return; finalArgumentTypes[i] = finalArgumentType; } if (scope.parameterCompatibilityLevel(this.binding, finalArgumentTypes, false) == Scope.NOT_COMPATIBLE) this.binding = new ProblemMethodBinding(this.binding.original(), this.binding.selector, finalArgumentTypes, ProblemReasons.NotFound); } }