org.eclipse.jdt.internal.compiler.lookup.Scope Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.Scope. 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: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 6 votes vote down vote up
private static ClassScope getClassScope(CompletionProposalCollector completionProposalCollector) {
	ClassScope scope = null;
	try {
		InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
		InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
		if (extendedContext != null) {
			Scope assistScope = ((Scope) Reflection.assistScopeField.get(extendedContext));
			if (assistScope != null) {
				scope = assistScope.classScope();
			}
		}
	} catch (IllegalAccessException ignore) {
		// ignore
	}
	return scope;
}
 
Example #2
Source File: StackMapFrameCodeStream.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
	int index = this.visibleLocalsCount;
	loop : for (int i = 0; i < index; i++) {
		LocalVariableBinding localBinding = this.visibleLocals[i];
		if (localBinding != null && localBinding.initializationCount > 0) {
			boolean isDefinitelyAssigned = isDefinitelyAssigned(scope, initStateIndex, localBinding);
			if (!isDefinitelyAssigned) {
				if (this.stateIndexes != null) {
					for (int j = 0, max = this.stateIndexesCounter; j < max; j++) {
						if (isDefinitelyAssigned(scope, this.stateIndexes[j], localBinding)) {
							continue loop;
						}
					}
				}
				localBinding.recordInitializationEndPC(this.position);
			}
		}
	}
}
 
Example #3
Source File: CompletionOnJavadocFieldReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected TypeBinding internalResolveType(Scope scope) {

		if (this.token != null) {
			return super.internalResolveType(scope);
		}

		// Resolve only receiver
		if (this.receiver == null) {
			this.actualReceiverType = scope.enclosingSourceType();
		} else if (scope.kind == Scope.CLASS_SCOPE) {
			this.actualReceiverType = this.receiver.resolveType((ClassScope) scope);
		} else {
			this.actualReceiverType = this.receiver.resolveType((BlockScope)scope);
		}
		return null;
	}
 
Example #4
Source File: InternalExtendedCompletionContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public InternalExtendedCompletionContext(
		InternalCompletionContext completionContext,
		ITypeRoot typeRoot,
		CompilationUnitDeclaration compilationUnitDeclaration,
		LookupEnvironment lookupEnvironment,
		Scope assistScope,
		ASTNode assistNode,
		ASTNode assistNodeParent,
		WorkingCopyOwner owner,
		CompletionParser parser) {
	this.completionContext = completionContext;
	this.typeRoot = typeRoot;
	this.compilationUnitDeclaration = compilationUnitDeclaration;
	this.lookupEnvironment = lookupEnvironment;
	this.assistScope = assistScope;
	this.assistNode = assistNode;
	this.assistNodeParent = assistNodeParent;
	this.owner = owner;
	this.parser = parser;
}
 
Example #5
Source File: ReferenceExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isCompatibleWith(TypeBinding left, Scope scope) {
	if (this.binding != null && this.binding.isValidBinding() // binding indicates if full resolution has already happened
			&& this.resolvedType != null && this.resolvedType.isValidBinding()) {
		return this.resolvedType.isCompatibleWith(left, scope);
	}
	// 15.28.2
	left = left.uncapture(this.enclosingScope);
	final MethodBinding sam = left.getSingleAbstractMethod(this.enclosingScope, true);
	if (sam == null || !sam.isValidBinding())
		return false;
	boolean isCompatible;
	setExpectedType(left);
	IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
	try {
		this.binding = null;
		this.trialResolution = true;
		resolveType(this.enclosingScope);
	} finally {
		this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
		isCompatible = this.binding != null && this.binding.isValidBinding();
		this.binding = null;
		setExpectedType(null);
		this.trialResolution = false;
	}
	return isCompatible;
}
 
