org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration Java Examples
The following examples show how to use
org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration.
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: DefaultBindingResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
synchronized IVariableBinding resolveVariable(VariableDeclaration variable) { final Object node = this.newAstToOldAst.get(variable); if (node instanceof AbstractVariableDeclaration) { AbstractVariableDeclaration abstractVariableDeclaration = (AbstractVariableDeclaration) node; IVariableBinding variableBinding = null; if (abstractVariableDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) abstractVariableDeclaration; variableBinding = this.getVariableBinding(fieldDeclaration.binding, variable); } else { variableBinding = this.getVariableBinding(((LocalDeclaration) abstractVariableDeclaration).binding, variable); } if (variableBinding == null) { return null; } this.bindingsToAstNodes.put(variableBinding, variable); String key = variableBinding.getKey(); if (key != null) { this.bindingTables.bindingKeysToBindings.put(key, variableBinding); } return variableBinding; } return null; }
Example #2
Source File: RecoveredField.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){ if (this.bracketBalance > 0){ // was an array initializer this.bracketBalance--; if (this.bracketBalance == 0) { if(this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { updateSourceEndIfNecessary(braceEnd - 1); return this.parent; } else { if (this.fieldDeclaration.declarationSourceEnd > 0) this.alreadyCompletedFieldInitialization = true; } } return this; } else if (this.bracketBalance == 0) { this.alreadyCompletedFieldInitialization = true; updateSourceEndIfNecessary(braceEnd - 1); } if (this.parent != null){ return this.parent.updateOnClosingBrace(braceStart, braceEnd); } return this; }
Example #3
Source File: RecoveredField.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){ if (this.fieldDeclaration.declarationSourceEnd == 0) { if (this.fieldDeclaration.type instanceof ArrayTypeReference || this.fieldDeclaration.type instanceof ArrayQualifiedTypeReference) { if (!this.alreadyCompletedFieldInitialization) { this.bracketBalance++; return null; // no update is necessary (array initializer) } } else { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980 // in case an initializer bracket is opened in a non-array field // e.g. int field = {.. this.bracketBalance++; return null; // no update is necessary (array initializer) } } if (this.fieldDeclaration.declarationSourceEnd == 0 && this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT){ this.bracketBalance++; return null; // no update is necessary (enum constant) } // might be an array initializer this.updateSourceEndIfNecessary(braceStart - 1, braceEnd - 1); return this.parent.updateOnOpeningBrace(braceStart, braceEnd); }
Example #4
Source File: SetGeneratedByVisitor.java From EasyMPermission with MIT License | 5 votes |
private void fixPositions(AbstractVariableDeclaration node) { node.sourceEnd = sourceEnd; node.sourceStart = sourceStart; node.declarationEnd = sourceEnd; node.declarationSourceEnd = sourceEnd; node.declarationSourceStart = sourceStart; node.modifiersSourceStart = sourceStart; }
Example #5
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private JavaElement getJavaElement(LocalVariableBinding binding) { LocalDeclaration local = binding.declaration; JavaElement parent = null; ReferenceContext referenceContext = binding.declaringScope.referenceContext(); if (referenceContext instanceof AbstractMethodDeclaration) { AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext; parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding); } else if (referenceContext instanceof TypeDeclaration){ // Local variable is declared inside an initializer TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding); parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type); } if (parent == null) return null; return new LocalVariable( parent, new String(local.name), local.declarationSourceStart, local.declarationSourceEnd, local.sourceStart, local.sourceEnd, Util.typeSignature(local.type), binding.declaration.annotations, local.modifiers, local.getKind() == AbstractVariableDeclaration.PARAMETER); }
Example #6
Source File: SelectionParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void consumeEnterVariable() { // EnterVariable ::= $empty // do nothing by default super.consumeEnterVariable(); AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; if (variable.type == this.assistNode){ if (!this.diet){ this.restartRecovery = true; // force to restart in recovery mode this.lastIgnoredToken = -1; } this.isOrphanCompletionNode = false; // already attached inside variable decl } }
Example #7
Source File: SelectionParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void consumeExitVariableWithInitialization() { super.consumeExitVariableWithInitialization(); // does not keep the initialization if selection is not inside AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; int start = variable.initialization.sourceStart; int end = variable.initialization.sourceEnd; if ((this.selectionStart < start) && (this.selectionEnd < start) || (this.selectionStart > end) && (this.selectionEnd > end)) { variable.initialization = null; } triggerRecoveryUponLambdaClosure(variable, false); }
Example #8
Source File: SelectionRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void acceptLocalVariable(LocalVariableBinding binding, org.eclipse.jdt.internal.compiler.env.ICompilationUnit unit) { LocalDeclaration local = binding.declaration; IJavaElement parent = null; if (binding.declaringScope.isLambdaSubscope() && unit instanceof ICompilationUnit) { HashSet existingElements = new HashSet(); HashMap knownScopes = new HashMap(); parent = this.handleFactory.createElement(binding.declaringScope, local.sourceStart, (ICompilationUnit) unit, existingElements, knownScopes); } else { parent = findLocalElement(local.sourceStart, binding.declaringScope.methodScope()); // findLocalElement() cannot find local variable } LocalVariable localVar = null; if(parent != null) { localVar = new LocalVariable( (JavaElement)parent, new String(local.name), local.declarationSourceStart, local.declarationSourceEnd, local.sourceStart, local.sourceEnd, local.type == null ? Signature.createTypeSignature(binding.type.readableName(), true) : Util.typeSignature(local.type), local.annotations, local.modifiers, local.getKind() == AbstractVariableDeclaration.PARAMETER); } if (localVar != null) { addElement(localVar); if(SelectionEngine.DEBUG){ System.out.print("SELECTION - accept local variable("); //$NON-NLS-1$ System.out.print(localVar.toString()); System.out.println(")"); //$NON-NLS-1$ } } }
Example #9
Source File: DefaultBindingResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
Example #10
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override @Nullable public ResolvedNode resolve(@NonNull JavaContext context, @NonNull Node node) { Object nativeNode = getNativeNode(node); if (nativeNode == null) { return null; } if (nativeNode instanceof NameReference) { return resolve(((NameReference) nativeNode).binding); } else if (nativeNode instanceof TypeReference) { return resolve(((TypeReference) nativeNode).resolvedType); } else if (nativeNode instanceof MessageSend) { return resolve(((MessageSend) nativeNode).binding); } else if (nativeNode instanceof AllocationExpression) { return resolve(((AllocationExpression) nativeNode).binding); } else if (nativeNode instanceof TypeDeclaration) { return resolve(((TypeDeclaration) nativeNode).binding); } else if (nativeNode instanceof ExplicitConstructorCall) { return resolve(((ExplicitConstructorCall) nativeNode).binding); } else if (nativeNode instanceof Annotation) { AnnotationBinding compilerAnnotation = ((Annotation) nativeNode).getCompilerAnnotation(); if (compilerAnnotation != null) { return new EcjResolvedAnnotation(compilerAnnotation); } return resolve(((Annotation) nativeNode).resolvedType); } else if (nativeNode instanceof AbstractMethodDeclaration) { return resolve(((AbstractMethodDeclaration) nativeNode).binding); } else if (nativeNode instanceof AbstractVariableDeclaration) { if (nativeNode instanceof LocalDeclaration) { return resolve(((LocalDeclaration) nativeNode).binding); } else if (nativeNode instanceof FieldDeclaration) { FieldDeclaration fieldDeclaration = (FieldDeclaration) nativeNode; if (fieldDeclaration.initialization instanceof AllocationExpression) { AllocationExpression allocation = (AllocationExpression)fieldDeclaration.initialization; if (allocation.binding != null) { // Field constructor call: this is an enum constant. return new EcjResolvedMethod(allocation.binding); } } return resolve(fieldDeclaration.binding); } } // TODO: Handle org.eclipse.jdt.internal.compiler.ast.SuperReference. It // doesn't contain an actual method binding; the parent node call should contain // it, but is missing a native node reference; investigate the ECJ bridge's super // handling. return null; }
Example #11
Source File: EclipseHandlerUtil.java From EasyMPermission with MIT License | 4 votes |
/** * Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the * variable name as message. * * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}. */ public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) { NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE); if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION; ASTNode source = sourceNode.get(); int pS = source.sourceStart, pE = source.sourceEnd; long p = (long)pS << 32 | pE; if (isPrimitive(variable.type)) return null; AllocationExpression exception = new AllocationExpression(); setGeneratedBy(exception, source); int partCount = 1; String exceptionTypeStr = exceptionType.getExceptionType(); for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++; long[] ps = new long[partCount]; Arrays.fill(ps, 0L); exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps); setGeneratedBy(exception.type, source); exception.arguments = new Expression[] { new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0) }; setGeneratedBy(exception.arguments[0], source); ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE); setGeneratedBy(throwStatement, source); SingleNameReference varName = new SingleNameReference(variable.name, p); setGeneratedBy(varName, source); NullLiteral nullLiteral = new NullLiteral(pS, pE); setGeneratedBy(nullLiteral, source); EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL); equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE; setGeneratedBy(equalExpression, source); Block throwBlock = new Block(0); throwBlock.statements = new Statement[] {throwStatement}; throwBlock.sourceStart = pS; throwBlock.sourceEnd = pE; setGeneratedBy(throwBlock, source); IfStatement ifStatement = new IfStatement(equalExpression, throwBlock, 0, 0); setGeneratedBy(ifStatement, source); return ifStatement; }
Example #12
Source File: HandleBuilder.java From EasyMPermission with MIT License | 4 votes |
/** * Returns the explicitly requested singular annotation on this node (field * or parameter), or null if there's no {@code @Singular} annotation on it. * * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. */ private SingularData getSingularData(EclipseNode node, ASTNode source) { for (EclipseNode child : node.down()) { if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Singular.class, child)) { char[] pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((AbstractVariableDeclaration) node.get()).name; AnnotationValues<Singular> ann = createAnnotation(Singular.class, child); String explicitSingular = ann.getInstance().value(); if (explicitSingular.isEmpty()) { if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_AUTO))) { node.addError("The singular must be specified explicitly (e.g. @Singular(\"task\")) because auto singularization is disabled."); explicitSingular = new String(pluralName); } else { explicitSingular = autoSingularize(node.getName()); if (explicitSingular == null) { node.addError("Can't singularize this name; please specify the singular explicitly (i.e. @Singular(\"sheep\"))"); explicitSingular = new String(pluralName); } } } char[] singularName = explicitSingular.toCharArray(); TypeReference type = ((AbstractVariableDeclaration) node.get()).type; TypeReference[] typeArgs = null; String typeName; if (type instanceof ParameterizedSingleTypeReference) { typeArgs = ((ParameterizedSingleTypeReference) type).typeArguments; typeName = new String(((ParameterizedSingleTypeReference) type).token); } else if (type instanceof ParameterizedQualifiedTypeReference) { TypeReference[][] tr = ((ParameterizedQualifiedTypeReference) type).typeArguments; if (tr != null) typeArgs = tr[tr.length - 1]; char[][] tokens = ((ParameterizedQualifiedTypeReference) type).tokens; StringBuilder sb = new StringBuilder(); for (int i = 0; i < tokens.length; i++) { if (i > 0) sb.append("."); sb.append(tokens[i]); } typeName = sb.toString(); } else { typeName = type.toString(); } String targetFqn = EclipseSingularsRecipes.get().toQualified(typeName); EclipseSingularizer singularizer = EclipseSingularsRecipes.get().getSingularizer(targetFqn); if (singularizer == null) { node.addError("Lombok does not know how to create the singular-form builder methods for type '" + typeName + "'; they won't be generated."); return null; } return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.<TypeReference>emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source); } } return null; }
Example #13
Source File: AssistParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected boolean triggerRecoveryUponLambdaClosure(Statement statement, boolean shouldCommit) { // Last block statement reduced is required to be on the AST stack top. boolean lambdaClosed = false; int statementStart, statementEnd; statementStart = statement.sourceStart; statementEnd = statement instanceof AbstractVariableDeclaration ? ((AbstractVariableDeclaration)statement).declarationSourceEnd : statement.sourceEnd; for (int i = this.elementPtr; i >= 0; --i) { if (this.elementKindStack[i] != K_LAMBDA_EXPRESSION_DELIMITER) continue; LambdaExpression expression = (LambdaExpression) this.elementObjectInfoStack[i]; if (expression.sourceStart >= statementStart && expression.sourceEnd <= statementEnd) { this.elementPtr = i - 1; lambdaClosed = true; } else { if (shouldCommit) { int stackLength = this.stack.length; if (++this.stateStackTop >= stackLength) { System.arraycopy( this.stack, 0, this.stack = new int[stackLength + StackIncrement], 0, stackLength); } this.stack[this.stateStackTop] = this.unstackedAct; commit(); this.stateStackTop --; } return false; } } if (lambdaClosed && this.currentElement != null) { this.restartRecovery = true; if (!(statement instanceof AbstractVariableDeclaration)) { // added already as part of standard recovery since these contribute a name to the scope prevailing at the cursor. /* See if CompletionParser.attachOrphanCompletionNode has already added bits and pieces of AST to the recovery tree. If so, we want to replace those fragments with the fuller statement that provides target type for the lambda that got closed just now. There is prior art/precedent in the Java 7 world to this: Search for recoveredBlock.statements[--recoveredBlock.statementCount] = null; See also that this concern does not arise in the case of field/local initialization since the initializer is replaced with full tree by consumeExitVariableWithInitialization. */ ASTNode assistNodeParent = this.assistNodeParent(); ASTNode enclosingNode = this.enclosingNode(); if (assistNodeParent != null || enclosingNode != null) { RecoveredBlock recoveredBlock = (RecoveredBlock) (this.currentElement instanceof RecoveredBlock ? this.currentElement : (this.currentElement.parent instanceof RecoveredBlock) ? this.currentElement.parent : null); if (recoveredBlock != null) { RecoveredStatement recoveredStatement = recoveredBlock.statementCount > 0 ? recoveredBlock.statements[recoveredBlock.statementCount - 1] : null; ASTNode parseTree = recoveredStatement != null ? recoveredStatement.updatedStatement(0, new HashSet()) : null; if (parseTree != null && (parseTree == assistNodeParent || parseTree == enclosingNode)) { recoveredBlock.statements[--recoveredBlock.statementCount] = null; this.currentElement = recoveredBlock; } } } this.currentElement.add(statement, 0); } } this.snapShot = null; return lambdaClosed; }
Example #14
Source File: SourceElementNotifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected void notifySourceElementRequestor(FieldDeclaration fieldDeclaration, TypeDeclaration declaringType) { // range check boolean isInRange = this.initialPosition <= fieldDeclaration.declarationSourceStart && this.eofPosition >= fieldDeclaration.declarationSourceEnd; switch(fieldDeclaration.getKind()) { case AbstractVariableDeclaration.ENUM_CONSTANT: if (this.reportReferenceInfo) { // accept constructor reference for enum constant if (fieldDeclaration.initialization instanceof AllocationExpression) { AllocationExpression alloc = (AllocationExpression) fieldDeclaration.initialization; this.requestor.acceptConstructorReference( declaringType.name, alloc.arguments == null ? 0 : alloc.arguments.length, alloc.sourceStart); } } // $FALL-THROUGH$ case AbstractVariableDeclaration.FIELD: int fieldEndPosition = this.sourceEnds.get(fieldDeclaration); if (fieldEndPosition == -1) { // use the declaration source end by default fieldEndPosition = fieldDeclaration.declarationSourceEnd; } if (isInRange) { int currentModifiers = fieldDeclaration.modifiers; // remember deprecation so as to not lose it below boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(fieldDeclaration.annotations); char[] typeName = null; if (fieldDeclaration.type == null) { // enum constant typeName = declaringType.name; currentModifiers |= ClassFileConstants.AccEnum; } else { // regular field typeName = CharOperation.concatWith(fieldDeclaration.type.getParameterizedTypeName(), '.'); } ISourceElementRequestor.FieldInfo fieldInfo = new ISourceElementRequestor.FieldInfo(); fieldInfo.typeAnnotated = ((fieldDeclaration.bits & ASTNode.HasTypeAnnotations) != 0); fieldInfo.declarationStart = fieldDeclaration.declarationSourceStart; fieldInfo.name = fieldDeclaration.name; fieldInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag; fieldInfo.type = typeName; fieldInfo.nameSourceStart = fieldDeclaration.sourceStart; fieldInfo.nameSourceEnd = fieldDeclaration.sourceEnd; fieldInfo.categories = (char[][]) this.nodesToCategories.get(fieldDeclaration); fieldInfo.annotations = fieldDeclaration.annotations; fieldInfo.node = fieldDeclaration; this.requestor.enterField(fieldInfo); } this.visitIfNeeded(fieldDeclaration, declaringType); if (isInRange){ this.requestor.exitField( // filter out initializations that are not a constant (simple check) (fieldDeclaration.initialization == null || fieldDeclaration.initialization instanceof ArrayInitializer || fieldDeclaration.initialization instanceof AllocationExpression || fieldDeclaration.initialization instanceof ArrayAllocationExpression || fieldDeclaration.initialization instanceof Assignment || fieldDeclaration.initialization instanceof ClassLiteralAccess || fieldDeclaration.initialization instanceof MessageSend || fieldDeclaration.initialization instanceof ArrayReference || fieldDeclaration.initialization instanceof ThisReference) ? -1 : fieldDeclaration.initialization.sourceStart, fieldEndPosition, fieldDeclaration.declarationSourceEnd); } break; case AbstractVariableDeclaration.INITIALIZER: if (isInRange){ this.requestor.enterInitializer( fieldDeclaration.declarationSourceStart, fieldDeclaration.modifiers); } this.visitIfNeeded((Initializer)fieldDeclaration); if (isInRange){ this.requestor.exitInitializer(fieldDeclaration.declarationSourceEnd); } break; } }
Example #15
Source File: RecoveredType.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) { this.pendingTypeParameters = null; /* do not consider a field starting passed the type end (if set) it must be belonging to an enclosing type */ if (this.typeDeclaration.declarationSourceEnd != 0 && fieldDeclaration.declarationSourceStart > this.typeDeclaration.declarationSourceEnd) { resetPendingModifiers(); return this.parent.add(fieldDeclaration, bracketBalanceValue); } if (this.fields == null) { this.fields = new RecoveredField[5]; this.fieldCount = 0; } else { if (this.fieldCount == this.fields.length) { System.arraycopy( this.fields, 0, (this.fields = new RecoveredField[2 * this.fieldCount]), 0, this.fieldCount); } } RecoveredField element; switch (fieldDeclaration.getKind()) { case AbstractVariableDeclaration.FIELD: case AbstractVariableDeclaration.ENUM_CONSTANT: element = new RecoveredField(fieldDeclaration, this, bracketBalanceValue); break; case AbstractVariableDeclaration.INITIALIZER: element = new RecoveredInitializer(fieldDeclaration, this, bracketBalanceValue); break; default: // never happens, as field is always identified return this; } this.fields[this.fieldCount++] = element; if(this.pendingAnnotationCount > 0) { element.attach( this.pendingAnnotations, this.pendingAnnotationCount, this.pendingModifiers, this.pendingModifersSourceStart); } resetPendingModifiers(); /* consider that if the opening brace was not found, it is there */ if (!this.foundOpeningBrace){ this.foundOpeningBrace = true; this.bracketBalance++; } /* if field not finished, then field becomes current */ if (fieldDeclaration.declarationSourceEnd == 0) return element; return this; }
Example #16
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public FieldBinding resolveTypeFor(FieldBinding field) { if (!isPrototype()) return this.prototype.resolveTypeFor(field); if ((field.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0) return field; long sourceLevel = this.scope.compilerOptions().sourceLevel; if (sourceLevel >= ClassFileConstants.JDK1_5) { if ((field.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0) field.modifiers |= ClassFileConstants.AccDeprecated; } if (isViewedAsDeprecated() && !field.isDeprecated()) field.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; if (hasRestrictedAccess()) field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess; FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields; int length = fieldDecls == null ? 0 : fieldDecls.length; for (int f = 0; f < length; f++) { if (fieldDecls[f].binding != field) continue; MethodScope initializationScope = field.isStatic() ? this.scope.referenceContext.staticInitializerScope : this.scope.referenceContext.initializerScope; FieldBinding previousField = initializationScope.initializedField; try { initializationScope.initializedField = field; FieldDeclaration fieldDecl = fieldDecls[f]; TypeBinding fieldType = fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT ? initializationScope.environment().convertToRawType(this, false /*do not force conversion of enclosing types*/) // enum constant is implicitly of declaring enum type : fieldDecl.type.resolveType(initializationScope, true /* check bounds*/); field.type = fieldType; field.modifiers &= ~ExtraCompilerModifiers.AccUnresolved; if (fieldType == null) { fieldDecl.binding = null; return null; } if (fieldType == TypeBinding.VOID) { this.scope.problemReporter().variableTypeCannotBeVoid(fieldDecl); fieldDecl.binding = null; return null; } if (fieldType.isArrayType() && ((ArrayBinding) fieldType).leafComponentType == TypeBinding.VOID) { this.scope.problemReporter().variableTypeCannotBeVoidArray(fieldDecl); fieldDecl.binding = null; return null; } if ((fieldType.tagBits & TagBits.HasMissingType) != 0) { field.tagBits |= TagBits.HasMissingType; } TypeBinding leafType = fieldType.leafComponentType(); if (leafType instanceof ReferenceBinding && (((ReferenceBinding)leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) { field.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } if (sourceLevel >= ClassFileConstants.JDK1_8) { Annotation [] annotations = fieldDecl.annotations; if (annotations != null && annotations.length != 0) { ASTNode.copySE8AnnotationsToType(initializationScope, field, annotations, fieldDecl.getKind() != AbstractVariableDeclaration.ENUM_CONSTANT); // type annotation is illegal on enum constant } Annotation.isTypeUseCompatible(fieldDecl.type, this.scope, annotations); } // apply null default: if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) { // TODO(SH): different strategy for 1.8, or is "repair" below enough? if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { // enum constants neither have a type declaration nor can they be null field.tagBits |= TagBits.AnnotationNonNull; } else { if (hasNonNullDefaultFor(DefaultLocationField, sourceLevel >= ClassFileConstants.JDK1_8)) { field.fillInDefaultNonNullness(fieldDecl, initializationScope); } // validate null annotation: if (!this.scope.validateNullAnnotation(field.tagBits, fieldDecl.type, fieldDecl.annotations)) field.tagBits &= ~TagBits.AnnotationNullMASK; } } } finally { initializationScope.initializedField = previousField; } return field; } return null; // should never reach this point }