use of org.eclipse.jdt.core.dom.IExtendedModifier in project lombok by rzwitserloot.
the class PatchValEclipse method addFinalAndValAnnotationToModifierList.
public static void addFinalAndValAnnotationToModifierList(Object converter, List<IExtendedModifier> modifiers, AST ast, LocalDeclaration in) {
// First check that 'in' has the final flag on, and a @val / @lombok.val annotation.
if ((in.modifiers & ClassFileConstants.AccFinal) == 0)
return;
if (in.annotations == null)
return;
boolean found = false;
Annotation valAnnotation = null;
for (Annotation ann : in.annotations) {
if (couldBeVal(ann.type)) {
found = true;
valAnnotation = ann;
break;
}
}
if (!found)
return;
// This is null only if the project is 1.4 or less. Lombok doesn't work in that.
if (modifiers == null)
return;
boolean finalIsPresent = false;
boolean valIsPresent = false;
for (Object present : modifiers) {
if (present instanceof Modifier) {
ModifierKeyword keyword = ((Modifier) present).getKeyword();
if (keyword == null)
continue;
if (keyword.toFlagValue() == Modifier.FINAL)
finalIsPresent = true;
}
if (present instanceof org.eclipse.jdt.core.dom.Annotation) {
Name typeName = ((org.eclipse.jdt.core.dom.Annotation) present).getTypeName();
if (typeName != null) {
String fullyQualifiedName = typeName.getFullyQualifiedName();
if ("val".equals(fullyQualifiedName) || "lombok.val".equals(fullyQualifiedName)) {
valIsPresent = true;
}
}
}
}
if (!finalIsPresent) {
modifiers.add(createModifier(ast, ModifierKeyword.FINAL_KEYWORD, valAnnotation.sourceStart, valAnnotation.sourceEnd));
}
if (!valIsPresent) {
MarkerAnnotation newAnnotation = createValAnnotation(ast, valAnnotation, valAnnotation.sourceStart, valAnnotation.sourceEnd);
try {
Reflection.astConverterRecordNodes.invoke(converter, newAnnotation, valAnnotation);
Reflection.astConverterRecordNodes.invoke(converter, newAnnotation.getTypeName(), valAnnotation.type);
} catch (IllegalAccessException e) {
throw Lombok.sneakyThrow(e);
} catch (InvocationTargetException e) {
throw Lombok.sneakyThrow(e.getCause());
}
modifiers.add(newAnnotation);
}
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final SingleVariableDeclaration it) {
if ((((it.getParent() instanceof MethodDeclaration) || (it.getParent() instanceof CatchClause)) || (it.getParent() instanceof EnhancedForStatement))) {
final Function1<IExtendedModifier, Boolean> _function = (IExtendedModifier it_1) -> {
return Boolean.valueOf(it_1.isAnnotation());
};
this.appendModifiers(it, IterableExtensions.<IExtendedModifier>filter(Iterables.<IExtendedModifier>filter(it.modifiers(), IExtendedModifier.class), _function));
} else {
this.appendModifiers(it, it.modifiers());
}
it.getType().accept(this);
this.appendExtraDimensions(it.getExtraDimensions());
boolean _isVarargs = it.isVarargs();
if (_isVarargs) {
this.appendToBuffer("...");
}
this.appendSpaceToBuffer();
it.getName().accept(this);
Expression _initializer = it.getInitializer();
boolean _tripleNotEquals = (_initializer != null);
if (_tripleNotEquals) {
this.appendToBuffer("=");
it.getInitializer().accept(this);
}
return false;
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project AutoRefactor by JnRouvignac.
the class RemoveUselessModifiersRefactoring method removeFinalModifier.
private boolean removeFinalModifier(List<IExtendedModifier> modifiers) {
boolean result = VISIT_SUBTREE;
for (Modifier m : getModifiersOnly(modifiers)) {
if (m.isFinal()) {
ctx.getRefactorings().remove(m);
result = DO_NOT_VISIT_SUBTREE;
}
}
return result;
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project eclipse-pmd by acanda.
the class UseUtilityClassQuickFix method addFinalIfNecessary.
private void addFinalIfNecessary(final TypeDeclaration typeDeclaration, final ASTRewrite rewrite) {
@SuppressWarnings("unchecked") final List<IExtendedModifier> modifiers = typeDeclaration.modifiers();
if (!Iterables.any(modifiers, isFinal())) {
final ListRewrite modifierRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY);
final Modifier modifier = (Modifier) typeDeclaration.getAST().createInstance(Modifier.class);
modifier.setKeyword(ModifierKeyword.FINAL_KEYWORD);
modifierRewrite.insertLast(modifier, null);
}
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project eclipse-pmd by acanda.
the class SuppressWarningsQuickFix method apply.
@Override
protected boolean apply(final ASTNode node) {
final ASTNode annotatableNode = findAnnotatableASTNode(node);
if (annotatableNode != null) {
final AST ast = node.getAST();
final List<IExtendedModifier> modifiers = getModifiers(annotatableNode);
final Annotation existingAnnotation = findExistingSuppressWarningsAnnotation(modifiers);
final Annotation annotation = createReplacementSuppressWarningsAnnotation(existingAnnotation, ast);
if (existingAnnotation == null) {
final int position = findPosition(modifiers);
modifiers.add(position, annotation);
} else {
ASTUtil.replace(existingAnnotation, annotation);
}
return !annotation.equals(existingAnnotation);
}
return false;
}
Aggregations