Example #6
Source File: ReferenceExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
MethodBinding internalResolveTentatively(TypeBinding targetType, Scope scope) {
	// FIXME: could enclosingScope still be null here??
	IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
	ExpressionContext previousContext = this.expressionContext;
	MethodBinding previousBinding = this.binding;
	MethodBinding previousDescriptor = this.descriptor;
	TypeBinding previousResolvedType = this.resolvedType;
	try {
		setExpressionContext(INVOCATION_CONTEXT);
		setExpectedType(targetType);
		this.binding = null;
		this.trialResolution = true;
		resolveType(this.enclosingScope);
		return this.binding;
	} finally {
		this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
		// remove *any relevant* traces of this 'inofficial' resolving:
		this.binding = previousBinding;
		this.descriptor = previousDescriptor;
		this.resolvedType = previousResolvedType;
		setExpressionContext(previousContext);
		this.expectedType = null; // don't call setExpectedType(null), would NPE
		this.trialResolution = false;
	}
}
 
Example #7
Source File: FlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/** During deferred checking re-visit a previously recording unboxing situation. */
protected void checkUnboxing(Scope scope, Expression expression, FlowInfo flowInfo) {
	int status = expression.nullStatus(flowInfo, this);
	if ((status & FlowInfo.NULL) != 0) {
		scope.problemReporter().nullUnboxing(expression, expression.resolvedType);
		return;
	} else if ((status & FlowInfo.POTENTIALLY_NULL) != 0) {
		scope.problemReporter().potentialNullUnboxing(expression, expression.resolvedType);
		return;
	} else if ((status & FlowInfo.NON_NULL) != 0) {
		return;
	}
	// not handled, perhaps our parent will eventually have something to say?
	if (this.parent != null) {
		this.parent.recordUnboxing(scope, expression, FlowInfo.UNKNOWN, flowInfo);
	}
}
 
Example #8
Source File: TypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/** Check all typeArguments against null constraints on their corresponding type variables. */
protected void checkNullConstraints(Scope scope, TypeReference[] typeArguments) {
	CompilerOptions compilerOptions = scope.compilerOptions();
	if (compilerOptions.isAnnotationBasedNullAnalysisEnabled
			&& compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8
			&& typeArguments != null)
	{
		TypeVariableBinding[] typeVariables = this.resolvedType.original().typeVariables();
		for (int i = 0; i < typeArguments.length; i++) {
			TypeReference arg = typeArguments[i];
			if (arg.resolvedType != null && arg.resolvedType.hasNullTypeAnnotations())
				arg.checkNullConstraints(scope, typeVariables, i);
		}
	}
}
 
Example #9
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean enclosingScopesHaveErrors() {
	Scope skope = this.enclosingScope;
	while (skope != null) {
		ReferenceContext context = skope.referenceContext();
		if (context != null && context.hasErrors())
			return true;
		skope = skope.parent;
	}
	return false;
}
 
Example #10
Source File: FunctionalExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean kosherDescriptor(Scope scope, MethodBinding sam, boolean shouldChatter) {

	VisibilityInspector inspector = new VisibilityInspector(this, scope, shouldChatter);
	
	boolean status = true;
	
	if (!inspector.visible(sam.returnType))
		status = false;
	if (!inspector.visible(sam.parameters))
		status = false;
	if (!inspector.visible(sam.thrownExceptions))
		status = false;
	
	return status;
}
 
Example #11
Source File: LoopingFlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean recordFinalAssignment(
	VariableBinding binding,
	Reference finalAssignment) {

	// do not consider variables which are defined inside this loop
	if (binding instanceof LocalVariableBinding) {
		Scope scope = ((LocalVariableBinding) binding).declaringScope;
		while ((scope = scope.parent) != null) {
			if (scope == this.associatedScope)
				return false;
		}
	}
	if (this.assignCount == 0) {
		this.finalAssignments = new Reference[5];
		this.finalVariables = new VariableBinding[5];
	} else {
		if (this.assignCount == this.finalAssignments.length)
			System.arraycopy(
				this.finalAssignments,
				0,
				(this.finalAssignments = new Reference[this.assignCount * 2]),
				0,
				this.assignCount);
		System.arraycopy(
			this.finalVariables,
			0,
			(this.finalVariables = new VariableBinding[this.assignCount * 2]),
			0,
			this.assignCount);
	}
	this.finalAssignments[this.assignCount] = finalAssignment;
	this.finalVariables[this.assignCount++] = binding;
	return true;
}
 
