Search in sources :

Example 6 with TextEditGroup

use of org.eclipse.text.edits.TextEditGroup in project che by eclipse.

the class AccessAnalyzer method createGroupDescription.

private TextEditGroup createGroupDescription(String name) {
    TextEditGroup result = new TextEditGroup(name);
    fGroupDescriptions.add(result);
    return result;
}
Also used : TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 7 with TextEditGroup

use of org.eclipse.text.edits.TextEditGroup in project che by eclipse.

the class SelfEncapsulateFieldRefactoring method addGetterSetterChanges.

private List<TextEditGroup> addGetterSetterChanges(CompilationUnit root, ASTRewrite rewriter, String lineDelimiter, boolean usingLocalSetter, boolean usingLocalGetter) throws CoreException {
    List<TextEditGroup> result = new ArrayList<TextEditGroup>(2);
    AST ast = root.getAST();
    FieldDeclaration decl = (FieldDeclaration) ASTNodes.getParent(fFieldDeclaration, ASTNode.FIELD_DECLARATION);
    int position = 0;
    int numberOfMethods = 0;
    List<BodyDeclaration> members = ASTNodes.getBodyDeclarations(decl.getParent());
    for (Iterator<BodyDeclaration> iter = members.iterator(); iter.hasNext(); ) {
        BodyDeclaration element = iter.next();
        if (element.getNodeType() == ASTNode.METHOD_DECLARATION) {
            if (fInsertionIndex == -1) {
                break;
            } else if (fInsertionIndex == numberOfMethods) {
                position++;
                break;
            }
            numberOfMethods++;
        }
        position++;
    }
    TextEditGroup description;
    ListRewrite rewrite = fRewriter.getListRewrite(decl.getParent(), getBodyDeclarationsProperty(decl.getParent()));
    if (!usingLocalGetter) {
        description = new TextEditGroup(RefactoringCoreMessages.SelfEncapsulateField_add_getter);
        result.add(description);
        rewrite.insertAt(createGetterMethod(ast, rewriter, lineDelimiter), position++, description);
    }
    if (!JdtFlags.isFinal(fField) && !usingLocalSetter) {
        description = new TextEditGroup(RefactoringCoreMessages.SelfEncapsulateField_add_setter);
        result.add(description);
        rewrite.insertAt(createSetterMethod(ast, rewriter, lineDelimiter), position, description);
    }
    if (!JdtFlags.isPrivate(fField))
        result.add(makeDeclarationPrivate(rewriter, decl));
    return result;
}
Also used : AST(org.eclipse.jdt.core.dom.AST) ArrayList(java.util.ArrayList) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 8 with TextEditGroup

use of org.eclipse.text.edits.TextEditGroup in project che by eclipse.

the class SelfEncapsulateFieldRefactoring method makeDeclarationPrivate.

private TextEditGroup makeDeclarationPrivate(ASTRewrite rewriter, FieldDeclaration decl) {
    TextEditGroup description = new TextEditGroup(RefactoringCoreMessages.SelfEncapsulateField_change_visibility);
    VariableDeclarationFragment[] vdfs = new VariableDeclarationFragment[] { fFieldDeclaration };
    int includedModifiers = Modifier.PRIVATE;
    int excludedModifiers = Modifier.PROTECTED | Modifier.PUBLIC;
    VariableDeclarationRewrite.rewriteModifiers(decl, vdfs, includedModifiers, excludedModifiers, rewriter, description);
    return description;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 9 with TextEditGroup

use of org.eclipse.text.edits.TextEditGroup in project che by eclipse.

the class ChangeSignatureProcessor method addExplicitSuperConstructorCall.

private void addExplicitSuperConstructorCall(MethodDeclaration constructor, CompilationUnitRewrite cuRewrite) {
    SuperConstructorInvocation superCall = constructor.getAST().newSuperConstructorInvocation();
    addArgumentsToNewSuperConstructorCall(superCall, cuRewrite);
    String msg = RefactoringCoreMessages.ChangeSignatureRefactoring_add_super_call;
    TextEditGroup description = cuRewrite.createGroupDescription(msg);
    cuRewrite.getASTRewrite().getListRewrite(constructor.getBody(), Block.STATEMENTS_PROPERTY).insertFirst(superCall, description);
}
Also used : SuperConstructorInvocation(org.eclipse.jdt.core.dom.SuperConstructorInvocation) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 10 with TextEditGroup

use of org.eclipse.text.edits.TextEditGroup in project che by eclipse.

the class TextChangeCompatibility method addTextEdit.

public static void addTextEdit(TextChange change, String name, TextEdit edit) throws MalformedTreeException {
    Assert.isNotNull(change);
    Assert.isNotNull(name);
    Assert.isNotNull(edit);
    TextEdit root = change.getEdit();
    if (root == null) {
        root = new MultiTextEdit();
        change.setEdit(root);
    }
    insert(root, edit);
    change.addTextEditGroup(new TextEditGroup(name, edit));
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextEditGroup(org.eclipse.text.edits.TextEditGroup) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Aggregations

TextEditGroup (org.eclipse.text.edits.TextEditGroup)34 ASTNode (org.eclipse.jdt.core.dom.ASTNode)12 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)12 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)11 TextEdit (org.eclipse.text.edits.TextEdit)10 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 AST (org.eclipse.jdt.core.dom.AST)6 CategorizedTextEditGroup (org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)6 SimpleName (org.eclipse.jdt.core.dom.SimpleName)5 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)4 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)4 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)4 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 EnhancedForStatement (org.eclipse.jdt.core.dom.EnhancedForStatement)3