public TextChange getChange(IFile file) { TextChange result= fChanges.get(file); if (result == null) { result= new TextFileChange(file.getName(), file); fChanges.put(file, result); } return result; }
public TextChange getChange(IFile file) { TextChange result= (TextChange)fChanges.get(file); if (result == null) { result= new TextFileChange(file.getName(), file); fChanges.put(file, result); } return result; }
public TextChange getChange(IFile file) { TextChange result= fChanges.get(file); if (result == null) { result= new TextFileChange(file.getName(), file); fChanges.put(file, result); } return result; }
public TextChange getChange(IFile file) { TextChange result= fChanges.get(file); if (result == null) { result= new TextFileChange(file.getName(), file); fChanges.put(file, result); } return result; }
public TextChange getChange(IFile file) { TextChange result = (TextChange) fChanges.get(file); if (result == null) { result = new TextFileChange(file.getName(), file); fChanges.put(file, result); } return result; }
/** * Returns the <code>TextChange</code> associated with the given file. * If the manager does not already manage an association it creates a one. * * @param file the file for which the text buffer change is requested * @return the text change associated with the given file. */ public TextChange get(IFile file) { TextChange result= (TextChange)fMap.get(file); if (result == null) { result= new TextFileChange(file.toString(), file); result.setKeepPreviewEdits(fKeepExecutedTextEdits); result.initializeValidationData(new NullProgressMonitor()); fMap.put(file, result); } return result; }
private void performTextEdit(TextEdit textEdit, IFile file, IProgressMonitor pm) throws CoreException { TextFileChange textFileChange = new TextFileChange("Add import for " + fQualifiedTypeToImport, file); //$NON-NLS-1$ textFileChange.setSaveMode(TextFileChange.KEEP_SAVE_STATE); textFileChange.setEdit(textEdit); textFileChange.perform(pm); }
private TextFileChange getChangeForFile(IFile file, CompositeChange parentChange) { if (fFileChanges.containsKey(file)) return fFileChanges.get(file); MultiTextEdit edit = new MultiTextEdit(); TextFileChange change = new TextFileChange(file.getName(), file); change.setEdit(edit); // mark a plugin.xml or a fragment.xml as PLUGIN2 type so they will be compared // with the PluginContentMergeViewer String textType = file.getName().equals(ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR) || file.getName().equals(ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR) ? "PLUGIN2" //$NON-NLS-1$ : file.getFileExtension(); change.setTextType(textType); parentChange.add(change); fFileChanges.put(file, change); return change; }
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; }
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; }
@Override protected TextChange createTextChange() throws CoreException { init(fRefactoring); fRefactoringStatus = fRefactoring.checkFinalConditions(new NullProgressMonitor()); if (fRefactoringStatus.hasFatalError()) { TextFileChange dummyChange = new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$ dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$ return dummyChange; } return (TextChange) fRefactoring.createChange(new NullProgressMonitor()); }
@Override protected TextChange createTextChange() throws CoreException { init(fRefactoring); fRefactoringStatus= fRefactoring.checkFinalConditions(new NullProgressMonitor()); if (fRefactoringStatus.hasFatalError()) { TextFileChange dummyChange= new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$ dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$ return dummyChange; } return (TextChange) fRefactoring.createChange(new NullProgressMonitor()); }
@Override protected TextChange createTextChange() throws CoreException { init(fRefactoring); fRefactoringStatus= fRefactoring.checkFinalConditions(new NullProgressMonitor()); if (fRefactoringStatus.hasFatalError()) { TextFileChange dummyChange= new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$ dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$ return dummyChange; } return (TextChange) fRefactoring.createChange(new NullProgressMonitor()); }
@Override public Change createChange(String name, TextEdit textEdit) { TextFileChange textFileChange = new TextFileChange(name, redirectedFile); textFileChange.setSaveMode(TextFileChange.FORCE_SAVE); textFileChange.setEdit(textEdit); textFileChange.setTextType(getURI().fileExtension()); return textFileChange; } }
private TextFileChange getTextChange(BundleTextChangeListener listener, IFile manifest) { TextEdit[] edits = listener.getTextOperations(); if (edits.length == 0) return null; MultiTextEdit edit = new MultiTextEdit(); edit.addChildren(edits); TextFileChange change = new TextFileChange("", manifest); //$NON-NLS-1$ change.setEdit(edit); PDEModelUtility.setChangeTextType(change, manifest); return change; } }
private static Change createChange(BundleTextChangeListener listener, IFile file) { TextEdit[] operations = listener.getTextOperations(); if (operations.length > 0) { TextFileChange change = new TextFileChange("", file); //$NON-NLS-1$ MultiTextEdit edit = new MultiTextEdit(); edit.addChildren(operations); change.setEdit(edit); PDEModelUtility.setChangeTextType(change, file); return change; } return null; }
@Override public Change createChange(String name, TextEdit textEdit) { TextFileChange textFileChange = new TextFileChange(name, file); textFileChange.setSaveMode(TextFileChange.FORCE_SAVE); textFileChange.setEdit(textEdit); textFileChange.setTextType(getURI().fileExtension()); return textFileChange; }
public static Change create(NLSSubstitution[] nlsSubstitutions, IPath propertyFilePath) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_change_name, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= null; if (!Checks.resourceExists(propertyFilePath)) { IProject project= getFileHandle(propertyFilePath).getProject(); String lineDelimiter= StubUtility.getLineDelimiterPreference(project); Document document= new Document(); document.setInitialLineDelimiter(lineDelimiter); textChange= new DocumentChange(name, document); addChanges(textChange, nlsSubstitutions); textChange.perform(new NullProgressMonitor()); String encoding= null; IContentType javaPropertiesContentType= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); //$NON-NLS-1$ IContentType[] contentTypes= Platform.getContentTypeManager().findContentTypesFor(propertyFilePath.lastSegment()); if (contentTypes.length == 0 || contentTypes.length > 1 || !contentTypes[0].equals(javaPropertiesContentType)) { if (javaPropertiesContentType != null) encoding= javaPropertiesContentType.getDefaultCharset(); if (encoding == null) encoding= "ISO-8859-1"; //$NON-NLS-1$ } return new CreateTextFileChange(propertyFilePath, textChange.getCurrentContent(new NullProgressMonitor()), encoding, "properties"); //$NON-NLS-1$ } textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ addChanges(textChange, nlsSubstitutions); return textChange; }
private Change createChange(IResource resource) { TextFileChange result = null; // creation of DOM/AST from a ICompilationUnit ASTParser parser = ASTParser.newParser(AST.JLS3); // We need the binding to be able to retrieve the types of the expressions in // the visitor (this is used to determine whether the assert() and fail() method // invocations can be found on the AssertJUnit class or not. If not, we don't // rewrite them since they are probably defined on the super class. parser.setResolveBindings(true); parser.setSource((ICompilationUnit) JavaCore.create(resource)); CompilationUnit astRoot = (CompilationUnit) parser.createAST(null); // AST ast = context.getASTRoot().getAST(); AST ast = astRoot.getAST(); ASTRewrite rewriter = new AnnotationRewriter().createRewriter(astRoot, ast); try { TextEdit edit = rewriter.rewriteAST(); result = new TextFileChange(resource.getName(), (IFile) resource); result.setEdit(edit); } catch (JavaModelException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } return result; } }
public TextChange createChange() throws Exception { TextChange change = oldFile == null ? new DocumentChange(label, oldDocument) : new TextFileChange(label, oldFile); // change.setSaveMode(TextFileChange.FORCE_SAVE); change.setEdit(new MultiTextEdit()); Object leftSide = new LineComparator(oldDocument); Object rightSide = new LineComparator(newDocument); RangeDifference[] differences = RangeDifferencer.findDifferences((IRangeComparator) leftSide, (IRangeComparator) rightSide); for(int i = 0; i < differences.length; i++ ) { RangeDifference curr = differences[i]; if(curr.leftLength() == 0 && curr.rightLength() == 0) continue; int rightOffset = newDocument.getLineOffset(curr.rightStart()); int rightLength = curr.rightLength() == 0 ? 0 : newDocument.getLineOffset(curr.rightEnd() - 1) - rightOffset + newDocument.getLineLength(curr.rightEnd() - 1); int leftOffset = oldDocument.getLineOffset(curr.leftStart()); int leftLength = curr.leftLength() == 0 ? 0 : oldDocument.getLineOffset(curr.leftEnd() - 1) - leftOffset + oldDocument.getLineLength(curr.leftEnd() - 1); String newText = newDocument.get(rightOffset, rightLength); addEdit(change, curr.leftStart(), new ReplaceEdit(leftOffset, leftLength, newText)); } return change; }