Example #12
Source File: LoopingFlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public LoopingFlowContext(
	FlowContext parent,
	FlowInfo upstreamNullFlowInfo,
	ASTNode associatedNode,
	BranchLabel breakLabel,
	BranchLabel continueLabel,
	Scope associatedScope,
	boolean isPreTest) {
	super(parent, associatedNode, breakLabel, isPreTest);
	this.tagBits |= FlowContext.PREEMPT_NULL_DIAGNOSTIC;
		// children will defer to this, which may defer to its own parent
	this.continueLabel = continueLabel;
	this.associatedScope = associatedScope;
	this.upstreamNullFlowInfo = upstreamNullFlowInfo.unconditionalCopy();
}
 
Example #13
Source File: FieldReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.jdt.internal.compiler.ast.Expression#computeConversion(org.eclipse.jdt.internal.compiler.lookup.Scope, org.eclipse.jdt.internal.compiler.lookup.TypeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding)
 */
public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
	if (runtimeTimeType == null || compileTimeType == null)
		return;
	// set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
	if (this.binding != null && this.binding.isValidBinding()) {
		FieldBinding originalBinding = this.binding.original();
		TypeBinding originalType = originalBinding.type;
	    // extra cast needed if field type is type variable
		if (originalType.leafComponentType().isTypeVariable()) {
	    	TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
	    		? compileTimeType  // unboxing: checkcast before conversion
	    		: runtimeTimeType;
	        this.genericCast = originalBinding.type.genericCast(targetType);
	        if (this.genericCast instanceof ReferenceBinding) {
				ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
				if (!referenceCast.canBeSeenBy(scope)) {
		        	scope.problemReporter().invalidType(this,
		        			new ProblemReferenceBinding(
								CharOperation.splitOn('.', referenceCast.shortReadableName()),
								referenceCast,
								ProblemReasons.NotVisible));
				}
	        }
		}
	}
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
}
 
Example #14
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isCastCompatible(ITypeBinding type) {
	try {
		Scope scope = this.resolver.scope();
		if (scope == null) return false;
		if (!(type instanceof TypeBinding)) return false;
		org.eclipse.jdt.internal.compiler.lookup.TypeBinding expressionType = ((TypeBinding) type).binding;
		// simulate capture in case checked binding did not properly get extracted from a reference
		expressionType = expressionType.capture(scope, 0);
		return TypeBinding.EXPRESSION.checkCastTypesCompatibility(scope, this.binding, expressionType, null);
	} catch (AbortCompilation e) {
		// don't surface internal exception to clients
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
		return false;
	}
}
 
Example #15
Source File: Extractor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static ClassScope findClassScope(Scope scope) {
    while (scope != null) {
        if (scope instanceof ClassScope) {
            return (ClassScope) scope;
        }
        scope = scope.parent;
    }

    return null;
}
 
Example #16
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IMethodBinding getFunctionalInterfaceMethod() {
	Scope scope = this.resolver.scope();
	if (this.binding == null || scope == null)
		return null;
	MethodBinding sam = this.binding.getSingleAbstractMethod(scope, true);
	if (sam == null || !sam.isValidBinding())
		return null;
	return this.resolver.getMethodBinding(sam);
}
 
