public static void format(IDocument document, IRegion region, IProject project) { DocumentChange documentChange = new DocumentChange("Format region", document); try { ICodeFormattingProcessor formatter = createCodeFormatter(document, region, ProjectOptions.getPHPVersion(project), ProjectOptions.isSupportingASPTags(project), ProjectOptions.useShortTags(project)); documentChange.setEdit(formatter.getTextEdits()); if (document != null) { LinkedModeModel.closeAllModels(document); documentChange.initializeValidationData(new NullProgressMonitor()); RefactoringStatus valid = documentChange.isValid(new NullProgressMonitor()); if (valid.hasFatalError()) { IStatus status = new Status(IStatus.ERROR, PHPUiPlugin.ID, IStatus.ERROR, try { manager.aboutToPerformChange(documentChange); undoChange = documentChange.perform(new NullProgressMonitor()); successful = true; } finally { } finally { if (documentChange != null) { documentChange.dispose();
@Override protected Change createUndoChange(UndoEdit edit) { return new UndoDocumentChange(getName(), fDocument, edit); } }
@Override public Change createChange(String name, TextEdit textEdit) { DocumentChange documentChange = new DocumentChange(getName(), document); documentChange.setEdit(textEdit); documentChange.setTextType(getURI().fileExtension()); return new DisplayChangeWrapper(documentChange); }
@Override public Change createChange(String name, TextEdit textEdit) { DocumentChange documentChange = new DocumentChange(getName(), getDocument()) { @Override public Object[] getAffectedObjects() { return new Object[] { editor }; } }; documentChange.setEdit(textEdit); documentChange.setTextType(getURI().fileExtension()); return new DisplayChangeWrapper(documentChange); } }
change= new DocumentChange(name, document);
public static Change create(NLSSubstitution[] nlsSubstitutions, IPath propertyFilePath) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_change_name, propertyFilePath.toString()); 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; }
change= new DocumentChange(name, document); } else { CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
/** * {@inheritDoc} */ protected Change createUndoChange(UndoEdit edit) { return new UndoDocumentChange(getName(), fDocument, edit); } }
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; }
@Override protected Change createUndoChange(UndoEdit edit) { return new UndoDocumentChange(getName(), fDocument, edit); } }
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; }
change= new DocumentChange(name, document); } else { CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
public TextChange getNewChange() { ICompilationUnit cu= getCompilationUnit(); String name= getName(); TextChange change; if (!cu.getResource().exists()) { String source; try { source= cu.getSource(); } catch (JavaModelException e) { JavaManipulationPlugin.log(e); source= new String(); // empty } Document document= new Document(source); document.setInitialLineDelimiter(StubUtility.getLineDelimiterUsed(cu)); change= new DocumentChange(name, document); } else { CompilationUnitChange cuChange = new CompilationUnitChange(name, cu); cuChange.setSaveMode(TextFileChange.LEAVE_DIRTY); change= cuChange; } TextEdit rootEdit= new MultiTextEdit(); change.setEdit(rootEdit); return change; }
change= new DocumentChange(name, document); } else { CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
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; }