@Override public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) { Set<? extends Element> fields = roundEnv.getElementsAnnotatedWith(Multiline.class); for (Element field : fields) { String docComment = elementUtils.getDocComment(field); if (null != docComment) { VariableElementImpl fieldElem = (VariableElementImpl) field; FieldBinding biding = (FieldBinding) fieldElem._binding; FieldDeclaration decl = biding.sourceField(); StringLiteral string = new StringLiteral(docComment.toCharArray(), decl.sourceStart ,decl.sourceEnd, decl.sourceStart); decl.initialization = string; } } return true; } }
@Override public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) { Set<? extends Element> fields = roundEnv.getElementsAnnotatedWith(Multiline.class); for (Element field : fields) { String docComment = elementUtils.getDocComment(field); if (null != docComment) { VariableElementImpl fieldElem = (VariableElementImpl) field; FieldBinding biding = (FieldBinding) fieldElem._binding; FieldDeclaration decl = biding.sourceField(); StringLiteral string = new StringLiteral(docComment.toCharArray(), decl.sourceStart, decl.sourceEnd, decl.sourceStart); decl.initialization = string; } } return true; } }
protected int getSourcePosition(FieldBinding fb) { FieldBinding fieldBinding = SpiWithJdtUtils.nvl(fb.original(), fb); if (fieldBinding == null) { return UNKNOWN_SOURCE_POS; } FieldDeclaration decl = fieldBinding.sourceField(); if (decl == null) { return UNKNOWN_SOURCE_POS; } return decl.declarationSourceStart; } }
@Override public ISourceRange getSource() { if (m_source == null) { FieldDeclaration decl = m_binding.sourceField(); if (decl != null) { CompilationUnitSpi cu = m_declaringType.getCompilationUnit(); m_source = m_env.getSource(cu, decl.declarationSourceStart, decl.declarationSourceEnd); } else { m_source = ISourceRange.NO_SOURCE; } } return m_source; }
@Override public ISourceRange getJavaDoc() { if (m_javaDocSource == null) { FieldDeclaration decl = m_binding.sourceField(); if (decl != null) { Javadoc doc = decl.javadoc; if (doc != null) { CompilationUnitSpi cu = m_declaringType.getCompilationUnit(); m_javaDocSource = m_env.getSource(cu, doc.sourceStart, doc.sourceEnd); } } if (m_javaDocSource == null) { m_javaDocSource = ISourceRange.NO_SOURCE; } } return m_javaDocSource; }
@Override public ISourceRange getSourceOfInitializer() { if (m_initializerSource == null) { FieldDeclaration decl = m_binding.sourceField(); if (decl != null) { Expression expr = decl.initialization; if (expr != null) { CompilationUnitSpi cu = m_declaringType.getCompilationUnit(); m_initializerSource = m_env.getSource(cu, expr.sourceStart, expr.sourceEnd); } } if (m_initializerSource == null) { m_initializerSource = ISourceRange.NO_SOURCE; } } return m_initializerSource; }
public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) { if (type.isEnum() && type.isLocalType()) { FieldBinding field = type.scope.enclosingMethodScope().initializedField; FieldDeclaration decl = field.sourceField(); String[] arguments = new String[] {new String(decl.name), new String(methodDecl.selector)}; this.handle( IProblem.AbstractMethodInEnum, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd); } else { String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; this.handle( IProblem.AbstractMethodInAbstractClass, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd); } } public void abstractMethodInConcreteClass(SourceTypeBinding type) {
public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) { if (type.isEnum() && type.isLocalType()) { FieldBinding field = type.scope.enclosingMethodScope().initializedField; FieldDeclaration decl = field.sourceField(); String[] arguments = new String[] {new String(decl.name), new String(methodDecl.selector)}; this.handle( IProblem.AbstractMethodInEnum, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd); } else { String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; this.handle( IProblem.AbstractMethodInAbstractClass, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd); } } public void abstractMethodInConcreteClass(SourceTypeBinding type) {
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again } } } } /* report a local/arg that is only read from a 'special operator',
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) { if (valueRequired) { // access is relevant, turn compound use into real use: fieldBinding.compoundUseFlag = 0; fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } else { if (fieldBinding.isUsedOnlyInCompound()) { fieldBinding.compoundUseFlag--; // consume one if (fieldBinding.compoundUseFlag == 0 // report only the last usage && fieldBinding.isOrEnclosedByPrivateType() && (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE) { // compoundAssignment/postIncrement is the only usage of this field currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); } } } } /* report a local/arg that is only read from a 'special operator',
public void abstractMethodInConcreteClass(SourceTypeBinding type) { if (type.isEnum() && type.isLocalType()) { FieldBinding field = type.scope.enclosingMethodScope().initializedField; FieldDeclaration decl = field.sourceField(); String[] arguments = new String[] {new String(decl.name)}; this.handle( IProblem.EnumConstantCannotDefineAbstractMethod, arguments, arguments, decl.sourceStart(), decl.sourceEnd()); } else { String[] arguments = new String[] {new String(type.sourceName())}; this.handle( IProblem.AbstractMethodsInConcreteClass, arguments, arguments, type.sourceStart(), type.sourceEnd()); } } public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
public void abstractMethodInConcreteClass(SourceTypeBinding type) { if (type.isEnum() && type.isLocalType()) { FieldBinding field = type.scope.enclosingMethodScope().initializedField; FieldDeclaration decl = field.sourceField(); String[] arguments = new String[] {new String(decl.name)}; this.handle( IProblem.EnumConstantCannotDefineAbstractMethod, arguments, arguments, decl.sourceStart(), decl.sourceEnd()); } else { String[] arguments = new String[] {new String(type.sourceName())}; this.handle( IProblem.AbstractMethodsInConcreteClass, arguments, arguments, type.sourceStart(), type.sourceEnd()); } } public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
public void abstractMethodInConcreteClass(SourceTypeBinding type) { if (type.isEnum() && type.isLocalType()) { FieldBinding field = type.scope.enclosingMethodScope().initializedField; FieldDeclaration decl = field.sourceField(); String[] arguments = new String[] {new String(decl.name)}; this.handle( IProblem.EnumConstantCannotDefineAbstractMethod, arguments, arguments, decl.sourceStart(), decl.sourceEnd()); } else { String[] arguments = new String[] {new String(type.sourceName())}; this.handle( IProblem.AbstractMethodsInConcreteClass, arguments, arguments, type.sourceStart(), type.sourceEnd()); } } public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {