use of org.eclipse.jdt.core.dom.IExtendedModifier in project flux by eclipse.
the class ModifierCorrectionSubProcessor method findAnnotation.
private static Annotation findAnnotation(String qualifiedTypeName, List<IExtendedModifier> modifiers) {
for (int i = 0; i < modifiers.size(); i++) {
IExtendedModifier curr = modifiers.get(i);
if (curr instanceof Annotation) {
Annotation annot = (Annotation) curr;
ITypeBinding binding = annot.getTypeName().resolveTypeBinding();
if (binding != null && qualifiedTypeName.equals(binding.getQualifiedName())) {
return annot;
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project flux by eclipse.
the class ModifierRewrite method copyAllModifiers.
public void copyAllModifiers(ASTNode otherDecl, TextEditGroup editGroup, boolean copyIndividually) {
ListRewrite modifierList = evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl);
List<IExtendedModifier> originalList = modifierList.getOriginalList();
if (originalList.isEmpty()) {
return;
}
if (copyIndividually) {
for (Iterator<IExtendedModifier> iterator = originalList.iterator(); iterator.hasNext(); ) {
ASTNode modifier = (ASTNode) iterator.next();
ASTNode copy = fModifierRewrite.getASTRewrite().createCopyTarget(modifier);
if (copy != null) {
// paranoia check (only left here because we're in RC1)
fModifierRewrite.insertLast(copy, editGroup);
}
}
} else {
ASTNode copy = modifierList.createCopyTarget((ASTNode) originalList.get(0), (ASTNode) originalList.get(originalList.size() - 1));
if (copy != null) {
// paranoia check (only left here because we're in RC1)
fModifierRewrite.insertLast(copy, editGroup);
}
}
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project AutoRefactor by JnRouvignac.
the class DeclarationOutsideLoopRatherThanInsideCleanUp method moveDeclaration.
private void moveDeclaration(final Statement statement, final VariableDeclarationStatement varToMove) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.DeclarationOutsideLoopRatherThanInsideCleanUp_description);
VariableDeclarationFragment fragment = (VariableDeclarationFragment) varToMove.fragments().get(0);
if (fragment.getInitializer() != null) {
Type copyOfType = ast.createCopyTarget(varToMove.getType());
SimpleName name = fragment.getName();
VariableDeclarationFragment newFragment = ast.newVariableDeclarationFragment(ast.createCopyTarget(name));
List<Dimension> extraDimensions = fragment.extraDimensions();
List<Dimension> newExtraDimensions = newFragment.extraDimensions();
newExtraDimensions.addAll(ASTNodes.createMoveTarget(rewrite, extraDimensions));
VariableDeclarationStatement newDeclareStatement = ast.newVariableDeclarationStatement(copyOfType, newFragment);
List<IExtendedModifier> modifiers = varToMove.modifiers();
List<IExtendedModifier> newModifiers = newDeclareStatement.modifiers();
for (IExtendedModifier iExtendedModifier : modifiers) {
Modifier modifier = (Modifier) iExtendedModifier;
if (!modifier.isPrivate() && !modifier.isStatic()) {
newModifiers.add(ASTNodes.createMoveTarget(rewrite, modifier));
}
}
rewrite.insertBefore(newDeclareStatement, statement, group);
ASTNodes.replaceButKeepComment(rewrite, varToMove, ast.newExpressionStatement(ast.newAssignment(ast.createCopyTarget(name), Assignment.Operator.ASSIGN, ASTNodes.createMoveTarget(rewrite, fragment.getInitializer()))), group);
} else {
rewrite.insertBefore(ASTNodes.createMoveTarget(rewrite, varToMove), statement, group);
rewrite.remove(varToMove, group);
}
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project AutoRefactor by JnRouvignac.
the class ImplicitDefaultConstructorRatherThanWrittenOneCleanUp method visit.
@Override
public boolean visit(final TypeDeclaration visited) {
if (!visited.isInterface()) {
MethodDeclaration uniqueConstructor = null;
boolean isPublicClass = false;
boolean isProtectedClass = false;
boolean isPackageClass = true;
boolean isPrivateClass = false;
for (IExtendedModifier extendedModifier : (List<IExtendedModifier>) visited.modifiers()) {
if (extendedModifier.isModifier()) {
Modifier modifier = (Modifier) extendedModifier;
if (modifier.isPublic()) {
isPublicClass = true;
isPackageClass = false;
break;
}
if (modifier.isProtected()) {
isProtectedClass = true;
isPackageClass = false;
break;
}
if (modifier.isPrivate()) {
isPrivateClass = true;
isPackageClass = false;
break;
}
}
}
for (MethodDeclaration methodDeclaration : visited.getMethods()) {
if (methodDeclaration.isConstructor()) {
if (uniqueConstructor != null) {
// Too much constructors
return true;
}
uniqueConstructor = methodDeclaration;
}
}
if (uniqueConstructor != null && (!isCheckedExceptionThrown(uniqueConstructor) || visited.getSuperclassType() == null || ASTNodes.hasType(visited.getSuperclassType().resolveBinding(), Object.class.getCanonicalName())) && Utils.isEmpty(uniqueConstructor.parameters()) && isDefaultStatements(uniqueConstructor)) {
if (uniqueConstructor.modifiers() != null && uniqueConstructor.modifiers().size() == 1) {
IExtendedModifier extendedModifier = (IExtendedModifier) uniqueConstructor.modifiers().get(0);
if (extendedModifier.isModifier()) {
Modifier modifier = (Modifier) extendedModifier;
if (modifier.isPublic() && isPublicClass || modifier.isProtected() && isProtectedClass || modifier.isPrivate() && isPrivateClass) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ImplicitDefaultConstructorRatherThanWrittenOneCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(uniqueConstructor, group);
return false;
}
}
} else if (Utils.isEmpty(uniqueConstructor.modifiers()) && isPackageClass) {
TextEditGroup group = new TextEditGroup(MultiFixMessages.ImplicitDefaultConstructorRatherThanWrittenOneCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.remove(uniqueConstructor, group);
return false;
}
}
}
return true;
}
use of org.eclipse.jdt.core.dom.IExtendedModifier in project AutoRefactor by JnRouvignac.
the class ObsoleteLocalVariableRatherThanFieldCleanUp method replaceFieldByLocalVariable.
private void replaceFieldByLocalVariable(final FieldDeclaration field, final VariableDeclarationFragment fragment, final SimpleName reassignment) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLocalVariableRatherThanFieldCleanUp_description);
boolean isFieldKept = field.fragments().size() != 1;
Assignment reassignmentAssignment = (Assignment) reassignment.getParent();
VariableDeclarationFragment newFragment = ast.newVariableDeclarationFragment(ASTNodes.createMoveTarget(rewrite, reassignment), ASTNodes.createMoveTarget(rewrite, reassignmentAssignment.getRightHandSide()));
List<Dimension> extraDimensions = fragment.extraDimensions();
List<Dimension> newExtraDimensions = newFragment.extraDimensions();
newExtraDimensions.addAll(ASTNodes.createMoveTarget(rewrite, extraDimensions));
VariableDeclarationStatement newDeclareStatement = ast.newVariableDeclarationStatement(isFieldKept ? ASTNodes.createMoveTarget(rewrite, field.getType()) : ast.createCopyTarget(field.getType()), newFragment);
List<IExtendedModifier> modifiers = field.modifiers();
List<IExtendedModifier> newModifiers = newDeclareStatement.modifiers();
for (IExtendedModifier iExtendedModifier : modifiers) {
Modifier modifier = (Modifier) iExtendedModifier;
if (!modifier.isPrivate() && !modifier.isStatic()) {
newModifiers.add(isFieldKept ? ASTNodes.createMoveTarget(rewrite, modifier) : ast.createCopyTarget(modifier));
}
}
ASTNodes.replaceButKeepComment(rewrite, ASTNodes.getTypedAncestor(reassignmentAssignment, Statement.class), newDeclareStatement, group);
if (isFieldKept) {
rewrite.remove(fragment, group);
ASTNodes.replaceButKeepComment(rewrite, field.getType(), ast.createCopyTarget(field.getType()), group);
} else {
rewrite.remove(field, group);
}
}
Aggregations