Example #17
Source File: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MethodBinding getConstructor(ReferenceBinding receiverType, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
	MethodBinding methodBinding = receiverType.getExactConstructor(argumentTypes);
	if (methodBinding != null) {
		if (canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this)) {
			return methodBinding;
		}
	}
	MethodBinding[] methods = receiverType.getMethods(TypeConstants.INIT);
	if (methods == Binding.NO_METHODS) {
		return new ProblemMethodBinding(TypeConstants.INIT, argumentTypes, ProblemReasons.NotFound);
	}
	MethodBinding[] compatible = new MethodBinding[methods.length];
	int compatibleIndex = 0;
	for (int i = 0, length = methods.length; i < length; i++) {
	    MethodBinding compatibleMethod = computeCompatibleMethod(methods[i], argumentTypes, invocationSite, Scope.APPLICABILITY);
		if (compatibleMethod != null)
			compatible[compatibleIndex++] = compatibleMethod;
	}
	if (compatibleIndex == 0)
		return new ProblemMethodBinding(TypeConstants.INIT, argumentTypes, ProblemReasons.NotFound); // need a more descriptive error... cannot convert from X to Y

	MethodBinding[] visible = new MethodBinding[compatibleIndex];
	int visibleIndex = 0;
	for (int i = 0; i < compatibleIndex; i++) {
		MethodBinding method = compatible[i];
		if (canBeSeenByForCodeSnippet(method, receiverType, invocationSite, this)) {
			visible[visibleIndex++] = method;
		}
	}
	if (visibleIndex == 1) {
		// 1.8: Give inference a chance to perform outstanding tasks (18.5.2):
		return inferInvocationType(invocationSite, visible[0], argumentTypes);
	}
	if (visibleIndex == 0) {
		return new ProblemMethodBinding(compatible[0], TypeConstants.INIT, compatible[0].parameters, ProblemReasons.NotVisible);
	}
	return mostSpecificClassMethodBinding(visible, visibleIndex, invocationSite);
}
 
Example #18
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void findBefore(
		char[] startWith,
		Scope scope,
		ClassScope classScope,
		int from,
		int recordTo,
		int parseTo,
		char[][] discouragedNames,
		UnresolvedReferenceNameRequestor nameRequestor) {
	MethodDeclaration fakeMethod =
		this.findBefore(startWith, scope, from, recordTo, parseTo, MAX_LINE_COUNT / 2, discouragedNames, nameRequestor);
	if (fakeMethod != null) fakeMethod.traverse(this, classScope);
}
 
Example #19
Source File: TypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/** Check whether this type reference conforms to all null constraints defined for any of the given type variables. */
protected void checkNullConstraints(Scope scope, TypeBinding[] variables, int rank) {
	if (variables != null && variables.length > rank) {
		TypeBinding variable = variables[rank];
		if (variable.hasNullTypeAnnotations()) {
			if (NullAnnotationMatching.analyse(variable, this.resolvedType, null, -1, CheckMode.BOUND_CHECK).isAnyMismatch())
				scope.problemReporter().nullityMismatchTypeArgument(variable, this.resolvedType, this);
    	}
	}
}
 
Example #20
Source File: QualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.jdt.internal.compiler.ast.Expression#postConversionType(Scope)
 */
public TypeBinding postConversionType(Scope scope) {
	TypeBinding convertedType = this.resolvedType;
	TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length);
	if (requiredGenericCast != null)
		convertedType = requiredGenericCast;
	int runtimeType = (this.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4;
	switch (runtimeType) {
		case T_boolean :
			convertedType = TypeBinding.BOOLEAN;
			break;
		case T_byte :
			convertedType = TypeBinding.BYTE;
			break;
		case T_short :
			convertedType = TypeBinding.SHORT;
			break;
		case T_char :
			convertedType = TypeBinding.CHAR;
			break;
		case T_int :
			convertedType = TypeBinding.INT;
			break;
		case T_float :
			convertedType = TypeBinding.FLOAT;
			break;
		case T_long :
			convertedType = TypeBinding.LONG;
			break;
		case T_double :
			convertedType = TypeBinding.DOUBLE;
			break;
		default :
	}
	if ((this.implicitConversion & TypeIds.BOXING) != 0) {
		convertedType = scope.environment().computeBoxingType(convertedType);
	}
	return convertedType;
}
 
