Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.Binding#LOCAL
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.Binding#LOCAL .
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: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Constant optimizedBooleanConstant() { switch (this.resolvedType.id) { case T_boolean : case T_JavaLangBoolean : if (this.constant != Constant.NotAConstant) return this.constant; switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field if (this.otherBindings == null) return ((FieldBinding)this.binding).constant(); //$FALL-THROUGH$ case Binding.LOCAL : // reading a local variable return this.otherBindings[this.otherBindings.length-1].constant(); } } return Constant.NotAConstant; }
Example 2
Source File: TypeMirrorImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public TypeKind getKind() { switch (_binding.kind()) { // case Binding.TYPE: // case Binding.RAW_TYPE: // case Binding.GENERIC_TYPE: // case Binding.PARAMETERIZED_TYPE: // handled by DeclaredTypeImpl, etc. // case Binding.BASE_TYPE: handled by PrimitiveTypeImpl // case Binding.METHOD: handled by ExecutableTypeImpl // case Binding.PACKAGE: handled by NoTypeImpl // case Binding.WILDCARD_TYPE: handled by WildcardTypeImpl // case Binding.ARRAY_TYPE: handled by ArrayTypeImpl // case Binding.TYPE_PARAMETER: handled by TypeVariableImpl // TODO: fill in the rest of these case Binding.FIELD: case Binding.LOCAL: case Binding.VARIABLE: case Binding.IMPORT: throw new IllegalArgumentException("Invalid binding kind: " + _binding.kind()); //$NON-NLS-1$ } return null; }
Example 3
Source File: QualifiedNameReference.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 4
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 5
Source File: DefaultBindingResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) { switch (binding.kind()) { case Binding.PACKAGE: return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding); case Binding.TYPE: case Binding.BASE_TYPE: case Binding.GENERIC_TYPE: case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: return getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); case Binding.ARRAY_TYPE: case Binding.TYPE_PARAMETER: return new TypeBinding(this, (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); case Binding.METHOD: return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) binding); case Binding.FIELD: case Binding.LOCAL: return getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding); } return null; }
Example 6
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.LOCAL: LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; // check if compound assignment is the only usage of this local Reference.reportOnlyUselesslyReadLocal(currentScope, localBinding, valueRequired); break; case Binding.FIELD: // check if compound assignment is the only usage of a private field reportOnlyUselesslyReadPrivateField(currentScope, (FieldBinding)this.binding, valueRequired); } this.generateCompoundAssignment( currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], expression, operator, assignmentImplicitConversion, valueRequired); }
Example 7
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/); } // check if reading a final blank field FieldBinding fieldBinding = (FieldBinding) this.binding; if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) { FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo); if (!fieldInits.isDefinitelyAssigned(fieldBinding)) { currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this); } } break; case Binding.LOCAL : // reading a local variable LocalVariableBinding localBinding; if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) { currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { localBinding.useFlag = LocalVariableBinding.USED; } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { localBinding.useFlag = LocalVariableBinding.FAKE_USED; } } if (valueRequired) { manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo); } return flowInfo; }
Example 8
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkInternalNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo, boolean checkString) { if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) { LocalVariableBinding local = (LocalVariableBinding) this.binding; if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0 && (checkString || local.type.id != TypeIds.T_JavaLangString)) { if ((this.bits & ASTNode.IsNonNull) == 0) { flowContext.recordUsingNullReference(scope, local, this, FlowContext.MAY_NULL, flowInfo); } flowInfo.markAsComparedEqualToNonNull(local); // from thereon it is set flowContext.markFinallyNullStatus(local, FlowInfo.NON_NULL); } } if (this.otherBindings != null) { if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.FIELD) { // is the first field dereferenced annotated Nullable? If so, report immediately checkNullableFieldDereference(scope, (FieldBinding) this.binding, this.sourcePositions[this.indexOfFirstFieldBinding-1]); } // look for annotated fields, they do not depend on flow context -> check immediately: int length = this.otherBindings.length - 1; // don't check the last binding for (int i = 0; i < length; i++) { checkNullableFieldDereference(scope, this.otherBindings[i], this.sourcePositions[this.indexOfFirstFieldBinding+i]); } } }
Example 9
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public VariableBinding nullAnnotatedVariableBinding(boolean supportTypeAnnotations) { switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field case Binding.LOCAL : // reading a local variable if (supportTypeAnnotations || (((VariableBinding)this.binding).tagBits & TagBits.AnnotationNullMASK) != 0) return (VariableBinding) this.binding; } return null; }
Example 10
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the local variable referenced by this node. Can be a direct reference (SingleNameReference) * or thru a cast expression etc... */ public LocalVariableBinding localVariableBinding() { switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field break; case Binding.LOCAL : // reading a local variable return (LocalVariableBinding) this.binding; } return null; }
Example 11
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Create a new element that knows what kind it is even if the binding is unresolved. */ public Element newElement(Binding binding, ElementKind kindHint) { if (binding == null) return null; switch (binding.kind()) { case Binding.FIELD: case Binding.LOCAL: case Binding.VARIABLE: return new VariableElementImpl(_env, (VariableBinding) binding); case Binding.TYPE: case Binding.GENERIC_TYPE: ReferenceBinding referenceBinding = (ReferenceBinding)binding; if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) { return new ErrorTypeElement(this._env, referenceBinding); } if (CharOperation.equals(referenceBinding.sourceName, TypeConstants.PACKAGE_INFO_NAME)) { return new PackageElementImpl(_env, referenceBinding.fPackage); } return new TypeElementImpl(_env, referenceBinding, kindHint); case Binding.METHOD: return new ExecutableElementImpl(_env, (MethodBinding)binding); case Binding.RAW_TYPE: case Binding.PARAMETERIZED_TYPE: return new TypeElementImpl(_env, ((ParameterizedTypeBinding)binding).genericType(), kindHint); case Binding.PACKAGE: return new PackageElementImpl(_env, (PackageBinding)binding); case Binding.TYPE_PARAMETER: return new TypeParameterElementImpl(_env, (TypeVariableBinding)binding); // TODO: fill in the rest of these case Binding.IMPORT: case Binding.ARRAY_TYPE: case Binding.BASE_TYPE: case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: throw new UnsupportedOperationException("NYI: binding type " + binding.kind()); //$NON-NLS-1$ } return null; }
Example 12
Source File: CodeSnippetSingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { switch (this.bits & RestrictiveFlagMASK) { case Binding.FIELD : // reading a field // check if reading a final blank field FieldBinding fieldBinding; if ((fieldBinding = (FieldBinding) this.binding).isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) { FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo); if (!fieldInits.isDefinitelyAssigned(fieldBinding)) { currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this); } } break; case Binding.LOCAL : // reading a local variable LocalVariableBinding localBinding; if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) { currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { localBinding.useFlag = LocalVariableBinding.USED; } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { localBinding.useFlag = LocalVariableBinding.FAKE_USED; } } return flowInfo; }
Example 13
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) { // optimizing assignment like: i = i + 1 or i = 1 + i if (assignment.expression.isCompactableOperation()) { BinaryExpression operation = (BinaryExpression) assignment.expression; int operator = (operation.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT; SingleNameReference variableReference; if ((operation.left instanceof SingleNameReference) && ((variableReference = (SingleNameReference) operation.left).binding == this.binding)) { // i = i + value, then use the variable on the right hand side, since it has the correct implicit conversion variableReference.generateCompoundAssignment(currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], operation.right, operator, operation.implicitConversion, valueRequired); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } return; } if ((operation.right instanceof SingleNameReference) && ((operator == OperatorIds.PLUS) || (operator == OperatorIds.MULTIPLY)) // only commutative operations && ((variableReference = (SingleNameReference) operation.right).binding == this.binding) && (operation.left.constant != Constant.NotAConstant) // exclude non constant expressions, since could have side-effect && (((operation.left.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4) != TypeIds.T_JavaLangString) // exclude string concatenation which would occur backwards && (((operation.right.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4) != TypeIds.T_JavaLangString)) { // exclude string concatenation which would occur backwards // i = value + i, then use the variable on the right hand side, since it has the correct implicit conversion variableReference.generateCompoundAssignment(currentScope, codeStream, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], operation.left, operator, operation.implicitConversion, valueRequired); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } return; } } switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // assigning to a field int pc = codeStream.position; FieldBinding codegenBinding = ((FieldBinding) this.binding).original(); if (!codegenBinding.isStatic()) { // need a receiver? if ((this.bits & ASTNode.DepthMASK) != 0) { ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT); Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/); codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope); } else { generateReceiver(codeStream); } } codeStream.recordPositionsFrom(pc, this.sourceStart); assignment.expression.generateCode(currentScope, codeStream, true); fieldStore(currentScope, codeStream, codegenBinding, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], this.actualReceiverType, true /*implicit this*/, valueRequired); if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } // no need for generic cast as value got dupped return; case Binding.LOCAL : // assigning to a local variable LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; if (localBinding.resolvedPosition != -1) { assignment.expression.generateCode(currentScope, codeStream, true); } else { if (assignment.expression.constant != Constant.NotAConstant) { // assigning an unused local to a constant value = no actual assignment is necessary if (valueRequired) { codeStream.generateConstant(assignment.expression.constant, assignment.implicitConversion); } } else { assignment.expression.generateCode(currentScope, codeStream, true); /* Even though the value may not be required, we force it to be produced, and discard it later on if it was actually not necessary, so as to provide the same behavior as JDK1.2beta3. */ if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); // implicit conversion } else { switch(localBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.pop2(); break; default : codeStream.pop(); break; } } } return; } // 26903, need extra cast to store null in array local var if (localBinding.type.isArrayType() && ((assignment.expression instanceof CastExpression) // arrayLoc = (type[])null && (((CastExpression)assignment.expression).innermostCastedExpression().resolvedType == TypeBinding.NULL))){ codeStream.checkcast(localBinding.type); } // normal local assignment (since cannot store in outer local which are final locations) codeStream.store(localBinding, valueRequired); if ((this.bits & ASTNode.FirstAssignmentToLocal) != 0) { // for local variable debug attributes localBinding.recordInitializationStartPC(codeStream.position); } // implicit conversion if (valueRequired) { codeStream.generateImplicitConversion(assignment.implicitConversion); } } }
Example 14
Source File: CodeSnippetParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected NameReference getUnspecifiedReferenceOptimized() { /* build a (unspecified) NameReference which may be qualified The optimization occurs for qualified reference while we are certain in this case the last item of the qualified name is a field access. This optimization is IMPORTANT while it results that when a NameReference is build, the type checker should always look for that it is not a type reference */ consumeNonTypeUseName(); if (this.scanner.startPosition >= this.codeSnippetStart && this.scanner.startPosition <= this.codeSnippetEnd+1+this.lineSeparatorLength /*14838*/){ int length; NameReference ref; if ((length = this.identifierLengthStack[this.identifierLengthPtr--]) == 1) { // single variable reference ref = new CodeSnippetSingleNameReference( this.identifierStack[this.identifierPtr], this.identifierPositionStack[this.identifierPtr--], this.evaluationContext); ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.LOCAL | Binding.FIELD; return ref; } //Qualified-variable-reference //In fact it is variable-reference DOT field-ref , but it would result in a type //conflict tha can be only reduce by making a superclass (or inetrface ) between //nameReference and FiledReference or putting FieldReference under NameReference //or else..........This optimisation is not really relevant so just leave as it is char[][] tokens = new char[length][]; this.identifierPtr -= length; System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); long[] positions = new long[length]; System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); ref = new CodeSnippetQualifiedNameReference( tokens, positions, (int) (this.identifierPositionStack[this.identifierPtr + 1] >> 32), // sourceStart (int) this.identifierPositionStack[this.identifierPtr + length], this.evaluationContext); // sourceEnd ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.LOCAL | Binding.FIELD; return ref; } else { return super.getUnspecifiedReferenceOptimized(); } }
Example 15
Source File: CodeSnippetSingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { switch (this.bits & RestrictiveFlagMASK) { case Binding.FIELD : // assigning to a field FieldBinding codegenField = ((FieldBinding) this.binding).original(); if (codegenField.canBeSeenBy(getReceiverType(currentScope), this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); } else { if (codegenField.isStatic()) { codeStream.aconst_null(); } else { if ((this.bits & DepthMASK) != 0) { // internal error, per construction we should have found it // not yet supported currentScope.problemReporter().needImplementation(this); } else { generateReceiver(codeStream); } } codeStream.generateEmulatedReadAccessForField(codegenField); if (valueRequired) { switch (codegenField.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2(); break; default: codeStream.dup(); break; } } codeStream.generateEmulationForField(codegenField); switch (codegenField.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup_x2(); codeStream.pop(); if (codegenField.isStatic()) { codeStream.aconst_null(); } else { generateReceiver(codeStream); } codeStream.dup_x2(); codeStream.pop(); break; default: codeStream.dup_x1(); codeStream.pop(); if (codegenField.isStatic()) { codeStream.aconst_null(); } else { generateReceiver(codeStream); } codeStream.dup_x1(); codeStream.pop(); break; } codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, codegenField.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(codegenField); } return; case Binding.LOCAL : // assigning to a local variable super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); } }
Example 16
Source File: CodeSnippetSingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; if (this.constant != Constant.NotAConstant) { if (valueRequired) { codeStream.generateConstant(this.constant, this.implicitConversion); } } else { switch (this.bits & RestrictiveFlagMASK) { case Binding.FIELD : // reading a field if (!valueRequired) break; FieldBinding codegenField = ((FieldBinding) this.binding).original(); Constant fieldConstant = codegenField.constant(); if (fieldConstant == Constant.NotAConstant) { // directly use inlined value for constant fields if (codegenField.canBeSeenBy(getReceiverType(currentScope), this, currentScope)) { TypeBinding someReceiverType = this.delegateThis != null ? this.delegateThis.type : this.actualReceiverType; TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, someReceiverType, true /* implicit this */); if (codegenField.isStatic()) { codeStream.fieldAccess(Opcodes.OPC_getstatic, codegenField, constantPoolDeclaringClass); } else { if ((this.bits & DepthMASK) != 0) { ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & DepthMASK) >> DepthSHIFT); Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/); codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope); } else { generateReceiver(codeStream); } codeStream.fieldAccess(Opcodes.OPC_getfield, codegenField, constantPoolDeclaringClass); } } else { // managing private access if (!codegenField.isStatic()) { if ((this.bits & DepthMASK) != 0) { // internal error, per construction we should have found it // not yet supported currentScope.problemReporter().needImplementation(this); } else { generateReceiver(codeStream); } } else { codeStream.aconst_null(); } codeStream.generateEmulatedReadAccessForField(codegenField); } if (this.genericCast != null) codeStream.checkcast(this.genericCast); codeStream.generateImplicitConversion(this.implicitConversion); } else { // directly use the inlined value codeStream.generateConstant(fieldConstant, this.implicitConversion); } break; case Binding.LOCAL : // reading a local LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; if (localBinding.resolvedPosition == -1) { if (valueRequired) { // restart code gen localBinding.useFlag = LocalVariableBinding.USED; throw new AbortMethod(CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE, null); } codeStream.recordPositionsFrom(pc, this.sourceStart); return; } if (!valueRequired) break; // outer local? if ((this.bits & IsCapturedOuterLocal) != 0) { checkEffectiveFinality(localBinding, currentScope); // outer local can be reached either through a synthetic arg or a synthetic field VariableBinding[] path = currentScope.getEmulationPath(localBinding); codeStream.generateOuterAccess(path, this, localBinding, currentScope); } else { // regular local variable read codeStream.load(localBinding); } codeStream.generateImplicitConversion(this.implicitConversion); break; } } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 17
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { // determine the rank until which we now we do not need any actual value for the field access int otherBindingsCount = this.otherBindings == null ? 0 : this.otherBindings.length; boolean needValue = otherBindingsCount == 0 ? valueRequired : !this.otherBindings[0].isStatic(); boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4; switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field if (needValue || complyTo14) { manageSyntheticAccessIfNecessary(currentScope, (FieldBinding) this.binding, 0, flowInfo); } FieldBinding fieldBinding = (FieldBinding) this.binding; if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding // check if reading a final blank field if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) { FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo); if (!fieldInits.isDefinitelyAssigned(fieldBinding)) { currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this); } } } break; case Binding.LOCAL : // reading a local variable LocalVariableBinding localBinding; if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) { currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { localBinding.useFlag = LocalVariableBinding.USED; } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { localBinding.useFlag = LocalVariableBinding.FAKE_USED; } } if (needValue) { checkInternalNPE(currentScope, flowContext, flowInfo, true); } if (needValue) { manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo); // only for first binding (if value needed only) } if (this.otherBindings != null) { for (int i = 0; i < otherBindingsCount; i++) { needValue = i < otherBindingsCount-1 ? !this.otherBindings[i+1].isStatic() : valueRequired; if (needValue || complyTo14) { manageSyntheticAccessIfNecessary(currentScope, this.otherBindings[i], i + 1, flowInfo); } } } return flowInfo; }
Example 18
Source File: AssistParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected NameReference getUnspecifiedReferenceOptimized() { int completionIndex; /* no need to take action if not inside completed identifiers */ if ((completionIndex = indexOfAssistIdentifier()) < 0) { return super.getUnspecifiedReferenceOptimized(); } consumeNonTypeUseName(); /* retrieve identifiers subset and whole positions, the completion node positions should include the entire replaced source. */ int length = this.identifierLengthStack[this.identifierLengthPtr]; char[][] subset = identifierSubSet(completionIndex); this.identifierLengthPtr--; this.identifierPtr -= length; long[] positions = new long[length]; System.arraycopy( this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); /* build specific completion on name reference */ NameReference reference; if (completionIndex == 0) { /* completion inside first identifier */ reference = createSingleAssistNameReference(assistIdentifier(), positions[0]); } else { /* completion inside subsequent identifier */ reference = createQualifiedAssistNameReference(subset, assistIdentifier(), positions); } reference.bits &= ~ASTNode.RestrictiveFlagMASK; reference.bits |= Binding.LOCAL | Binding.FIELD; this.assistNode = reference; this.lastCheckPoint = reference.sourceEnd + 1; return reference; }
Example 19
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Given a binding of uncertain type, try to create the right sort of TypeMirror for it. */ public TypeMirror newTypeMirror(Binding binding) { switch (binding.kind()) { case Binding.FIELD: case Binding.LOCAL: case Binding.VARIABLE: // For variables, return the type of the variable return newTypeMirror(((VariableBinding)binding).type); case Binding.PACKAGE: return getNoType(TypeKind.PACKAGE); case Binding.IMPORT: throw new UnsupportedOperationException("NYI: import type " + binding.kind()); //$NON-NLS-1$ case Binding.METHOD: return new ExecutableTypeImpl(_env, (MethodBinding) binding); case Binding.TYPE: case Binding.RAW_TYPE: case Binding.GENERIC_TYPE: case Binding.PARAMETERIZED_TYPE: ReferenceBinding referenceBinding = (ReferenceBinding) binding; if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) { return getErrorType(referenceBinding); } return new DeclaredTypeImpl(_env, (ReferenceBinding)binding); case Binding.ARRAY_TYPE: return new ArrayTypeImpl(_env, (ArrayBinding)binding); case Binding.BASE_TYPE: BaseTypeBinding btb = (BaseTypeBinding)binding; switch (btb.id) { case TypeIds.T_void: return getNoType(TypeKind.VOID); case TypeIds.T_null: return getNullType(); default: return getPrimitiveType(btb); } case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: // TODO compatible, but shouldn't it really be an intersection type? return new WildcardTypeImpl(_env, (WildcardBinding) binding); case Binding.TYPE_PARAMETER: return new TypeVariableImpl(_env, (TypeVariableBinding) binding); } return null; }