org.eclipse.jdt.internal.compiler.lookup.BlockScope Java Examples
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.BlockScope.
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: Extractor.java From javaide with GNU General Public License v3.0 | 6 votes |
@Override public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) { Annotation[] annotations = localTypeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = localTypeDeclaration.binding; if (binding == null) { return true; } String fqn = getFqn(scope); if (fqn == null) { fqn = new String(localTypeDeclaration.binding.readableName()); } Item item = ClassItem.create(fqn, ClassKind.forType(localTypeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; }
Example #2
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static void handleRegularResource(BlockScope scope, FlowInfo flowInfo, AllocationExpression allocation) { FakedTrackingVariable presetTracker = allocation.closeTracker; if (presetTracker != null && presetTracker.originalBinding != null) { // the current assignment forgets a previous resource in the LHS, may cause a leak // report now because handleResourceAssignment can't distinguish this from a self-wrap situation int closeStatus = flowInfo.nullStatus(presetTracker.binding); if (closeStatus != FlowInfo.NON_NULL // old resource was not closed && closeStatus != FlowInfo.UNKNOWN // old resource had some flow information && !flowInfo.isDefinitelyNull(presetTracker.originalBinding) // old resource was not null && !(presetTracker.currentAssignment instanceof LocalDeclaration)) // forgetting old val in local decl is syntactically impossible allocation.closeTracker.recordErrorLocation(presetTracker.currentAssignment, closeStatus); } else { allocation.closeTracker = new FakedTrackingVariable(scope, allocation, flowInfo, FlowInfo.UNKNOWN); // no local available, closeable is unassigned } flowInfo.markAsDefinitelyNull(allocation.closeTracker.binding); }
Example #3
Source File: Expression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding resolveTypeExpecting(BlockScope scope, TypeBinding expectedType) { setExpectedType(expectedType); // needed in case of generic method invocation TypeBinding expressionType = this.resolveType(scope); if (expressionType == null) return null; if (TypeBinding.equalsEquals(expressionType, expectedType)) return expressionType; if (!expressionType.isCompatibleWith(expectedType)) { if (scope.isBoxingCompatibleWith(expressionType, expectedType)) { computeConversion(scope, expectedType, expressionType); } else { scope.problemReporter().typeMismatchError(expressionType, expectedType, this, null); return null; } } return expressionType; }
Example #4
Source File: ArrayReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; if (this.receiver instanceof CastExpression // no cast check for ((type[])null)[0] && ((CastExpression)this.receiver).innermostCastedExpression() instanceof NullLiteral) { this.receiver.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on } TypeBinding arrayType = this.receiver.resolveType(scope); if (arrayType != null) { this.receiver.computeConversion(scope, arrayType, arrayType); if (arrayType.isArrayType()) { TypeBinding elementType = ((ArrayBinding) arrayType).elementsType(); this.resolvedType = ((this.bits & ASTNode.IsStrictlyAssigned) == 0) ? elementType.capture(scope, this.sourceEnd) : elementType; } else { scope.problemReporter().referenceMustBeArrayTypeAt(arrayType, this); } } TypeBinding positionType = this.position.resolveTypeExpecting(scope, TypeBinding.INT); if (positionType != null) { this.position.computeConversion(scope, TypeBinding.INT, positionType); } return this.resolvedType; }
Example #5
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Casting an enclosing instance will considered as useful if removing it would actually bind to a different type */ public static void checkNeedForEnclosingInstanceCast(BlockScope scope, Expression enclosingInstance, TypeBinding enclosingInstanceType, TypeBinding memberType) { if (scope.compilerOptions().getSeverity(CompilerOptions.UnnecessaryTypeCheck) == ProblemSeverities.Ignore) return; TypeBinding castedExpressionType = ((CastExpression)enclosingInstance).expression.resolvedType; if (castedExpressionType == null) return; // cannot do better // obvious identity cast if (TypeBinding.equalsEquals(castedExpressionType, enclosingInstanceType)) { scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance); } else if (castedExpressionType == TypeBinding.NULL){ return; // tolerate null enclosing instance cast } else { TypeBinding alternateEnclosingInstanceType = castedExpressionType; if (castedExpressionType.isBaseType() || castedExpressionType.isArrayType()) return; // error case if (TypeBinding.equalsEquals(memberType, scope.getMemberType(memberType.sourceName(), (ReferenceBinding) alternateEnclosingInstanceType))) { scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance); } } }
Example #6
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) { //If inlinable field, forget the access emulation, the code gen will directly target it if (((this.bits & ASTNode.DepthMASK) == 0 && (this.bits & ASTNode.IsCapturedOuterLocal) == 0) || (this.constant != Constant.NotAConstant)) { return; } if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) { LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding; if (localVariableBinding != null) { if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) { // local was tagged as uninitialized return; } switch(localVariableBinding.useFlag) { case LocalVariableBinding.FAKE_USED : case LocalVariableBinding.USED : currentScope.emulateOuterAccess(localVariableBinding); } } } }
Example #7
Source File: IntLiteral.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Code generation for long literal * * @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; if (valueRequired) { codeStream.generateConstant(this.constant, this.implicitConversion); } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example #8
Source File: CombinedBinaryExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void traverse(ASTVisitor visitor, BlockScope scope) { if (this.referencesTable == null) { super.traverse(visitor, scope); } else { if (visitor.visit(this, scope)) { int restart; for (restart = this.arity - 1; restart >= 0; restart--) { if (!visitor.visit( this.referencesTable[restart], scope)) { visitor.endVisit( this.referencesTable[restart], scope); break; } } restart++; // restart now points to the deepest BE for which // visit returned true, if any if (restart == 0) { this.referencesTable[0].left.traverse(visitor, scope); } for (int i = restart, end = this.arity; i < end; i++) { this.referencesTable[i].right.traverse(visitor, scope); visitor.endVisit(this.referencesTable[i], scope); } this.right.traverse(visitor, scope); } visitor.endVisit(this, scope); } }
Example #9
Source File: ReferenceExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { // static methods with receiver value never get here if (this.haveReceiver) { this.lhs.checkNPE(currentScope, flowContext, flowInfo); this.lhs.analyseCode(currentScope, flowContext, flowInfo, true); } manageSyntheticAccessIfNecessary(currentScope, flowInfo); return flowInfo; }
Example #10
Source File: ThrowStatement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Throw code generation * * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream */ public void generateCode(BlockScope currentScope, CodeStream codeStream) { if ((this.bits & ASTNode.IsReachable) == 0) return; int pc = codeStream.position; this.exception.generateCode(currentScope, codeStream, true); codeStream.athrow(); codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example #11
Source File: PatchVal.java From EasyMPermission with MIT License | 5 votes |
public static TypeBinding skipResolveInitializerIfAlreadyCalled2(Expression expr, BlockScope scope, LocalDeclaration decl) { if (decl != null && LocalDeclaration.class.equals(decl.getClass()) && expr.resolvedType != null) return expr.resolvedType; try { return expr.resolveType(scope); } catch (NullPointerException e) { return null; } }
Example #12
Source File: PatchVal.java From EasyMPermission with MIT License | 5 votes |
private static boolean isVal(TypeReference ref, BlockScope scope) { if (!couldBeVal(ref)) return false; TypeBinding resolvedType = ref.resolvedType; if (resolvedType == null) resolvedType = ref.resolveType(scope, false); if (resolvedType == null) return false; char[] pkg = resolvedType.qualifiedPackageName(); char[] nm = resolvedType.qualifiedSourceName(); return matches("lombok", pkg) && matches("val", nm); }
Example #13
Source File: SelectionOnNameOfMemberValuePair.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void resolveTypeExpecting(BlockScope scope, TypeBinding requiredType) { super.resolveTypeExpecting(scope, requiredType); if(this.binding != null) { throw new SelectionNodeFound(this.binding); } throw new SelectionNodeFound(); }
Example #14
Source File: Expression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Every expression is responsible for generating its implicit conversion when necessary. * * @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) { if (this.constant != Constant.NotAConstant) { // generate a constant expression int pc = codeStream.position; codeStream.generateConstant(this.constant, this.implicitConversion); codeStream.recordPositionsFrom(pc, this.sourceStart); } else { // actual non-constant code generation throw new ShouldNotImplement(Messages.ast_missingCode); } }
Example #15
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void traverse(ASTVisitor visitor, BlockScope blockScope) { if (visitor.visit(this, blockScope)) { this.type.traverse(visitor, blockScope); this.expression.traverse(visitor, blockScope); } visitor.endVisit(this, blockScope); }
Example #16
Source File: SuperReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; ReferenceBinding enclosingReceiverType = scope.enclosingReceiverType(); if (!checkAccess(scope, enclosingReceiverType)) return null; if (enclosingReceiverType.id == T_JavaLangObject) { scope.problemReporter().cannotUseSuperInJavaLangObject(this); return null; } return this.resolvedType = enclosingReceiverType.superclass(); }
Example #17
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Normal field binding did not work, try to bind to a field of the delegate receiver. */ public TypeBinding reportError(BlockScope scope) { if (this.binding instanceof ProblemFieldBinding) { scope.problemReporter().invalidField(this, (FieldBinding) this.binding); } else if (this.binding instanceof ProblemReferenceBinding || this.binding instanceof MissingTypeBinding) { scope.problemReporter().invalidType(this, (TypeBinding) this.binding); } else { scope.problemReporter().unresolvableReference(this, this.binding); } return null; }
Example #18
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 #19
Source File: NullAnnotationMatching.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** Check null-ness of 'var' against a possible null annotation */ public static int checkAssignment(BlockScope currentScope, FlowContext flowContext, VariableBinding var, int nullStatus, Expression expression, TypeBinding providedType) { long lhsTagBits = 0L; boolean hasReported = false; if (currentScope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8) { lhsTagBits = var.tagBits & TagBits.AnnotationNullMASK; } else { if (expression instanceof ConditionalExpression && expression.isPolyExpression()) { // drill into both branches: ConditionalExpression ce = ((ConditionalExpression) expression); int status1 = NullAnnotationMatching.checkAssignment(currentScope, flowContext, var, ce.ifTrueNullStatus, ce.valueIfTrue, ce.valueIfTrue.resolvedType); int status2 = NullAnnotationMatching.checkAssignment(currentScope, flowContext, var, ce.ifFalseNullStatus, ce.valueIfFalse, ce.valueIfFalse.resolvedType); if (status1 == status2) return status1; return nullStatus; // if both branches disagree use the precomputed & merged nullStatus } lhsTagBits = var.type.tagBits & TagBits.AnnotationNullMASK; NullAnnotationMatching annotationStatus = analyse(var.type, providedType, nullStatus); if (annotationStatus.isDefiniteMismatch()) { currentScope.problemReporter().nullityMismatchingTypeAnnotation(expression, providedType, var.type, annotationStatus); hasReported = true; } else if (annotationStatus.isUnchecked()) { flowContext.recordNullityMismatch(currentScope, expression, providedType, var.type, nullStatus); hasReported = true; } else if (annotationStatus.nullStatus != FlowInfo.UNKNOWN) { return annotationStatus.nullStatus; } } if (lhsTagBits == TagBits.AnnotationNonNull && nullStatus != FlowInfo.NON_NULL) { if (!hasReported) flowContext.recordNullityMismatch(currentScope, expression, providedType, var.type, nullStatus); return FlowInfo.NON_NULL; } else if (lhsTagBits == TagBits.AnnotationNullable && nullStatus == FlowInfo.UNKNOWN) { // provided a legacy type? return FlowInfo.POTENTIALLY_NULL; // -> use more specific info from the annotation } return nullStatus; }
Example #20
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static FakedTrackingVariable pickMoreUnsafe(FakedTrackingVariable tracker1, FakedTrackingVariable tracker2, BlockScope scope, FlowInfo info) { // whichever of the two trackers has stronger indication to be leaking will be returned, // the other one will be removed from the scope (considered to be merged into the former). int status1 = info.nullStatus(tracker1.binding); int status2 = info.nullStatus(tracker2.binding); if (status1 == FlowInfo.NULL || status2 == FlowInfo.NON_NULL) return pick(tracker1, tracker2, scope); if (status1 == FlowInfo.NON_NULL || status2 == FlowInfo.NULL) return pick(tracker2, tracker1, scope); if ((status1 & FlowInfo.POTENTIALLY_NULL) != 0) return pick(tracker1, tracker2, scope); if ((status2 & FlowInfo.POTENTIALLY_NULL) != 0) return pick(tracker2, tracker1, scope); return pick(tracker1, tracker2, scope); }
Example #21
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Pick tracking variables from 'varsOfScope' to establish a proper order of processing: * As much as possible pick wrapper resources before their inner resources. * Also consider cases of wrappers and their inners being declared at different scopes. */ public static FakedTrackingVariable pickVarForReporting(Set varsOfScope, BlockScope scope, boolean atExit) { if (varsOfScope.isEmpty()) return null; FakedTrackingVariable trackingVar = (FakedTrackingVariable) varsOfScope.iterator().next(); while (trackingVar.outerTracker != null) { // resource is wrapped, is wrapper defined in this scope? if (varsOfScope.contains(trackingVar.outerTracker)) { // resource from same scope, travel up the wrapper chain trackingVar = trackingVar.outerTracker; } else if (atExit) { // at an exit point we report against inner despite a wrapper that may/may not be closed later break; } else { BlockScope outerTrackerScope = trackingVar.outerTracker.binding.declaringScope; if (outerTrackerScope == scope) { // outerTracker is from same scope and already processed -> pick trackingVar now break; } else { // outer resource is from other (outer?) scope Scope currentScope = scope; while ((currentScope = currentScope.parent) instanceof BlockScope) { if (outerTrackerScope == currentScope) { // at end of block pass responsibility for inner resource to outer scope holding a wrapper varsOfScope.remove(trackingVar); // drop this one // pick a next candidate: return pickVarForReporting(varsOfScope, scope, atExit); } } break; // not parent owned -> pick this var } } } varsOfScope.remove(trackingVar); return trackingVar; }
Example #22
Source File: FloatLiteral.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Code generation for float literal * * @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; if (valueRequired) { codeStream.generateConstant(this.constant, this.implicitConversion); } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example #23
Source File: TypeReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope, boolean checkBounds) { return resolveType(scope, checkBounds, 0); }
Example #24
Source File: SetGeneratedByVisitor.java From EasyMPermission with MIT License | 4 votes |
@Override public boolean visit(SwitchStatement node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
Example #25
Source File: CodeSnippetFieldReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { // Answer the signature type of the field. // constants are propaged when the field is final // and initialized with a (compile time) constant // regular receiver reference this.actualReceiverType = this.receiver.resolveType(scope); if (this.actualReceiverType == null){ this.constant = Constant.NotAConstant; return null; } // the case receiverType.isArrayType and token = 'length' is handled by the scope API this.binding = scope.getField(this.actualReceiverType, this.token, this); FieldBinding firstAttempt = this.binding; boolean isNotVisible = false; if (!this.binding.isValidBinding()) { if (this.binding instanceof ProblemFieldBinding && ((ProblemFieldBinding) this.binding).problemId() == NotVisible) { isNotVisible = true; 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 this.constant = Constant.NotAConstant; scope.problemReporter().invalidField(this, this.actualReceiverType); return null; } this.actualReceiverType = this.delegateThis.type; } else { this.constant = Constant.NotAConstant; scope.problemReporter().invalidField(this, this.actualReceiverType); return null; } CodeSnippetScope localScope = new CodeSnippetScope(scope); this.binding = localScope.getFieldForCodeSnippet(this.delegateThis.type, this.token, this); } } if (!this.binding.isValidBinding()) { this.constant = Constant.NotAConstant; if (isNotVisible) { this.binding = firstAttempt; } scope.problemReporter().invalidField(this, this.actualReceiverType); return null; } if (isFieldUseDeprecated(this.binding, scope, this.bits)) { scope.problemReporter().deprecatedField(this.binding, this); } // check for this.x in static is done in the resolution of the receiver this.constant = this.receiver.isImplicitThis() ? this.binding.constant() : Constant.NotAConstant; if (!this.receiver.isThis()) { // TODO need to check if shouldn't be isImplicitThis check (and then removed) this.constant = Constant.NotAConstant; } return this.resolvedType = this.binding.type; }
Example #26
Source File: SetGeneratedByVisitor.java From EasyMPermission with MIT License | 4 votes |
@Override public boolean visit(IfStatement node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
Example #27
Source File: EmptyStatement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void traverse(ASTVisitor visitor, BlockScope scope) { visitor.visit(this, scope); visitor.endVisit(this, scope); }
Example #28
Source File: BinaryExpressionFragmentBuilder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean visit(DoubleLiteral doubleLiteral, BlockScope scope) { addSmallFragment(doubleLiteral); return false; }
Example #29
Source File: ASTVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void endVisit(TryStatement tryStatement, BlockScope scope) { // do nothing by default }
Example #30
Source File: ASTVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean visit(ThisReference thisReference, BlockScope scope) { return true; // do nothing by default, keep traversing }