use of org.eclipse.jdt.core.dom.rewrite.ListRewrite in project che 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.rewrite.ListRewrite in project che by eclipse.
the class ModifierRewrite method copyAllAnnotations.
public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) {
ListRewrite modifierList = evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl);
List<IExtendedModifier> originalList = modifierList.getOriginalList();
for (Iterator<IExtendedModifier> iterator = originalList.iterator(); iterator.hasNext(); ) {
IExtendedModifier modifier = iterator.next();
if (modifier.isAnnotation()) {
fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup);
}
}
}
use of org.eclipse.jdt.core.dom.rewrite.ListRewrite in project che by eclipse.
the class NewVariableCorrectionProposal method doAddEnumConst.
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
SimpleName node = fOriginalNode;
ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
}
if (newTypeDecl != null) {
AST ast = newTypeDecl.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
EnumConstantDeclaration constDecl = ast.newEnumConstantDeclaration();
constDecl.setName(ast.newSimpleName(node.getIdentifier()));
ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
listRewriter.insertLast(constDecl, null);
addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME);
return rewrite;
}
return null;
}
use of org.eclipse.jdt.core.dom.rewrite.ListRewrite in project che by eclipse.
the class ChangeMethodSignatureProposal method modifyExceptions.
private void modifyExceptions(ASTRewrite rewrite, MethodDeclaration methodDecl) {
AST ast = methodDecl.getAST();
ImportRewrite imports = getImportRewrite();
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(methodDecl, imports);
ListRewrite listRewrite = rewrite.getListRewrite(methodDecl, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY);
// old exceptions
List<Type> exceptions = methodDecl.thrownExceptionTypes();
// index over the old exceptions
int k = 0;
for (int i = 0; i < fExceptionChanges.length; i++) {
ChangeDescription curr = fExceptionChanges[i];
if (curr == null) {
k++;
} else if (curr instanceof InsertDescription) {
InsertDescription desc = (InsertDescription) curr;
String type = imports.addImport(desc.type, context);
ASTNode newNode = imports.addImport(desc.type, ast, context);
listRewrite.insertAt(newNode, i, null);
String key = getExceptionTypeGroupId(i);
addLinkedPosition(rewrite.track(newNode), false, key);
Javadoc javadoc = methodDecl.getJavadoc();
if (javadoc != null && JavadocTagsSubProcessor.findThrowsTag(javadoc, type) == null) {
TagElement newTagElement = ast.newTagElement();
newTagElement.setTagName(TagElement.TAG_THROWS);
ASTNode newRef = ASTNodeFactory.newName(ast, type);
newTagElement.fragments().add(newRef);
//$NON-NLS-1$
insertTabStop(rewrite, newTagElement.fragments(), "throws_tagcomment" + i);
insertThrowsTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), exceptions, k, newTagElement);
addLinkedPosition(rewrite.track(newRef), false, key);
}
} else if (curr instanceof RemoveDescription) {
Type node = exceptions.get(k);
listRewrite.remove(node, null);
k++;
TagElement tagNode = findThrowsTag(methodDecl, node);
if (tagNode != null) {
rewrite.remove(tagNode, null);
}
} else if (curr instanceof EditDescription) {
EditDescription desc = (EditDescription) curr;
Type oldNode = exceptions.get(k);
String type = imports.addImport(desc.type, context);
ASTNode newNode = imports.addImport(desc.type, ast, context);
listRewrite.replace(oldNode, newNode, null);
String key = getExceptionTypeGroupId(i);
addLinkedPosition(rewrite.track(newNode), false, key);
k++;
TagElement tagNode = findThrowsTag(methodDecl, oldNode);
if (tagNode != null) {
ASTNode newRef = ASTNodeFactory.newType(ast, type);
rewrite.replace((ASTNode) tagNode.fragments().get(0), newRef, null);
addLinkedPosition(rewrite.track(newRef), false, key);
}
} else if (curr instanceof SwapDescription) {
Type decl1 = exceptions.get(k);
Type decl2 = exceptions.get(((SwapDescription) curr).index);
rewrite.replace(decl1, rewrite.createCopyTarget(decl2), null);
rewrite.replace(decl2, rewrite.createCopyTarget(decl1), null);
k++;
TagElement tagNode1 = findThrowsTag(methodDecl, decl1);
TagElement tagNode2 = findThrowsTag(methodDecl, decl2);
if (tagNode1 != null && tagNode2 != null) {
rewrite.replace(tagNode1, rewrite.createCopyTarget(tagNode2), null);
rewrite.replace(tagNode2, rewrite.createCopyTarget(tagNode1), null);
}
}
}
}
use of org.eclipse.jdt.core.dom.rewrite.ListRewrite in project che by eclipse.
the class AddArgumentCorrectionProposal method getRewrite.
/*(non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.ASTRewriteCorrectionProposal#getRewrite()
*/
@Override
protected ASTRewrite getRewrite() {
AST ast = fCallerNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
ChildListPropertyDescriptor property = getProperty();
for (int i = 0; i < fInsertIndexes.length; i++) {
int idx = fInsertIndexes[i];
//$NON-NLS-1$
String key = "newarg_" + i;
Expression newArg = evaluateArgumentExpressions(ast, fParamTypes[idx], key);
ListRewrite listRewriter = rewrite.getListRewrite(fCallerNode, property);
listRewriter.insertAt(newArg, idx, null);
addLinkedPosition(rewrite.track(newArg), i == 0, key);
}
return rewrite;
}
Aggregations