use of org.eclipse.jdt.core.dom.Modifier in project AutoRefactor by JnRouvignac.
the class ObsoleteRedundantModifiersCleanUp method removeProtectedModifier.
private boolean removeProtectedModifier(final BodyDeclaration visited) {
List<IExtendedModifier> modifiers = visited.modifiers();
for (Modifier modifier : getModifiersOnly(modifiers)) {
if (modifier.isProtected()) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(modifier, group);
return false;
}
}
return true;
}
use of org.eclipse.jdt.core.dom.Modifier in project eclipse-pmd by acanda.
the class LocalVariableCouldBeFinalQuickFix method apply.
/**
* Adds the final modifier to the variable declaration.
*/
@Override
@SuppressWarnings("unchecked")
protected boolean apply(final VariableDeclarationStatement node) {
final Modifier modifier = (Modifier) node.getAST().createInstance(Modifier.class);
modifier.setKeyword(ModifierKeyword.FINAL_KEYWORD);
node.modifiers().add(modifier);
return true;
}
use of org.eclipse.jdt.core.dom.Modifier 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.Modifier in project eclipse-pmd by acanda.
the class UseUtilityClassQuickFix method addPrivateConstructor.
@SuppressWarnings("unchecked")
private void addPrivateConstructor(final TypeDeclaration typeDeclaration, final ASTRewrite rewrite) {
final AST ast = typeDeclaration.getAST();
final MethodDeclaration constructor = (MethodDeclaration) ast.createInstance(MethodDeclaration.class);
constructor.setConstructor(true);
final Modifier modifier = (Modifier) ast.createInstance(Modifier.class);
modifier.setKeyword(ModifierKeyword.PRIVATE_KEYWORD);
constructor.modifiers().add(modifier);
constructor.setName(ASTUtil.copy(typeDeclaration.getName()));
final Block body = (Block) ast.createInstance(Block.class);
constructor.setBody(body);
final ListRewrite statementRewrite = rewrite.getListRewrite(body, Block.STATEMENTS_PROPERTY);
final ASTNode comment = rewrite.createStringPlaceholder("// hide constructor of utility class", ASTNode.EMPTY_STATEMENT);
statementRewrite.insertFirst(comment, null);
final int position = findConstructorPosition(typeDeclaration);
final ListRewrite bodyDeclarationRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
bodyDeclarationRewrite.insertAt(constructor, position, null);
}
use of org.eclipse.jdt.core.dom.Modifier in project eclipse-pmd by acanda.
the class MethodArgumentCouldBeFinalQuickFix method apply.
/**
* Adds the final modifier to the variable declaration.
*/
@Override
@SuppressWarnings("unchecked")
protected boolean apply(final SingleVariableDeclaration node) {
final Modifier modifier = (Modifier) node.getAST().createInstance(Modifier.class);
modifier.setKeyword(ModifierKeyword.FINAL_KEYWORD);
node.modifiers().add(modifier);
return true;
}
Aggregations