Java Code Examples for org.eclipse.jdt.internal.compiler.ast.FieldDeclaration#getKind()
The following examples show how to use
org.eclipse.jdt.internal.compiler.ast.FieldDeclaration#getKind() .
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: 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 2
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 3
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 }