Example #21
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isAssignmentCompatible(ITypeBinding type) {
	try {
		if (this == type) return true; //$IDENTITY-COMPARISON$
		if (!(type instanceof TypeBinding)) return false;
		TypeBinding other = (TypeBinding) type;
		Scope scope = this.resolver.scope();
		if (scope == null) return false;
		return this.binding.isCompatibleWith(other.binding) || scope.isBoxingCompatibleWith(this.binding, other.binding);
	} catch (AbortCompilation e) {
		// don't surface internal exception to clients
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
		return false;
	}
}
 
Example #22
Source File: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope,
		boolean isExplicitUse) {
	// ignore references insing Javadoc comments
	if ((this.bits & ASTNode.InsideJavadoc) == 0 && method.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(method)) {
		// ignore cases where method is used from inside itself (e.g. direct recursions)
		method.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
	}

	// TODO (maxime) consider separating concerns between deprecation and access restriction.
	// 				 Caveat: this was not the case when access restriction funtion was added.
	if (isExplicitUse && (method.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) {
		// note: explicit constructors calls warnings are kept despite the 'new C1()' case (two
		//       warnings, one on type, the other on constructor), because of the 'super()' case.
		AccessRestriction restriction =
			scope.environment().getAccessRestriction(method.declaringClass.erasure());
		if (restriction != null) {
			scope.problemReporter().forbiddenReference(method, this,
					restriction.classpathEntryType, restriction.classpathEntryName,
					restriction.getProblemId());
		}
	}

	if (!method.isViewedAsDeprecated()) return false;

	// inside same unit - no report
	if (scope.isDefinedInSameUnit(method.declaringClass)) return false;

	// non explicit use and non explicitly deprecated - no report
	if (!isExplicitUse &&
			(method.modifiers & ClassFileConstants.AccDeprecated) == 0) {
		return false;
	}

	// if context is deprecated, may avoid reporting
	if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
	return true;
}
 
Example #23
Source File: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {

		if (type.isArrayType()) {
			type = ((ArrayBinding) type).leafComponentType;
		}
		if (type.isBaseType())
			return false;

		ReferenceBinding refType = (ReferenceBinding) type;
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=397888
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
		if ((this.bits & ASTNode.InsideJavadoc) == 0  && refType instanceof TypeVariableBinding) {
			refType.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
		}
		// ignore references insing Javadoc comments
		if ((this.bits & ASTNode.InsideJavadoc) == 0 && refType.isOrEnclosedByPrivateType() && !scope.isDefinedInType(refType)) {
			// ignore cases where type is used from inside itself
			((ReferenceBinding)refType.erasure()).modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
		}

		if (refType.hasRestrictedAccess()) {
			AccessRestriction restriction = scope.environment().getAccessRestriction(type.erasure());
			if (restriction != null) {
				scope.problemReporter().forbiddenReference(type, this, restriction.classpathEntryType,
						restriction.classpathEntryName, restriction.getProblemId());
			}
		}

		// force annotations resolution before deciding whether the type may be deprecated
		refType.initializeDeprecatedAnnotationTagBits();

		if (!refType.isViewedAsDeprecated()) return false;

		// inside same unit - no report
		if (scope.isDefinedInSameUnit(refType)) return false;

		// if context is deprecated, may avoid reporting
		if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
		return true;
	}
 
Example #24
Source File: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void resolvePolyExpressionArguments(Invocation invocation, MethodBinding methodBinding, Scope scope) {
	TypeBinding[] argumentTypes = null;
	Expression[] innerArguments = invocation.arguments();
	if (innerArguments != null) {
		argumentTypes = new TypeBinding[innerArguments.length];
		for (int i = 0; i < innerArguments.length; i++)
			argumentTypes[i] = innerArguments[i].resolvedType;
	}
	resolvePolyExpressionArguments(invocation, methodBinding, argumentTypes, scope);
}
 
Example #25
Source File: ReferenceExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/** During inference: Try to find an applicable method binding without causing undesired side-effects. */
public MethodBinding findCompileTimeMethodTargeting(TypeBinding targetType, Scope scope) {
	MethodBinding targetMethod = internalResolveTentatively(targetType, scope);
	if (targetMethod == null || !targetMethod.isValidBinding())
		return null;
	return targetMethod;
}
 
Example #26
Source File: Reference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean checkNullableFieldDereference(Scope scope, FieldBinding field, long sourcePosition) {
	// preference to type annotations if we have any
	if ((field.type.tagBits & TagBits.AnnotationNullable) != 0) {
		scope.problemReporter().dereferencingNullableExpression(sourcePosition, scope.environment());
		return true;
	}
	if ((field.tagBits & TagBits.AnnotationNullable) != 0) {
		scope.problemReporter().nullableFieldDereference(field, sourcePosition);
		return true;
	}
	return false;
}
 
Example #27
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.jdt.internal.compiler.ast.Expression#computeConversion(org.eclipse.jdt.internal.compiler.lookup.Scope, org.eclipse.jdt.internal.compiler.lookup.TypeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding)
 */
public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
	if (runtimeTimeType == null || compileTimeType == null)
		return;
	if ((this.bits & Binding.FIELD) != 0 && this.binding != null && this.binding.isValidBinding()) {
		// set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
		FieldBinding field = (FieldBinding) this.binding;
		FieldBinding originalBinding = field.original();
		TypeBinding originalType = originalBinding.type;
		// extra cast needed if field type is type variable
		if (originalType.leafComponentType().isTypeVariable()) {
	    	TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
	    		? compileTimeType  // unboxing: checkcast before conversion
	    		: runtimeTimeType;
	        this.genericCast = originalType.genericCast(scope.boxing(targetType));
	        if (this.genericCast instanceof ReferenceBinding) {
				ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
				if (!referenceCast.canBeSeenBy(scope)) {
		        	scope.problemReporter().invalidType(this,
		        			new ProblemReferenceBinding(
								CharOperation.splitOn('.', referenceCast.shortReadableName()),
								referenceCast,
								ProblemReasons.NotVisible));
				}
	        }
		}
	}
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
}
 
