Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.BlockScope#methodScope()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.BlockScope#methodScope() .
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: CodeSnippetThisReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean checkAccess(BlockScope scope, ReferenceBinding thisType) { // this/super cannot be used in constructor call MethodScope methodScope = scope.methodScope(); if (this.evaluationContext.isConstructorCall) { methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this); return false; } // static may not refer to this/super if (this.evaluationContext.declaringTypeName == null || this.evaluationContext.isStatic) { methodScope.problemReporter().errorThisSuperInStatic(this); return false; } scope.tagAsAccessingEnclosingInstanceStateOf(thisType, false /* type variable access */); return true; }
Example 2
Source File: CodeSnippetThisReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding resolveType(BlockScope scope) { // implicit this this.constant = Constant.NotAConstant; ReferenceBinding snippetType = scope.enclosingSourceType(); MethodScope methodScope = scope.methodScope(); if (!this.isImplicit && !checkAccess(scope, snippetType)) { return null; } this.delegateThis = scope.getField(snippetType, DELEGATE_THIS, this); if (this.delegateThis == null || !this.delegateThis.isValidBinding()) { // should not happen // if this happen we should report illegal access to this in a static context methodScope.problemReporter().errorThisSuperInStatic(this); return null; } return this.resolvedType = this.delegateThis.type; }
Example 3
Source File: CodeSnippetQualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Check and/or redirect the field access to the delegate receiver if any */ public TypeBinding checkFieldAccess(BlockScope scope) { FieldBinding fieldBinding = (FieldBinding) this.binding; MethodScope methodScope = scope.methodScope(); TypeBinding declaringClass = fieldBinding.original().declaringClass; // check for forward references if ((this.indexOfFirstFieldBinding == 1 || declaringClass.isEnum()) && TypeBinding.equalsEquals(methodScope.enclosingSourceType(), declaringClass) && methodScope.lastVisibleFieldID >= 0 && fieldBinding.id >= methodScope.lastVisibleFieldID && (!fieldBinding.isStatic() || methodScope.isStatic)) { scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding); } this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.FIELD; return getOtherFieldBindings(scope); }
Example 4
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Mark that this resource is passed to some outside code * (as argument to a method/ctor call or as a return value from the current method), * and thus should be considered as potentially closed. * @param owned should the resource be considered owned by some outside? */ public static FlowInfo markPassedToOutside(BlockScope scope, Expression expression, FlowInfo flowInfo, FlowContext flowContext, boolean owned) { FakedTrackingVariable trackVar = getCloseTrackingVariable(expression, flowInfo, flowContext); if (trackVar != null) { // insert info that the tracked resource *may* be closed (by the target method, i.e.) FlowInfo infoResourceIsClosed = owned ? flowInfo : flowInfo.copy(); int flag = owned ? OWNED_BY_OUTSIDE : SHARED_WITH_OUTSIDE; do { trackVar.globalClosingState |= flag; if (scope.methodScope() != trackVar.methodScope) trackVar.globalClosingState |= CLOSED_IN_NESTED_METHOD; infoResourceIsClosed.markAsDefinitelyNonNull(trackVar.binding); } while ((trackVar = trackVar.innerTracker) != null); if (owned) { return infoResourceIsClosed; // don't let downstream signal any problems on this flow } else { return FlowInfo.conditional(flowInfo, infoResourceIsClosed); // only report potential problems on this flow } } return flowInfo; }
Example 5
Source File: ReferenceExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean shouldGenerateImplicitLambda(BlockScope currentScope) { // these cases are either too complicated, impossible to handle or result in significant code duplication return (this.binding.isVarargs() || (isConstructorReference() && this.receiverType.syntheticOuterLocalVariables() != null && currentScope.methodScope().isStatic) || this.expectedType instanceof IntersectionCastTypeBinding || // marker interfaces require alternate meta factory. this.expectedType.findSuperTypeOriginatingFrom(currentScope.getJavaIoSerializable()) != null || // serialization support. this.requiresBridges()); // bridges. // To fix: We should opt for direct code generation wherever possible. }
Example 6
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private FakedTrackingVariable(BlockScope scope, ASTNode location, FlowInfo flowInfo, int nullStatus) { super(UNASSIGNED_CLOSEABLE_NAME, location.sourceStart, location.sourceEnd); this.type = new SingleTypeReference( TypeConstants.OBJECT, ((long)this.sourceStart <<32)+this.sourceEnd); this.methodScope = scope.methodScope(); this.originalBinding = null; resolve(scope); if (nullStatus != 0) flowInfo.markNullStatus(this.binding, nullStatus); // mark that this flow has seen the resource }
Example 7
Source File: MessageSend.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void recordCallingClose(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Expression closeTarget) { FakedTrackingVariable trackingVariable = FakedTrackingVariable.getCloseTrackingVariable(closeTarget, flowInfo, flowContext); if (trackingVariable != null) { // null happens if target is not a local variable or not an AutoCloseable if (trackingVariable.methodScope == currentScope.methodScope()) { trackingVariable.markClose(flowInfo, flowContext); } else { trackingVariable.markClosedInNestedMethod(); } } }
Example 8
Source File: CodeSnippetQualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding getOtherFieldBindings(BlockScope scope) { // At this point restrictiveFlag may ONLY have two potential value : FIELD LOCAL (i.e cast <<(VariableBinding) binding>> is valid) int length = this.tokens.length; if ((this.bits & Binding.FIELD) != 0) { if (!((FieldBinding) this.binding).isStatic()) { //must check for the static status.... if (this.indexOfFirstFieldBinding == 1) { //the field is the first token of the qualified reference.... if (scope.methodScope().isStatic) { scope.problemReporter().staticFieldAccessToNonStaticVariable(this, (FieldBinding) this.binding); return null; } } else { //accessing to a field using a type as "receiver" is allowed only with static field scope.problemReporter().staticFieldAccessToNonStaticVariable(this, (FieldBinding) this.binding); return null; } } // only last field is actually a write access if any if (isFieldUseDeprecated((FieldBinding) this.binding, scope, this.indexOfFirstFieldBinding == length ? this.bits : 0)) { scope.problemReporter().deprecatedField((FieldBinding) this.binding, this); } } TypeBinding type = ((VariableBinding) this.binding).type; int index = this.indexOfFirstFieldBinding; if (index == length) { // restrictiveFlag == FIELD this.constant = ((FieldBinding) this.binding).constant(); return type; } // allocation of the fieldBindings array and its respective constants int otherBindingsLength = length - index; this.otherBindings = new FieldBinding[otherBindingsLength]; // fill the first constant (the one of the binding) this.constant =((VariableBinding) this.binding).constant(); // iteration on each field while (index < length) { char[] token = this.tokens[index]; if (type == null) return null; // could not resolve type prior to this point FieldBinding field = scope.getField(type, token, this); int place = index - this.indexOfFirstFieldBinding; this.otherBindings[place] = field; if (!field.isValidBinding()) { // try to retrieve the field as private field CodeSnippetScope localScope = new CodeSnippetScope(scope); if (this.delegateThis == null) { if (this.evaluationContext.declaringTypeName != null) { this.delegateThis = scope.getField(scope.enclosingSourceType(), DELEGATE_THIS, this); if (this.delegateThis == null){ // if not found then internal error, field should have been found return super.reportError(scope); } this.actualReceiverType = this.delegateThis.type; } else { this.constant = Constant.NotAConstant; //don't fill other constants slots... scope.problemReporter().invalidField(this, field, index, type); return null; } } field = localScope.getFieldForCodeSnippet(this.delegateThis.type, token, this); this.otherBindings[place] = field; } if (field.isValidBinding()) { // only last field is actually a write access if any if (isFieldUseDeprecated(field, scope, index+1 == length ? this.bits : 0)) { scope.problemReporter().deprecatedField(field, this); } // constant propagation can only be performed as long as the previous one is a constant too. if (this.constant != Constant.NotAConstant){ this.constant = field.constant(); } type = field.type; index++; } else { this.constant = Constant.NotAConstant; //don't fill other constants slots... scope.problemReporter().invalidField(this, field, index, type); return null; } } return (this.otherBindings[otherBindingsLength - 1]).type; }
Example 9
Source File: ExceptionHandlingFlowContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
ExceptionHandlingFlowContext( FlowContext parent, ASTNode associatedNode, ReferenceBinding[] handledExceptions, int [] exceptionToCatchBlockMap, Argument [] catchArguments, FlowContext initializationParent, BlockScope scope, UnconditionalFlowInfo flowInfo) { super(parent, associatedNode); this.isMethodContext = scope == scope.methodScope(); this.handledExceptions = handledExceptions; this.catchArguments = catchArguments; this.exceptionToCatchBlockMap = exceptionToCatchBlockMap; int count = handledExceptions.length, cacheSize = (count / ExceptionHandlingFlowContext.BitCacheSize) + 1; this.isReached = new int[cacheSize]; // none is reached by default this.isNeeded = new int[cacheSize]; // none is needed by default this.initsOnExceptions = new UnconditionalFlowInfo[count]; boolean markExceptionsAndThrowableAsReached = !this.isMethodContext || scope.compilerOptions().reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable; for (int i = 0; i < count; i++) { ReferenceBinding handledException = handledExceptions[i]; int catchBlock = this.exceptionToCatchBlockMap != null? this.exceptionToCatchBlockMap[i] : i; this.indexes.put(handledException, i); // key type -> value index if (handledException.isUncheckedException(true)) { if (markExceptionsAndThrowableAsReached || handledException.id != TypeIds.T_JavaLangThrowable && handledException.id != TypeIds.T_JavaLangException) { this.isReached[i / ExceptionHandlingFlowContext.BitCacheSize] |= 1 << (i % ExceptionHandlingFlowContext.BitCacheSize); } this.initsOnExceptions[catchBlock] = flowInfo.unconditionalCopy(); } else { this.initsOnExceptions[catchBlock] = FlowInfo.DEAD_END; } } if (!this.isMethodContext) { System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize); } this.initsOnReturn = FlowInfo.DEAD_END; this.initializationParent = initializationParent; }
Example 10
Source File: Reference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
static void reportOnlyUselesslyReadLocal(BlockScope currentScope, LocalVariableBinding localBinding, boolean valueRequired) { if (localBinding.declaration == null) return; // secret local if ((localBinding.declaration.bits & ASTNode.IsLocalDeclarationReachable) == 0) return; // declaration is unreachable if (localBinding.useFlag >= LocalVariableBinding.USED) return; // we're only interested in cases with only compound access (negative count) if (valueRequired) { // access is relevant localBinding.useFlag = LocalVariableBinding.USED; return; } else { localBinding.useFlag++; if (localBinding.useFlag != LocalVariableBinding.UNUSED) // have all negative counts been consumed? return; // still waiting to see more usages of this kind } // at this point we know we have something to report if (localBinding.declaration instanceof Argument) { // check compiler options to report against unused arguments MethodScope methodScope = currentScope.methodScope(); if (methodScope != null && !methodScope.isLambdaScope()) { // lambda must be congruent with the descriptor. MethodBinding method = ((AbstractMethodDeclaration)methodScope.referenceContext()).binding; boolean shouldReport = !method.isMain(); if (method.isImplementing()) { shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenImplementingAbstract; } else if (method.isOverriding()) { shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenOverridingConcrete; } if (shouldReport) { // report the case of an argument that is unread except through a special operator currentScope.problemReporter().unusedArgument(localBinding.declaration); } } } else { // report the case of a local variable that is unread except for a special operator currentScope.problemReporter().unusedLocalVariable(localBinding.declaration); } localBinding.useFlag = LocalVariableBinding.USED; // don't report again }
Example 11
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding checkFieldAccess(BlockScope scope) { FieldBinding fieldBinding = (FieldBinding) this.binding; this.constant = fieldBinding.constant(); this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.FIELD; MethodScope methodScope = scope.methodScope(); if (fieldBinding.isStatic()) { // check if accessing enum static field in initializer ReferenceBinding declaringClass = fieldBinding.declaringClass; if (declaringClass.isEnum()) { SourceTypeBinding sourceType = scope.enclosingSourceType(); if (this.constant == Constant.NotAConstant && !methodScope.isStatic && (TypeBinding.equalsEquals(sourceType, declaringClass) || TypeBinding.equalsEquals(sourceType.superclass, declaringClass)) // enum constant body && methodScope.isInsideInitializerOrConstructor()) { scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); } } } else { if (scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding); } // must check for the static status.... if (methodScope.isStatic) { scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding); return fieldBinding.type; } else { scope.tagAsAccessingEnclosingInstanceStateOf(fieldBinding.declaringClass, false /* type variable access */); } } if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) scope.problemReporter().deprecatedField(fieldBinding, this); if ((this.bits & ASTNode.IsStrictlyAssigned) == 0 && TypeBinding.equalsEquals(methodScope.enclosingSourceType(), fieldBinding.original().declaringClass) && methodScope.lastVisibleFieldID >= 0 && fieldBinding.id >= methodScope.lastVisibleFieldID && (!fieldBinding.isStatic() || methodScope.isStatic)) { scope.problemReporter().forwardReference(this, 0, fieldBinding); this.bits |= ASTNode.IgnoreNoEffectAssignCheck; } return fieldBinding.type; }