org.eclipse.text.edits.TextEditGroup Java Examples
The following examples show how to use
org.eclipse.text.edits.TextEditGroup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnusedCodeFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { TextEditGroup group= createTextEditGroup(FixMessages.UnusedCodeFix_RemoveCast_description, cuRewrite); ASTRewrite rewrite= cuRewrite.getASTRewrite(); CastExpression cast= fCast; Expression expression= cast.getExpression(); if (expression instanceof ParenthesizedExpression) { Expression childExpression= ((ParenthesizedExpression) expression).getExpression(); if (NecessaryParenthesesChecker.needsParentheses(childExpression, cast, CastExpression.EXPRESSION_PROPERTY)) { expression= childExpression; } } replaceCast(cast, expression, rewrite, group); }
Example #2
Source File: ReplaceRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) { ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor); if (fToReplace.length == replacements.length) { for (int i= 0; i < fToReplace.length; i++) { container.replace(fToReplace[i], replacements[i], description); } } else if (fToReplace.length < replacements.length) { for (int i= 0; i < fToReplace.length; i++) { container.replace(fToReplace[i], replacements[i], description); } for (int i= fToReplace.length; i < replacements.length; i++) { container.insertAfter(replacements[i], replacements[i - 1], description); } } else if (fToReplace.length > replacements.length) { int delta= fToReplace.length - replacements.length; for(int i= 0; i < delta; i++) { container.remove(fToReplace[i], description); } for (int i= delta, r= 0; i < fToReplace.length; i++, r++) { container.replace(fToReplace[i], replacements[r], description); } } }
Example #3
Source File: ExtractTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addReplaceExpressionWithTemp() throws JavaModelException { IASTFragment[] fragmentsToReplace= retainOnlyReplacableMatches(getMatchingFragments()); //TODO: should not have to prune duplicates here... ASTRewrite rewrite= fCURewrite.getASTRewrite(); HashSet<IASTFragment> seen= new HashSet<IASTFragment>(); for (int i= 0; i < fragmentsToReplace.length; i++) { IASTFragment fragment= fragmentsToReplace[i]; if (! seen.add(fragment)) continue; SimpleName tempName= fCURewrite.getAST().newSimpleName(fTempName); TextEditGroup description= fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_replace); fragment.replace(rewrite, tempName, description); if (fLinkedProposalModel != null) fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(rewrite.track(tempName), false); } }
Example #4
Source File: ReplaceTypeCodeWithStateStrategy.java From JDeodorant with MIT License | 6 votes |
private void createStateField() { ASTRewrite sourceRewriter = ASTRewrite.create(sourceTypeDeclaration.getAST()); AST contextAST = sourceTypeDeclaration.getAST(); ListRewrite contextBodyRewrite = sourceRewriter.getListRewrite(sourceTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY); VariableDeclarationFragment typeFragment = createStateFieldVariableDeclarationFragment(sourceRewriter, contextAST); FieldDeclaration typeFieldDeclaration = contextAST.newFieldDeclaration(typeFragment); sourceRewriter.set(typeFieldDeclaration, FieldDeclaration.TYPE_PROPERTY, contextAST.newSimpleName(abstractClassName), null); ListRewrite typeFieldDeclarationModifiersRewrite = sourceRewriter.getListRewrite(typeFieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY); typeFieldDeclarationModifiersRewrite.insertLast(contextAST.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD), null); contextBodyRewrite.insertBefore(typeFieldDeclaration, typeCheckElimination.getTypeField().getParent(), null); try { TextEdit sourceEdit = sourceRewriter.rewriteAST(); ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement(); CompilationUnitChange change = compilationUnitChanges.get(sourceICompilationUnit); change.getEdit().addChild(sourceEdit); change.addTextEditGroup(new TextEditGroup("Create field holding the current state", new TextEdit[] {sourceEdit})); } catch (JavaModelException e) { e.printStackTrace(); } }
Example #5
Source File: ASTRewriteAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void rewriteExtraDimensions(int oldDim, int newDim, int pos, TextEditGroup editGroup) { if (oldDim < newDim) { for (int i= oldDim; i < newDim; i++) { doTextInsert(pos, "[]", editGroup); //$NON-NLS-1$ } } else if (newDim < oldDim) { try { getScanner().setOffset(pos); for (int i= newDim; i < oldDim; i++) { getScanner().readToToken(TerminalTokens.TokenNameRBRACKET); } doTextRemove(pos, getScanner().getCurrentEndOffset() - pos, editGroup); } catch (CoreException e) { handleException(e); } } }
Example #6
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected void changeParamgumentName(ParameterInfo info) { VariableDeclaration param= getParameter(info.getOldIndex()); if (!info.getOldName().equals(param.getName().getIdentifier())) return; //don't change if original parameter name != name in rippleMethod String msg= RefactoringCoreMessages.ChangeSignatureRefactoring_update_parameter_references; TextEditGroup description= fCuRewrite.createGroupDescription(msg); TempOccurrenceAnalyzer analyzer= new TempOccurrenceAnalyzer(param, false); analyzer.perform(); SimpleName[] paramOccurrences= analyzer.getReferenceAndDeclarationNodes(); // @param tags are updated in changeJavaDocTags() for (int j= 0; j < paramOccurrences.length; j++) { SimpleName occurence= paramOccurrences[j]; getASTRewrite().set(occurence, SimpleName.IDENTIFIER_PROPERTY, info.getNewName(), description); } }
Example #7
Source File: ReplaceTypeCodeWithStateStrategy.java From JDeodorant with MIT License | 6 votes |
private void addRequiredImportDeclarationsToContext() { ImportRewrite sourceImportRewrite = ImportRewrite.create(sourceCompilationUnit, true); for(ITypeBinding typeBinding : requiredImportDeclarationsForContext) { if(!typeBinding.isNested()) sourceImportRewrite.addImport(typeBinding); } try { TextEdit sourceImportEdit = sourceImportRewrite.rewriteImports(null); if(sourceImportRewrite.getCreatedImports().length > 0) { ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement(); CompilationUnitChange change = compilationUnitChanges.get(sourceICompilationUnit); change.getEdit().addChild(sourceImportEdit); change.addTextEditGroup(new TextEditGroup("Add required import declarations", new TextEdit[] {sourceImportEdit})); } } catch (CoreException e) { e.printStackTrace(); } }
Example #8
Source File: TypeAnnotationRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from * <code>node</code>'s <code>childListProperty</code>. * <p> * In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER} * the latter is ignored, because this is implied by the former and creates no ambiguity.</p> * * @param node ASTNode * @param childListProperty child list property * @param rewrite rewrite that removes the nodes * @param editGroup the edit group in which to collect the corresponding text edits, or null if * ungrouped */ public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) { CompilationUnit root= (CompilationUnit) node.getRoot(); if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) { return; } ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty); @SuppressWarnings("unchecked") List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty); for (ASTNode child : children) { if (child instanceof Annotation) { Annotation annotation= (Annotation) child; if (isPureTypeAnnotation(annotation)) { listRewrite.remove(child, editGroup); } } } }
Example #9
Source File: ExtractTempRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void addReplaceExpressionWithTemp() throws JavaModelException { IASTFragment[] fragmentsToReplace = retainOnlyReplacableMatches(getMatchingFragments()); //TODO: should not have to prune duplicates here... ASTRewrite rewrite = fCURewrite.getASTRewrite(); HashSet<IASTFragment> seen = new HashSet<>(); for (int i = 0; i < fragmentsToReplace.length; i++) { IASTFragment fragment = fragmentsToReplace[i]; if (!seen.add(fragment)) { continue; } SimpleName tempName = fCURewrite.getAST().newSimpleName(fTempName); TextEditGroup description = fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_replace); fragment.replace(rewrite, tempName, description); if (fLinkedProposalModel != null) { fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(rewrite.track(tempName), false); } } }
Example #10
Source File: CodeStyleFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { ASTRewrite rewrite= cuRewrite.getASTRewrite(); TextEditGroup group= createTextEditGroup(getDescription(), cuRewrite); AST ast= rewrite.getAST(); FieldAccess fieldAccess= ast.newFieldAccess(); ThisExpression thisExpression= ast.newThisExpression(); if (fQualifier != null) thisExpression.setQualifier(ast.newName(fQualifier)); fieldAccess.setExpression(thisExpression); fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName)); rewrite.replace(fName, fieldAccess, group); }
Example #11
Source File: MoveMethodRefactoring.java From JDeodorant with MIT License | 6 votes |
private void addAdditionalMethodsToTargetClass() { AST ast = targetTypeDeclaration.getAST(); Set<MethodDeclaration> methodsToBeMoved = new LinkedHashSet<MethodDeclaration>(additionalMethodsToBeMoved.values()); for(MethodDeclaration methodDeclaration : methodsToBeMoved) { TypeVisitor typeVisitor = new TypeVisitor(); methodDeclaration.accept(typeVisitor); for(ITypeBinding typeBinding : typeVisitor.getTypeBindings()) { this.additionalTypeBindingsToBeImportedInTargetClass.add(typeBinding); } MethodDeclaration newMethodDeclaration = (MethodDeclaration)ASTNode.copySubtree(ast, methodDeclaration); ASTRewrite targetRewriter = ASTRewrite.create(targetCompilationUnit.getAST()); ListRewrite targetClassBodyRewrite = targetRewriter.getListRewrite(targetTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY); targetClassBodyRewrite.insertLast(newMethodDeclaration, null); try { TextEdit targetEdit = targetRewriter.rewriteAST(); targetMultiTextEdit.addChild(targetEdit); targetCompilationUnitChange.addTextEditGroup(new TextEditGroup("Add additional moved method", new TextEdit[] {targetEdit})); } catch(JavaModelException javaModelException) { javaModelException.printStackTrace(); } } }
Example #12
Source File: ExpressionsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { TextEditGroup group= createTextEditGroup(FixMessages.ExpressionsFix_addParanoiacParentheses_description, cuRewrite); ASTRewrite rewrite= cuRewrite.getASTRewrite(); AST ast= cuRewrite.getRoot().getAST(); for (int i= 0; i < fExpressions.length; i++) { // add parenthesis around expression Expression expression= fExpressions[i]; ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression((Expression) rewrite.createCopyTarget(expression)); rewrite.replace(expression, parenthesizedExpression, group); } }
Example #13
Source File: ReplaceRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) { ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor); if (fToReplace.length == replacements.length) { for (int i= 0; i < fToReplace.length; i++) { container.replace(fToReplace[i], replacements[i], description); } } else if (fToReplace.length < replacements.length) { for (int i= 0; i < fToReplace.length; i++) { container.replace(fToReplace[i], replacements[i], description); } for (int i= fToReplace.length; i < replacements.length; i++) { container.insertAfter(replacements[i], replacements[i - 1], description); } } else if (fToReplace.length > replacements.length) { int delta= fToReplace.length - replacements.length; for(int i= 0; i < delta; i++) { container.remove(fToReplace[i], description); } for (int i= delta, r= 0; i < fToReplace.length; i++, r++) { container.replace(fToReplace[i], replacements[r], description); } } }
Example #14
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addInheritedTypeQualifications(final AbstractTypeDeclaration declaration, final CompilationUnitRewrite targetRewrite, final TextEditGroup group) { Assert.isNotNull(declaration); Assert.isNotNull(targetRewrite); final CompilationUnit unit= (CompilationUnit) declaration.getRoot(); final ITypeBinding binding= declaration.resolveBinding(); if (binding != null) { Type type= null; if (declaration instanceof TypeDeclaration) { type= ((TypeDeclaration) declaration).getSuperclassType(); if (type != null && unit.findDeclaringNode(binding) != null) addTypeQualification(type, targetRewrite, group); } List<Type> types= null; if (declaration instanceof TypeDeclaration) types= ((TypeDeclaration) declaration).superInterfaceTypes(); else if (declaration instanceof EnumDeclaration) types= ((EnumDeclaration) declaration).superInterfaceTypes(); if (types != null) { for (final Iterator<Type> iterator= types.iterator(); iterator.hasNext();) { type= iterator.next(); if (unit.findDeclaringNode(type.resolveBinding()) != null) addTypeQualification(type, targetRewrite, group); } } } }
Example #15
Source File: TextEditUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Moves the given text edit groups (and its text edits) into the given * change. */ public static void moveTextEditGroupsIntoChange( TextEditBasedChangeGroup[] groups, TextChange textChange) { for (TextEditBasedChangeGroup changeGroup : groups) { TextEditGroup group = changeGroup.getTextEditGroup(); for (TextEdit edit : group.getTextEdits()) { if (edit.getParent() != null) { edit.getParent().removeChild(edit); } textChange.addEdit(edit); } // We must create a new change group since it doesn't have API to change // the parent change TextEditBasedChangeGroup newChangeGroup = new TextEditBasedChangeGroup( textChange, group); newChangeGroup.setEnabled(changeGroup.isEnabled()); textChange.addChangeGroup(newChangeGroup); } }
Example #16
Source File: SimpleFragment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) { if (replacement instanceof Name && fNode.getParent() instanceof ParenthesizedExpression) { // replace including the parenthesized expression around it rewrite.replace(fNode.getParent(), replacement, textEditGroup); } else { rewrite.replace(fNode, replacement, textEditGroup); } }
Example #17
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createEdits(ICompilationUnit unit, ASTRewrite rewriter, List<TextEditGroup> groups, ImportRewrite importRewrite) throws CoreException { TextChange change= fChangeManager.get(unit); MultiTextEdit root= new MultiTextEdit(); change.setEdit(root); root.addChild(importRewrite.rewriteImports(null)); root.addChild(rewriter.rewriteAST()); for (Iterator<TextEditGroup> iter= groups.iterator(); iter.hasNext();) { change.addTextEditGroup(iter.next()); } }
Example #18
Source File: InlineConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void removeConstantDeclarationIfNecessary() { if (fDeclarationToRemove == null) return; FieldDeclaration parentDeclaration= (FieldDeclaration) fDeclarationToRemove.getParent(); ASTNode toRemove; if (parentDeclaration.fragments().size() == 1) toRemove= parentDeclaration; else toRemove= fDeclarationToRemove; TextEditGroup msg= fCuRewrite.createGroupDescription(RefactoringCoreMessages.InlineConstantRefactoring_remove_declaration); fCuRewrite.getASTRewrite().remove(toRemove, msg); fCuRewrite.getImportRemover().registerRemovedNode(toRemove); }
Example #19
Source File: ReplaceRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public void replace(ASTNode[] replacements, TextEditGroup description) { if (fToReplace.length == 1) { if (replacements.length == 1) { handleOneOne(replacements, description); } else { handleOneMany(replacements, description); } } else { handleManyMany(replacements, description); } }
Example #20
Source File: ASTRewriteAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void replaceOperation(int posBeforeOperation, String newOperation, TextEditGroup editGroup) { try { getScanner().readNext(posBeforeOperation, true); doTextReplace(getScanner().getCurrentStartOffset(), getScanner().getCurrentLength(), newOperation, editGroup); } catch (CoreException e) { handleException(e); } }
Example #21
Source File: RewriteEventStore.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Marks a node as tracked. The edits added to the group editGroup can be used to get the * position of the node after the rewrite operation. * @param node The node to track * @param editGroup Collects the range markers describing the node position. */ public final void markAsTracked(ASTNode node, TextEditGroup editGroup) { if (getTrackedNodeData(node) != null) { throw new IllegalArgumentException("Node is already marked as tracked"); //$NON-NLS-1$ } setTrackedNodeData(node, editGroup); }
Example #22
Source File: CallInliner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addNewLocals(TextEditGroup textEditGroup) { if (fLocals.isEmpty()) return; for (Iterator<VariableDeclarationStatement> iter= fLocals.iterator(); iter.hasNext();) { ASTNode element= iter.next(); fListRewrite.insertAt(element, fInsertionIndex++, textEditGroup); } }
Example #23
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void updateConstructorReference(ITypeBinding[] parameters, ASTNode reference, CompilationUnitRewrite targetRewrite, ICompilationUnit cu) throws CoreException { final TextEditGroup group= targetRewrite.createGroupDescription(RefactoringCoreMessages.MoveInnerToTopRefactoring_update_constructor_reference); if (reference instanceof SuperConstructorInvocation) updateConstructorReference((SuperConstructorInvocation) reference, targetRewrite, cu, group); else if (reference instanceof ClassInstanceCreation) updateConstructorReference((ClassInstanceCreation) reference, targetRewrite, cu, group); else if (reference.getParent() instanceof ClassInstanceCreation) updateConstructorReference((ClassInstanceCreation) reference.getParent(), targetRewrite, cu, group); else if (reference.getParent() instanceof ParameterizedType && reference.getParent().getParent() instanceof ClassInstanceCreation) updateConstructorReference(parameters, (ParameterizedType) reference.getParent(), targetRewrite, cu, group); }
Example #24
Source File: ExtractMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private MethodDeclaration createNewMethod(ASTNode[] selectedNodes, String lineDelimiter, TextEditGroup substitute) throws CoreException { MethodDeclaration result= createNewMethodDeclaration(); result.setBody(createMethodBody(selectedNodes, substitute, result.getModifiers())); if (fGenerateJavadoc) { AbstractTypeDeclaration enclosingType= (AbstractTypeDeclaration)ASTNodes.getParent(fAnalyzer.getEnclosingBodyDeclaration(), AbstractTypeDeclaration.class); String string= CodeGeneration.getMethodComment(fCUnit, enclosingType.getName().getIdentifier(), result, null, lineDelimiter); if (string != null) { Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC); result.setJavadoc(javadoc); } } return result; }
Example #25
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void updateConstructorReference(final ClassInstanceCreation creation, final CompilationUnitRewrite targetRewrite, final ICompilationUnit unit, TextEditGroup group) throws JavaModelException { Assert.isNotNull(creation); Assert.isNotNull(targetRewrite); Assert.isNotNull(unit); final ASTRewrite rewrite= targetRewrite.getASTRewrite(); if (fCreateInstanceField) insertExpressionAsParameter(creation, rewrite, unit, group); final Expression expression= creation.getExpression(); if (expression != null) { rewrite.remove(expression, null); targetRewrite.getImportRemover().registerRemovedNode(expression); } }
Example #26
Source File: JavadocTagsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void insertTag(ListRewrite rewriter, TagElement newElement, Set<String> sameKindLeadingNames, TextEditGroup groupDescription) { List<? extends ASTNode> tags= rewriter.getRewrittenList(); String insertedTagName= newElement.getTagName(); ASTNode after= null; int tagRanking= getTagRanking(insertedTagName); for (int i= tags.size() - 1; i >= 0; i--) { TagElement curr= (TagElement) tags.get(i); String tagName= curr.getTagName(); if (tagName == null || tagRanking > getTagRanking(tagName)) { after= curr; break; } if (sameKindLeadingNames != null && isSameTag(insertedTagName, tagName)) { String arg= getArgument(curr); if (arg != null && sameKindLeadingNames.contains(arg)) { after= curr; break; } } } if (after != null) { rewriter.insertAfter(newElement, after, groupDescription); } else { rewriter.insertFirst(newElement, groupDescription); } }
Example #27
Source File: TextEditCreation.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Puts the edits found in a doc change, tak * @param fChange * @param editsAlreadyCreatedLst * @param docChange * @param rootEdit * @param renameEdits */ private void fillEditsInDocChange(TextChange docChange, MultiTextEdit rootEdit, List<Tuple<List<TextEdit>, String>> renameEdits) { Assert.isTrue(renameEdits.size() > 0); try { for (Tuple<List<TextEdit>, String> t : renameEdits) { TextEdit[] arr = t.o1.toArray(new TextEdit[t.o1.size()]); rootEdit.addChildren(arr); docChange.addTextEditGroup(new TextEditGroup(t.o2, arr)); } } catch (RuntimeException e) { //StringBuffer buf = new StringBuffer("Found occurrences:"); //for (Tuple<TextEdit, String> t : renameEdits) { // buf.append("Offset: "); // buf.append(t.o1.getOffset()); // buf.append("Len: "); // buf.append(t.o1.getLength()); // buf.append("Str: "); // buf.append(t.o2); // buf.append("\n"); //} // //don't bother reporting this to the user (usually happens if we have it the file changes during the analysis). //PydevPlugin.log(buf.toString(), e); throw e; } }
Example #28
Source File: ASTRewriteAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void rewriteOperation(ASTNode parent, StructuralPropertyDescriptor property, int posBeforeOperation) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { try { String newOperation= event.getNewValue().toString(); TextEditGroup editGroup= getEditGroup(event); getScanner().readNext(posBeforeOperation, true); doTextReplace(getScanner().getCurrentStartOffset(), getScanner().getCurrentLength(), newOperation, editGroup); } catch (CoreException e) { handleException(e); } } }
Example #29
Source File: ControlStatementsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { ASTRewrite rewrite= cuRewrite.getASTRewrite(); Block block= (Block)fStatement.getStructuralProperty(fChild); Statement statement= (Statement)block.statements().get(0); Statement moveTarget= (Statement)rewrite.createMoveTarget(statement); TextEditGroup group= createTextEditGroup(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, cuRewrite); rewrite.set(fStatement, fChild, moveTarget, group); }
Example #30
Source File: CallInliner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RefactoringStatus perform(TextEditGroup textEditGroup) throws CoreException { RefactoringStatus result= new RefactoringStatus(); String[] blocks= fSourceProvider.getCodeBlocks(fContext, fImportRewrite); if(!fFieldInitializer) { initializeInsertionPoint(fSourceProvider.getNumberOfStatements() + fLocals.size()); } addNewLocals(textEditGroup); replaceCall(result, blocks, textEditGroup); return result; }