Example #28
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.jdt.internal.compiler.ast.Expression#postConversionType(Scope)
 */
public TypeBinding postConversionType(Scope scope) {
	TypeBinding convertedType = this.resolvedType;
	if (this.genericCast != null)
		convertedType = this.genericCast;
	int runtimeType = (this.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4;
	switch (runtimeType) {
		case T_boolean :
			convertedType = TypeBinding.BOOLEAN;
			break;
		case T_byte :
			convertedType = TypeBinding.BYTE;
			break;
		case T_short :
			convertedType = TypeBinding.SHORT;
			break;
		case T_char :
			convertedType = TypeBinding.CHAR;
			break;
		case T_int :
			convertedType = TypeBinding.INT;
			break;
		case T_float :
			convertedType = TypeBinding.FLOAT;
			break;
		case T_long :
			convertedType = TypeBinding.LONG;
			break;
		case T_double :
			convertedType = TypeBinding.DOUBLE;
			break;
		default :
	}
	if ((this.implicitConversion & TypeIds.BOXING) != 0) {
		convertedType = scope.environment().computeBoxingType(convertedType);
	}
	return convertedType;
}
 
Example #29
Source File: Expression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding expressionType, TypeBinding match, boolean isNarrowing) {
	if (TypeBinding.equalsEquals(match, castType)) {
		if (!isNarrowing) tagAsUnnecessaryCast(scope, castType);
		return true;
	}
	if (match != null && (!castType.isReifiable() || !expressionType.isReifiable())) {
		if(isNarrowing
				? match.isProvablyDistinct(expressionType)
				: castType.isProvablyDistinct(match)) {
			return false;
		}
	}
	if (!isNarrowing) tagAsUnnecessaryCast(scope, castType);
	return true;
}
 
Example #30
Source File: Expression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isAssignmentCompatible (TypeBinding left, Scope scope) {
	if (this.resolvedType == null)
		return false;
	return isConstantValueOfTypeAssignableToType(this.resolvedType, left) || 
				this.resolvedType.isCompatibleWith(left) || 
				isBoxingCompatible(this.resolvedType, left, this, scope);
}