Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.TypeBinding#notEquals()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.TypeBinding#notEquals() .
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: CodeSnippetMessageSend.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { // if method from parameterized type got found, use the original method at codegen time MethodBinding codegenBinding = this.binding.original(); if (codegenBinding != this.binding) { // extra cast needed if method return type was type variable if (codegenBinding.returnType.isTypeVariable()) { TypeVariableBinding variableReturnType = (TypeVariableBinding) codegenBinding.returnType; if (TypeBinding.notEquals(variableReturnType.firstBound, this.binding.returnType)) { // no need for extra cast if same as first bound anyway this.valueCast = this.binding.returnType; } } } } }
Example 2
Source File: NullAnnotationMatching.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** Are both types identical wrt the unannotated type and any null type annotations? Only unstructured types and captures are considered. */ protected static boolean areSameTypes(TypeBinding requiredType, TypeBinding providedType, TypeBinding providedSubstitute) { if (requiredType == providedType) //$IDENTITY-COMPARISON$ // short cut for really-really-same types return true; if (requiredType.isParameterizedType() || requiredType.isArrayType()) return false; // not analysing details here if (TypeBinding.notEquals(requiredType, providedType)) { if (requiredType instanceof CaptureBinding) { // when providing exactly the lower bound of the required type we're definitely fine: TypeBinding lowerBound = ((CaptureBinding)requiredType).lowerBound; if (lowerBound != null && areSameTypes(lowerBound, providedType, providedSubstitute)) return true; } else if (requiredType.kind() == Binding.TYPE_PARAMETER && requiredType == providedSubstitute) { //$IDENTITY-COMPARISON$ return true; } else if (providedType instanceof CaptureBinding) { // when requiring exactly the upper bound of the provided type we're fine, too: TypeBinding upperBound = ((CaptureBinding)providedType).upperBound(); if (upperBound != null && areSameTypes(requiredType, upperBound, providedSubstitute)) return true; } return false; } return (requiredType.tagBits & TagBits.AnnotationNullMASK) == (providedType.tagBits & TagBits.AnnotationNullMASK); }
Example 3
Source File: ASTNode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static int checkInvocationArgument(BlockScope scope, Expression argument, TypeBinding parameterType, TypeBinding argumentType, TypeBinding originalParameterType) { argument.computeConversion(scope, parameterType, argumentType); if (argumentType != TypeBinding.NULL && parameterType.kind() == Binding.WILDCARD_TYPE) { // intersection types are tolerated WildcardBinding wildcard = (WildcardBinding) parameterType; if (wildcard.boundKind != Wildcard.SUPER) { return INVOCATION_ARGUMENT_WILDCARD; } } TypeBinding checkedParameterType = parameterType; // originalParameterType == null ? parameterType : originalParameterType; if (TypeBinding.notEquals(argumentType, checkedParameterType) && argumentType.needsUncheckedConversion(checkedParameterType)) { scope.problemReporter().unsafeTypeConversion(argument, argumentType, checkedParameterType); return INVOCATION_ARGUMENT_UNCHECKED; } return INVOCATION_ARGUMENT_OK; }
Example 4
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Determines whether apparent unnecessary cast wasn't actually used to * perform return type inference of generic method invocation or boxing. */ private boolean isIndirectlyUsed() { if (this.expression instanceof MessageSend) { MethodBinding method = ((MessageSend)this.expression).binding; if (method instanceof ParameterizedGenericMethodBinding && ((ParameterizedGenericMethodBinding)method).inferredReturnType) { if (this.expectedType == null) return true; if (TypeBinding.notEquals(this.resolvedType, this.expectedType)) return true; } } if (this.expectedType != null && this.resolvedType.isBaseType() && !this.resolvedType.isCompatibleWith(this.expectedType)) { // boxing: Short s = (short) _byte return true; } return false; }
Example 5
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Cast expression code generation * * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream * @param valueRequired boolean */ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; boolean annotatedCast = (this.type.bits & ASTNode.HasTypeAnnotations) != 0; boolean needRuntimeCheckcast = (this.bits & ASTNode.GenerateCheckcast) != 0; if (this.constant != Constant.NotAConstant) { if (valueRequired || needRuntimeCheckcast || annotatedCast) { // Added for: 1F1W9IG: IVJCOM:WINNT - Compiler omits casting check codeStream.generateConstant(this.constant, this.implicitConversion); if (needRuntimeCheckcast || annotatedCast) { codeStream.checkcast(this.type, this.resolvedType); } if (!valueRequired) { // the resolveType cannot be double or long codeStream.pop(); } } codeStream.recordPositionsFrom(pc, this.sourceStart); return; } this.expression.generateCode(currentScope, codeStream, annotatedCast || valueRequired || needRuntimeCheckcast); if (annotatedCast || (needRuntimeCheckcast && TypeBinding.notEquals(this.expression.postConversionType(currentScope), this.resolvedType.erasure()))) { // no need to issue a checkcast if already done as genericCast codeStream.checkcast(this.type, this.resolvedType); } if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else if (needRuntimeCheckcast) { boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; switch (isUnboxing ? postConversionType(currentScope).id : this.resolvedType.id) { case T_long : case T_double : codeStream.pop2(); break; default : codeStream.pop(); break; } } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 6
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static AnnotationBinding [] getPackedAnnotationBindings(AnnotationBinding [] annotations) { int length = annotations == null ? 0 : annotations.length; if (length == 0) return annotations; AnnotationBinding[] repackagedBindings = annotations; // only replicate if repackaging. for (int i = 0; i < length; i++) { AnnotationBinding annotation = repackagedBindings[i]; if (annotation == null) continue; ReferenceBinding annotationType = annotation.getAnnotationType(); if (!annotationType.isRepeatableAnnotationType()) continue; ReferenceBinding containerType = annotationType.containerAnnotationType(); if (containerType == null) continue; // FUBAR. MethodBinding [] values = containerType.getMethods(TypeConstants.VALUE); if (values == null || values.length != 1) continue; // FUBAR. MethodBinding value = values[0]; if (value.returnType == null || value.returnType.dimensions() != 1 || TypeBinding.notEquals(value.returnType.leafComponentType(), annotationType)) continue; // FUBAR // We have a kosher repeatable annotation with a kosher containing type. See if actually repeats. List<AnnotationBinding> containees = null; for (int j = i + 1; j < length; j++) { AnnotationBinding otherAnnotation = repackagedBindings[j]; if (otherAnnotation == null) continue; if (otherAnnotation.getAnnotationType() == annotationType) { //$IDENTITY-COMPARISON$ if (repackagedBindings == annotations) System.arraycopy(repackagedBindings, 0, repackagedBindings = new AnnotationBinding[length], 0, length); repackagedBindings[j] = null; // so it is not double packed. if (containees == null) { containees = new ArrayList<AnnotationBinding>(); containees.add(annotation); } containees.add(otherAnnotation); } } if (containees != null) { ElementValuePair [] elementValuePairs = new ElementValuePair [] { new ElementValuePair(TypeConstants.VALUE, containees.toArray(), value) }; repackagedBindings[i] = new AnnotationBinding(containerType, elementValuePairs); } } if (repackagedBindings == annotations) return annotations; int finalTally = 0; for (int i = 0; i < length; i++) { if (repackagedBindings[i] != null) finalTally++; } annotations = new AnnotationBinding [finalTally]; for (int i = 0, j = 0; i < length; i++) { if (repackagedBindings[i] != null) annotations[j++] = repackagedBindings[i]; } return annotations; }
Example 7
Source File: TypesImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public TypeMirror asMemberOf(DeclaredType containing, Element element) { // throw new UnsupportedOperationException("NYI: TypesImpl.asMemberOf(" + containing + ", " + element + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ElementImpl elementImpl = (ElementImpl) element; DeclaredTypeImpl declaredTypeImpl = (DeclaredTypeImpl) containing; ReferenceBinding referenceBinding = (ReferenceBinding) declaredTypeImpl._binding; switch(element.getKind()) { case CONSTRUCTOR : case METHOD : MethodBinding methodBinding = (MethodBinding) elementImpl._binding; if (TypeBinding.notEquals(methodBinding.declaringClass, referenceBinding)) { throw new IllegalArgumentException("element is not valid for the containing declared type"); //$NON-NLS-1$ } for (MethodBinding method : referenceBinding.methods()) { if (CharOperation.equals(method.selector, methodBinding.selector) && method.areParameterErasuresEqual(methodBinding)) { return this._env.getFactory().newTypeMirror(method); } } break; case FIELD : case ENUM_CONSTANT: FieldBinding fieldBinding = (FieldBinding) elementImpl._binding; if (TypeBinding.notEquals(fieldBinding.declaringClass, referenceBinding)) { throw new IllegalArgumentException("element is not valid for the containing declared type"); //$NON-NLS-1$ } for (FieldBinding field : referenceBinding.fields()) { if (CharOperation.equals(field.name, fieldBinding.name)) { return this._env.getFactory().newTypeMirror(field); } } break; case ENUM : case ANNOTATION_TYPE : case INTERFACE : case CLASS : ReferenceBinding referenceBinding2 = (ReferenceBinding) elementImpl._binding; if (TypeBinding.notEquals(referenceBinding2.enclosingType(), referenceBinding)) { throw new IllegalArgumentException("element is not valid for the containing declared type"); //$NON-NLS-1$ } for (ReferenceBinding referenceBinding3 : referenceBinding.memberTypes()) { if (CharOperation.equals(referenceBinding3.compoundName, referenceBinding3.compoundName)) { return this._env.getFactory().newTypeMirror(referenceBinding3); } } break; default: break; } throw new IllegalArgumentException("element is not valid for the containing declared type: element kind " + element.getKind()); //$NON-NLS-1$ }
Example 8
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean canBeSeenByForCodeSnippet(FieldBinding fieldBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { if (fieldBinding.isPublic()) return true; ReferenceBinding invocationType = (ReferenceBinding) receiverType; if (TypeBinding.equalsEquals(invocationType, fieldBinding.declaringClass)) return true; if (fieldBinding.isProtected()) { // answer true if the invocationType is the declaringClass or they are in the same package // OR the invocationType is a subclass of the declaringClass // AND the receiverType is the invocationType or its subclass // OR the field is a static field accessed directly through a type if (TypeBinding.equalsEquals(invocationType, fieldBinding.declaringClass)) return true; if (invocationType.fPackage == fieldBinding.declaringClass.fPackage) return true; if (fieldBinding.declaringClass.isSuperclassOf(invocationType)) { if (invocationSite.isSuperAccess()) return true; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; if (invocationType.isSuperclassOf((ReferenceBinding) receiverType)) return true; if (fieldBinding.isStatic()) return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } return false; } if (fieldBinding.isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType if (TypeBinding.notEquals(receiverType, fieldBinding.declaringClass)) return false; if (TypeBinding.notEquals(invocationType, fieldBinding.declaringClass)) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = fieldBinding.declaringClass; temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } if (TypeBinding.notEquals(outerInvocationType, outerDeclaringClass)) return false; } return true; } // isDefault() if (invocationType.fPackage != fieldBinding.declaringClass.fPackage) return false; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; ReferenceBinding type = (ReferenceBinding) receiverType; PackageBinding declaringPackage = fieldBinding.declaringClass.fPackage; TypeBinding originalDeclaringClass = fieldBinding.declaringClass .original(); do { if (type.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 if (TypeBinding.equalsEquals(originalDeclaringClass, type.erasure().original())) return true; } else { if (TypeBinding.equalsEquals(originalDeclaringClass, type.original())) return true; } if (declaringPackage != type.fPackage) return false; } while ((type = type.superclass()) != null); return false; }
Example 9
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean canBeSeenByForCodeSnippet(MethodBinding methodBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { if (methodBinding.isPublic()) return true; ReferenceBinding invocationType = (ReferenceBinding) receiverType; if (TypeBinding.equalsEquals(invocationType, methodBinding.declaringClass)) return true; if (methodBinding.isProtected()) { // answer true if the invocationType is the declaringClass or they are in the same package // OR the invocationType is a subclass of the declaringClass // AND the receiverType is the invocationType or its subclass // OR the method is a static method accessed directly through a type if (TypeBinding.equalsEquals(invocationType, methodBinding.declaringClass)) return true; if (invocationType.fPackage == methodBinding.declaringClass.fPackage) return true; if (methodBinding.declaringClass.isSuperclassOf(invocationType)) { if (invocationSite.isSuperAccess()) return true; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; if (invocationType.isSuperclassOf((ReferenceBinding) receiverType)) return true; if (methodBinding.isStatic()) return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } return false; } if (methodBinding.isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType if (TypeBinding.notEquals(receiverType, methodBinding.declaringClass)) return false; if (TypeBinding.notEquals(invocationType, methodBinding.declaringClass)) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = methodBinding.declaringClass; temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } if (TypeBinding.notEquals(outerInvocationType, outerDeclaringClass)) return false; } return true; } // isDefault() if (invocationType.fPackage != methodBinding.declaringClass.fPackage) return false; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; ReferenceBinding type = (ReferenceBinding) receiverType; PackageBinding declaringPackage = methodBinding.declaringClass.fPackage; TypeBinding originalDeclaringClass = methodBinding.declaringClass .original(); do { if (type.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 if (TypeBinding.equalsEquals(originalDeclaringClass, type.erasure().original())) return true; } else { if (TypeBinding.equalsEquals(originalDeclaringClass, type.original())) return true; } if (declaringPackage != type.fPackage) return false; } while ((type = type.superclass()) != null); return false; }
Example 10
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { // compute a new constant if the cast is effective this.constant = Constant.NotAConstant; this.implicitConversion = TypeIds.T_undefined; boolean exprContainCast = false; TypeBinding castType = this.resolvedType = this.type.resolveType(scope); if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) { this.expression.setExpressionContext(CASTING_CONTEXT); if (this.expression instanceof FunctionalExpression) { this.expression.setExpectedType(this.resolvedType); this.bits |= ASTNode.DisableUnnecessaryCastCheck; } } if (this.expression instanceof CastExpression) { this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck; exprContainCast = true; } TypeBinding expressionType = this.expression.resolveType(scope); if (this.expression instanceof MessageSend) { MessageSend messageSend = (MessageSend) this.expression; MethodBinding methodBinding = messageSend.binding; if (methodBinding != null && methodBinding.isPolymorphic()) { messageSend.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) methodBinding, castType); if (TypeBinding.notEquals(expressionType, castType)) { expressionType = castType; this.bits |= ASTNode.DisableUnnecessaryCastCheck; } } } if (castType != null) { if (expressionType != null) { boolean nullAnnotationMismatch = scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled && NullAnnotationMatching.analyse(castType, expressionType, -1).isAnyMismatch(); boolean isLegal = checkCastTypesCompatibility(scope, castType, expressionType, this.expression); if (isLegal) { this.expression.computeConversion(scope, castType, expressionType); if ((this.bits & ASTNode.UnsafeCast) != 0) { // unsafe cast if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !(expressionType.isRawType() && this.expression.forcedToBeRaw(scope.referenceContext()))) { scope.problemReporter().unsafeCast(this, scope); } } else if (nullAnnotationMismatch) { // report null annotation issue at medium priority scope.problemReporter().unsafeNullnessCast(this, scope); } else { if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore){ scope.problemReporter().rawTypeReference(this.type, castType); } if ((this.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == ASTNode.UnnecessaryCast) { // unnecessary cast if (!isIndirectlyUsed()) // used for generic type inference or boxing ? scope.problemReporter().unnecessaryCast(this); } } } else { // illegal cast if ((castType.tagBits & TagBits.HasMissingType) == 0) { // no complaint if secondary error scope.problemReporter().typeCastError(this, castType, expressionType); } this.bits |= ASTNode.DisableUnnecessaryCastCheck; // disable further secondary diagnosis } } this.resolvedType = castType.capture(scope, this.sourceEnd); if (exprContainCast) { checkNeedForCastCast(scope, this); } } return this.resolvedType; }
Example 11
Source File: ReferenceExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { this.actualMethodBinding = this.binding; // grab before synthetics come into play. // Handle some special cases up front and transform them into implicit lambdas. if (shouldGenerateImplicitLambda(currentScope)) { generateImplicitLambda(currentScope, codeStream, valueRequired); return; } SourceTypeBinding sourceType = currentScope.enclosingSourceType(); if (this.receiverType.isArrayType()) { if (isConstructorReference()) { this.actualMethodBinding = this.binding = sourceType.addSyntheticArrayMethod((ArrayBinding) this.receiverType, SyntheticMethodBinding.ArrayConstructor); } else if (CharOperation.equals(this.selector, TypeConstants.CLONE)) { this.actualMethodBinding = this.binding = sourceType.addSyntheticArrayMethod((ArrayBinding) this.receiverType, SyntheticMethodBinding.ArrayClone); } } else if (this.syntheticAccessor != null) { if (this.lhs.isSuper() || isMethodReference()) this.binding = this.syntheticAccessor; } else { // cf. MessageSend.generateCode()'s call to CodeStream.getConstantPoolDeclaringClass. We have extracted the relevant portions sans side effect here. if (this.binding != null && isMethodReference()) { if (TypeBinding.notEquals(this.binding.declaringClass, this.lhs.resolvedType.erasure())) { if (!this.binding.declaringClass.canBeSeenBy(currentScope)) { this.binding = new MethodBinding(this.binding, (ReferenceBinding) this.lhs.resolvedType.erasure()); } } } } int pc = codeStream.position; StringBuffer buffer = new StringBuffer(); int argumentsSize = 0; buffer.append('('); if (this.haveReceiver) { this.lhs.generateCode(currentScope, codeStream, true); if (this.lhs.isSuper() && !this.actualMethodBinding.isPrivate()) { if (this.lhs instanceof QualifiedSuperReference) { QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) this.lhs; TypeReference qualification = qualifiedSuperReference.qualification; if (qualification.resolvedType.isInterface()) { buffer.append(sourceType.signature()); } else { buffer.append(((QualifiedSuperReference) this.lhs).currentCompatibleType.signature()); } } else { buffer.append(sourceType.signature()); } } else { buffer.append(this.receiverType.signature()); } argumentsSize = 1; } else { if (this.isConstructorReference()) { ReferenceBinding[] enclosingInstances = Binding.UNINITIALIZED_REFERENCE_TYPES; if (this.receiverType.isNestedType()) { ReferenceBinding nestedType = (ReferenceBinding) this.receiverType; if ((enclosingInstances = nestedType.syntheticEnclosingInstanceTypes()) != null) { int length = enclosingInstances.length; argumentsSize = length; for (int i = 0 ; i < length; i++) { ReferenceBinding syntheticArgumentType = enclosingInstances[i]; buffer.append(syntheticArgumentType.signature()); Object[] emulationPath = currentScope.getEmulationPath( syntheticArgumentType, false /* allow compatible match */, true /* disallow instance reference in explicit constructor call */); codeStream.generateOuterAccess(emulationPath, this, syntheticArgumentType, currentScope); } } else { enclosingInstances = Binding.NO_REFERENCE_TYPES; } // Reject types that capture outer local arguments, these cannot be manufactured by the metafactory. if (nestedType.syntheticOuterLocalVariables() != null) { currentScope.problemReporter().noSuchEnclosingInstance(nestedType.enclosingType(), this, false); return; } } if (this.syntheticAccessor != null) { this.binding = sourceType.addSyntheticFactoryMethod(this.binding, this.syntheticAccessor, enclosingInstances); } } } buffer.append(')'); buffer.append('L'); buffer.append(this.resolvedType.constantPoolName()); buffer.append(';'); int invokeDynamicNumber = codeStream.classFile.recordBootstrapMethod(this); codeStream.invokeDynamic(invokeDynamicNumber, argumentsSize, 1, this.descriptor.selector, buffer.toString().toCharArray(), this.isConstructorReference(), (this.lhs instanceof TypeReference? (TypeReference) this.lhs : null), this.typeArguments); if (!valueRequired) codeStream.pop(); codeStream.recordPositionsFrom(pc, this.sourceStart); }