org.eclipse.ltk.core.refactoring.TextChange Java Examples
The following examples show how to use
org.eclipse.ltk.core.refactoring.TextChange.
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: NLSPropertyFileModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); String value= PropertyFileDocumentModel.escape(substitution.getValue(), true) + model.getLineDelimiter(); KeyValuePair newPair= new KeyValuePair(key, value); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, BasicElementLabels.getJavaElementName(substitution.getKey())), edit); } } } }
Example #2
Source File: QualifiedNameSearchResult.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public Change getSingleChange(IFile[] alreadyTouchedFiles) { Collection<TextChange> values= fChanges.values(); if (values.size() == 0) { return null; } CompositeChange result= new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name); result.markAsSynthetic(); List<IFile> files= Arrays.asList(alreadyTouchedFiles); for (Iterator<TextChange> iter= values.iterator(); iter.hasNext();) { TextFileChange change= (TextFileChange)iter.next(); if (!files.contains(change.getFile())) { result.add(change); } } return result; }
Example #3
Source File: TextChangeManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Returns all text changes managed by this instance. * * @return all text changes managed by this instance */ public TextChange[] getAllChanges(){ Set<ICompilationUnit> cuSet= fMap.keySet(); ICompilationUnit[] cus= cuSet.toArray(new ICompilationUnit[cuSet.size()]); // sort by cu name: Arrays.sort(cus, new Comparator<ICompilationUnit>() { @Override public int compare(ICompilationUnit o1, ICompilationUnit o2) { String name1= o1.getElementName(); String name2= o2.getElementName(); return name1.compareTo(name2); } }); TextChange[] textChanges= new TextChange[cus.length]; for (int i= 0; i < cus.length; i++) { textChanges[i]= fMap.get(cus[i]); } return textChanges; }
Example #4
Source File: RenameNonVirtualMethodProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) { SearchResultGroup[] grouped= getOccurrences(); for (int i= 0; i < grouped.length; i++) { SearchResultGroup group= grouped[i]; SearchMatch[] results= group.getSearchResults(); ICompilationUnit cu= group.getCompilationUnit(); TextChange change= manager.get(cu); for (int j= 0; j < results.length; j++){ SearchMatch match= results[j]; if (!(match instanceof MethodDeclarationMatch)) { ReplaceEdit replaceEdit= createReplaceEdit(match, cu); String editName= RefactoringCoreMessages.RenamePrivateMethodRefactoring_update; addTextEdit(change, editName, replaceEdit); } } } pm.done(); }
Example #5
Source File: TextChangeCombiner.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public Change combineChanges(Change masterChange) { if (!(masterChange instanceof CompositeChange)) return masterChange; Map<Object, TextChange> resource2textChange = newLinkedHashMap(); List<Change> otherChanges = newArrayList(); Set<IEditorPart> editorsToSave = newHashSet(); visitCompositeChange((CompositeChange) masterChange, resource2textChange, otherChanges, editorsToSave); CompositeChange compositeChange = new FilteringCompositeChange(masterChange.getName()); for (TextChange combinedTextChange : resource2textChange.values()) { if(((MultiTextEdit) combinedTextChange.getEdit()).getChildrenSize() >0) { if(combinedTextChange instanceof EditorDocumentChange) { ((EditorDocumentChange) combinedTextChange).setDoSave(editorsToSave.contains(((EditorDocumentChange) combinedTextChange).getEditor())); compositeChange.add(combinedTextChange); } else compositeChange.add(DisplayChangeWrapper.wrap(combinedTextChange)); } } for(Change otherChange: otherChanges) compositeChange.add(DisplayChangeWrapper.wrap(otherChange)); if(compositeChange.getChildren().length == 0) return null; return compositeChange; }
Example #6
Source File: DeleteChangeCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
Example #7
Source File: TextChangeManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Returns all text changes managed by this instance. * * @return all text changes managed by this instance */ public TextChange[] getAllChanges() { Set<ICompilationUnit> cuSet = fMap.keySet(); ICompilationUnit[] cus = cuSet.toArray(new ICompilationUnit[cuSet.size()]); // sort by cu name: Arrays.sort(cus, new Comparator<ICompilationUnit>() { @Override public int compare(ICompilationUnit o1, ICompilationUnit o2) { String name1 = o1.getElementName(); String name2 = o2.getElementName(); return name1.compareTo(name2); } }); TextChange[] textChanges = new TextChange[cus.length]; for (int i = 0; i < cus.length; i++) { textChanges[i] = fMap.get(cus[i]); } return textChanges; }
Example #8
Source File: NLSPropertyFileModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static Change removeKeys(IPath propertyFilePath, List<String> keys) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_remove_from_property_file, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor())); for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) { String key= iterator.next(); TextEdit edit= model.remove(key); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(key)), edit); } } return textChange; }
Example #9
Source File: NLSSourceModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addAccessor(NLSSubstitution sub, TextChange change, String accessorName) { if (sub.getState() == NLSSubstitution.EXTERNALIZED) { NLSElement element= sub.getNLSElement(); Region position= element.getPosition(); String[] args= {sub.getValueNonEmpty(), BasicElementLabels.getJavaElementName(sub.getKey())}; String text= Messages.format(NLSMessages.NLSSourceModifier_externalize, args); String resourceGetter= createResourceGetter(sub.getKey(), accessorName); TextEdit edit= new ReplaceEdit(position.getOffset(), position.getLength(), resourceGetter); if (fIsEclipseNLS && element.getTagPosition() != null) { MultiTextEdit multiEdit= new MultiTextEdit(); multiEdit.addChild(edit); Region tagPosition= element.getTagPosition(); multiEdit.addChild(new DeleteEdit(tagPosition.getOffset(), tagPosition.getLength())); edit= multiEdit; } TextChangeCompatibility.addTextEdit(change, text, edit); } }
Example #10
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 #11
Source File: PropertyFileDocumentModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Inserts the given key value pairs into this model at appropriate * positions. Records all required text changes in the given change * * @param keyValuePairs the key value pairs to insert * @param change the change to use to record text changes */ public void insert(KeyValuePair[] keyValuePairs, TextChange change) { ArrayList<KeyValuePair> sorted= new ArrayList<KeyValuePair>(Arrays.asList(keyValuePairs)); Collections.sort(sorted, new Comparator<KeyValuePair>() { public int compare(KeyValuePair p1, KeyValuePair p2) { return Collator.getInstance().compare(p1.fKey, p2.fKey); } }); for (int i = 0; i < sorted.size(); i++) { KeyValuePair curr= sorted.get(i); InsertEdit insertEdit= insert(curr); String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, BasicElementLabels.getJavaElementName(curr.getKey())); TextChangeCompatibility.addTextEdit(change, message, insertEdit); } }
Example #12
Source File: RenameNonVirtualMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) { SearchResultGroup[] grouped= getOccurrences(); for (int i= 0; i < grouped.length; i++) { SearchResultGroup group= grouped[i]; SearchMatch[] results= group.getSearchResults(); ICompilationUnit cu= group.getCompilationUnit(); TextChange change= manager.get(cu); for (int j= 0; j < results.length; j++){ SearchMatch match= results[j]; if (!(match instanceof MethodDeclarationMatch)) { ReplaceEdit replaceEdit= createReplaceEdit(match, cu); String editName= RefactoringCoreMessages.RenamePrivateMethodRefactoring_update; addTextEdit(change, editName, replaceEdit); } } } pm.done(); }
Example #13
Source File: NLSPropertyFileModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static void addInsertEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { ArrayList<KeyValuePair> keyValuePairsToAdd= new ArrayList<KeyValuePair>(); for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { String value= PropertyFileDocumentModel.escape(substitution.getValueNonEmpty(), true) + model.getLineDelimiter(); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); keyValuePairsToAdd.add(new KeyValuePair(key, value)); } } if (keyValuePairsToAdd.size() > 0) { model.insert(keyValuePairsToAdd.toArray(new KeyValuePair[keyValuePairsToAdd.size()]), textChange); } }
Example #14
Source File: TextChangeManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns all text changes managed by this instance. * * @return all text changes managed by this instance */ public TextChange[] getAllChanges(){ Set<ICompilationUnit> cuSet= fMap.keySet(); ICompilationUnit[] cus= cuSet.toArray(new ICompilationUnit[cuSet.size()]); // sort by cu name: Arrays.sort(cus, new Comparator<ICompilationUnit>() { public int compare(ICompilationUnit o1, ICompilationUnit o2) { String name1= o1.getElementName(); String name2= o2.getElementName(); return name1.compareTo(name2); } }); TextChange[] textChanges= new TextChange[cus.length]; for (int i= 0; i < cus.length; i++) { textChanges[i]= fMap.get(cus[i]); } return textChanges; }
Example #15
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * * @param change * @return Map <Integer oldOffset, Integer updatedOffset> */ private static Map<Integer, Integer> getEditChangeOffsetUpdates(TextChange change) { TextEditChangeGroup[] editChanges= change.getTextEditChangeGroups(); Map<Integer, Integer> offsetUpdates= new HashMap<Integer, Integer>(editChanges.length); for (int i= 0; i < editChanges.length; i++) { TextEditChangeGroup editChange= editChanges[i]; IRegion oldRegion= editChange.getRegion(); if (oldRegion == null) continue; IRegion updatedRegion= TextEdit.getCoverage(change.getPreviewEdits(editChange.getTextEdits())); if (updatedRegion == null) continue; offsetUpdates.put(new Integer(oldRegion.getOffset()), new Integer(updatedRegion.getOffset())); } return offsetUpdates; }
Example #16
Source File: DeleteChangeCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
Example #17
Source File: AccessorClassModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static Change removeFields(ICompilationUnit cu, List<String> fields) throws CoreException { AccessorClassModifier sourceModification= new AccessorClassModifier(cu); String message= Messages.format(NLSMessages.AccessorClassModifier_remove_fields_from_accessor, BasicElementLabels.getFileName(cu)); TextChange change= new CompilationUnitChange(message, cu); MultiTextEdit multiTextEdit= new MultiTextEdit(); change.setEdit(multiTextEdit); for (int i= 0; i < fields.size(); i++) { String field= fields.get(i); NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null); sourceModification.removeKey(substitution, change); } if (change.getChangeGroups().length == 0) return null; change.addEdit(sourceModification.getTextEdit()); return change; }
Example #18
Source File: NLSPropertyFileModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void addRemoveEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doRemove(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { TextEdit edit= model.remove(substitution.getInitialKey()); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(substitution.getInitialKey())), edit); } } } }
Example #19
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IRegion getCorrespondingEditChangeRange(SearchMatch searchResult, TextChangeManager manager) { TextChange change= getTextChange(searchResult, manager); if (change == null) return null; IRegion oldMatchRange= createTextRange(searchResult); TextEditChangeGroup[] editChanges= change.getTextEditChangeGroups(); for (int i= 0; i < editChanges.length; i++) { if (oldMatchRange.equals(editChanges[i].getRegion())) return TextEdit.getCoverage(change.getPreviewEdits(editChanges[i].getTextEdits())); } return null; }
Example #20
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static ASTNode getEnclosingBlockOrMethodOrLambda(TextEdit declarationEdit, TextChange change, CompilationUnit newCUNode) { ASTNode enclosing= RefactoringAnalyzeUtil.getBlock(declarationEdit, change, newCUNode); if (enclosing == null) enclosing= RefactoringAnalyzeUtil.getMethodDeclaration(declarationEdit, change, newCUNode); if (enclosing == null) enclosing= RefactoringAnalyzeUtil.getLambdaExpression(declarationEdit, change, newCUNode); return enclosing; }
Example #21
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * This method analyzes a set of local variable renames inside one cu. It checks whether * any new compile errors have been introduced by the rename(s) and whether the correct * node(s) has/have been renamed. * * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames * @param cuChange the TextChange containing all local variable changes to be applied. * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found * @throws CoreException thrown if there was an error greating the preview content of the change */ public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement(); String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null); result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode)); if (result.hasError()) return result; for (int i= 0; i < analyzePackages.length; i++) { ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode); // get new declaration IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange); ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength()); Assert.isTrue(newDeclaration instanceof Name); VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration); Assert.isNotNull(declaration); SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange); result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes)); } return result; }
Example #22
Source File: MoveCuUpdateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addReferenceUpdates(TextChangeManager changeManager, ICompilationUnit movedUnit, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException, CoreException { List<ICompilationUnit> cuList= Arrays.asList(fCus); SearchResultGroup[] references= getReferences(movedUnit, pm, status); for (int i= 0; i < references.length; i++) { SearchResultGroup searchResultGroup= references[i]; ICompilationUnit referencingCu= searchResultGroup.getCompilationUnit(); if (referencingCu == null) continue; boolean simpleReferencesNeedNewImport= simpleReferencesNeedNewImport(movedUnit, referencingCu, cuList); SearchMatch[] results= searchResultGroup.getSearchResults(); for (int j= 0; j < results.length; j++) { // TODO: should update type references with results from addImport TypeReference reference= (TypeReference) results[j]; if (reference.isImportDeclaration()) { ImportRewrite rewrite= getImportRewrite(referencingCu); IImportDeclaration importDecl= (IImportDeclaration) SearchUtils.getEnclosingJavaElement(results[j]); if (Flags.isStatic(importDecl.getFlags())) { rewrite.removeStaticImport(importDecl.getElementName()); addStaticImport(movedUnit, importDecl, rewrite); } else { rewrite.removeImport(importDecl.getElementName()); rewrite.addImport(createStringForNewImport(movedUnit, importDecl)); } } else if (reference.isQualified()) { TextChange textChange= changeManager.get(referencingCu); String changeName= RefactoringCoreMessages.MoveCuUpdateCreator_update_references; TextEdit replaceEdit= new ReplaceEdit(reference.getOffset(), reference.getSimpleNameStart() - reference.getOffset(), fNewPackage); TextChangeCompatibility.addTextEdit(textChange, changeName, replaceEdit); } else if (simpleReferencesNeedNewImport) { ImportRewrite importEdit= getImportRewrite(referencingCu); String typeName= reference.getSimpleName(); importEdit.addImport(getQualifiedType(fDestination.getElementName(), typeName)); } } } }
Example #23
Source File: PyDocumentChange.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public static TextChange create(String name, IDocument document) { if (ResourcesPlugin.getPlugin() != null) { return new PyDocumentChange(name, document); } else { return new PyDocumentChangeForTests(name, document); } }
Example #24
Source File: RefactoringAnalyzeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static IRegion[] getNewRanges(TextEdit[] edits, TextChange change) { IRegion[] result = new IRegion[edits.length]; for (int i = 0; i < edits.length; i++) { result[i] = RefactoringAnalyzeUtil.getNewTextRange(edits[i], change); } return result; }
Example #25
Source File: ChangeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static void convertTextChange(TextChange textChange, WorkspaceEdit rootEdit) { Object modifiedElement = textChange.getModifiedElement(); if (!(modifiedElement instanceof IJavaElement)) { return; } TextEdit textEdits = textChange.getEdit(); if (textEdits == null) { return; } ICompilationUnit compilationUnit = (ICompilationUnit) ((IJavaElement) modifiedElement).getAncestor(IJavaElement.COMPILATION_UNIT); convertTextEdit(rootEdit, compilationUnit, textEdits); }
Example #26
Source File: ChangeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static void convertSingleChange(Change change, WorkspaceEdit edit) throws CoreException { if (change instanceof CompositeChange) { return; } if (change instanceof TextChange) { convertTextChange((TextChange) change, edit); } else if (change instanceof ResourceChange) { convertResourceChange((ResourceChange) change, edit); } }
Example #27
Source File: FixCorrectionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override protected TextChange createTextChange() throws CoreException { CompilationUnitChange createChange = fFix.createChange(null); createChange.setSaveMode(TextFileChange.LEAVE_DIRTY); // if (fFix instanceof ILinkedFix) { // setLinkedProposalModel(((ILinkedFix) fFix).getLinkedPositions()); // } return createChange; }
Example #28
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.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 #29
Source File: QualifiedNameFinder.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException { int start= matchAccess.getMatchOffset(); int length= matchAccess.getMatchLength(); // skip embedded FQNs (bug 130764): if (start > 0) { char before= matchAccess.getFileContentChar(start - 1); if (before == '.' || Character.isJavaIdentifierPart(before)) { return true; } } int fileContentLength= matchAccess.getFileContentLength(); int end= start + length; if (end < fileContentLength) { char after= matchAccess.getFileContentChar(end); if (Character.isJavaIdentifierPart(after)) { return true; } } IFile file= matchAccess.getFile(); synchronized(fResult) { TextChange change= fResult.getChange(file); TextChangeCompatibility.addTextEdit( change, RefactoringCoreMessages.QualifiedNameFinder_update_name, new ReplaceEdit(start, length, fNewValue), QUALIFIED_NAMES); } return true; }
Example #30
Source File: RenameFieldProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor monitor) throws CoreException { try { monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1); TextChange[] changes= fChangeManager.getAllChanges(); RenameJavaElementDescriptor descriptor= createRefactoringDescriptor(); return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes); } finally { monitor.done(); } }