当前位置: 首页>>代码示例>>Java>>正文


Java TextFileChange.setEdit方法代码示例

本文整理汇总了Java中org.eclipse.ltk.core.refactoring.TextFileChange.setEdit方法的典型用法代码示例。如果您正苦于以下问题:Java TextFileChange.setEdit方法的具体用法?Java TextFileChange.setEdit怎么用?Java TextFileChange.setEdit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.ltk.core.refactoring.TextFileChange的用法示例。


在下文中一共展示了TextFileChange.setEdit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
protected Change createChange() throws CoreException {
  final Change change = fClasspathFixProposal.createChange(null);
  if (fImportRewrites != null) {
    final CompositeChange composite = new CompositeChange(getDisplayString());
    composite.add(change);
    for (final ImportRewrite ir : fImportRewrites) {
      final TextFileChange cuChange = new TextFileChange("Add import", //$NON-NLS-1$
          (IFile) ir.getCompilationUnit().getResource());
      cuChange.setEdit(ir.rewriteImports(null));
      composite.add(cuChange);
    }
    return composite;
  }
  return change;
}
 
开发者ID:x10-lang,项目名称:apgas,代码行数:16,代码来源:APGASClasspathFixCorrelationProposal.java

示例2: createTextChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:12,代码来源:RefactoringCorrectionProposal.java

示例3: createChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
@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;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:9,代码来源:DefaultRefactoringDocumentProvider.java

示例4: createTextChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:RefactoringCorrectionProposal.java

示例5: doDelete

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
	if (! confirmDeleteIfReferenced())
		return new NullChange();
	int resourceUpdateFlags= IResource.KEEP_HISTORY;
	int jCoreUpdateFlags= IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;

	pm.beginTask("", 2); //$NON-NLS-1$
	IPackageFragmentRoot root= getRoot();
	IResource rootResource= root.getResource();
	CompositeChange result= new CompositeChange(getName());

	ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
	IJavaProject[] referencingProjects= JavaElementUtil.getReferencingProjects(root);
	HashMap<IFile, String> classpathFilesContents= new HashMap<IFile, String>();
	for (int i= 0; i < referencingProjects.length; i++) {
		IJavaProject javaProject= referencingProjects[i];
		IFile classpathFile= javaProject.getProject().getFile(".classpath"); //$NON-NLS-1$
		if (classpathFile.exists()) {
			classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
		}
	}

	root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));

	rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
	for (Iterator<Entry<IFile, String>> iterator= classpathFilesContents.entrySet().iterator(); iterator.hasNext();) {
		Entry<IFile, String> entry= iterator.next();
		IFile file= entry.getKey();
		String contents= entry.getValue();
		//Restore time stamps? This should probably be some sort of UndoTextFileChange.
		TextFileChange classpathUndo= new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file);
		classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
		result.add(classpathUndo);
	}
	result.add(new UndoDeleteResourceChange(rootDescription));

	pm.done();
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:DeletePackageFragmentRootChange.java

示例6: createTextChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
@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());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:RefactoringCorrectionProposal.java

示例7: createChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
protected Change createChange() throws CoreException {
  final TextFileChange change = new TextFileChange("Add Import",
      (IFile) fImportRewrite.getCompilationUnit().getResource());
  change.setEdit(fImportRewrite.rewriteImports(new NullProgressMonitor()));
  return change;
}
 
开发者ID:x10-lang,项目名称:apgas,代码行数:7,代码来源:ConstructsImportProposal.java

示例8: performSaveActions

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
private void performSaveActions(IFile file, IDocument document, IProgressMonitor monitor,
		IPreferenceStore preferenceStore) {
	boolean runFormat = preferenceStore.getBoolean(TypeScriptUIPreferenceConstants.EDITOR_SAVE_ACTIONS_FORMAT);
	SubMonitor progress = SubMonitor.convert(monitor, (runFormat ? 10 : 0));
	if (!runFormat) {
		return;
	}

	IUndoManager manager = RefactoringCore.getUndoManager();

	CompositeChange saveActionsChange = new CompositeChange("Save Actions");
	List<Change> undoChanges = new ArrayList<>();
	boolean success = false;
	try {
		manager.aboutToPerformChange(saveActionsChange);

		// Format the file contents
		if (runFormat) {
			TextFileChange change = new TextFileChange("Format", file);
			try {
				IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(file.getProject());
				final IIDETypeScriptFile tsFile = tsProject.openFile(file, document);
				List<CodeEdit> codeEdits = tsFile.format(0, document.getLength()).get();
				change.setEdit(DocumentUtils.toTextEdit(codeEdits, document));
				change.initializeValidationData(new NullProgressMonitor());
				PerformChangeOperation performChangeOperation = new PerformChangeOperation(change);
				ResourcesPlugin.getWorkspace().run(performChangeOperation, progress.newChild(10));
				Change undoChange = performChangeOperation.getUndoChange();
				if (undoChange != null) {
					undoChanges.add(undoChange);
				}
			} catch (Exception e) {
				JSDTTypeScriptUIPlugin.log(e);
			}
		}

		success = true;
	} finally {
		manager.changePerformed(saveActionsChange, success);
	}

	// Add an undo change if possible
	if (!undoChanges.isEmpty()) {
		manager.addUndo(saveActionsChange.getName(), new CompositeChange(saveActionsChange.getName(),
				undoChanges.toArray(new Change[undoChanges.size()])));
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:48,代码来源:TypeScriptDocumentProvider.java

示例9: doDelete

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
  if (!confirmDeleteIfReferenced()) return new NullChange();
  int resourceUpdateFlags = IResource.KEEP_HISTORY;
  int jCoreUpdateFlags =
      IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH
          | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;

  pm.beginTask("", 2); // $NON-NLS-1$
  IPackageFragmentRoot root = getRoot();
  IResource rootResource = root.getResource();
  CompositeChange result = new CompositeChange(getName());

  ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
  IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(root);
  HashMap<IFile, String> classpathFilesContents = new HashMap<IFile, String>();
  for (int i = 0; i < referencingProjects.length; i++) {
    IJavaProject javaProject = referencingProjects[i];
    IFile classpathFile = javaProject.getProject().getFile(".classpath"); // $NON-NLS-1$
    if (classpathFile.exists()) {
      classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
    }
  }

  root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));

  rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
  for (Iterator<Entry<IFile, String>> iterator = classpathFilesContents.entrySet().iterator();
      iterator.hasNext(); ) {
    Entry<IFile, String> entry = iterator.next();
    IFile file = entry.getKey();
    String contents = entry.getValue();
    // Restore time stamps? This should probably be some sort of UndoTextFileChange.
    TextFileChange classpathUndo =
        new TextFileChange(
            Messages.format(
                RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file,
                BasicElementLabels.getPathLabel(file.getFullPath(), true)),
            file);
    classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
    result.add(classpathUndo);
  }
  result.add(new UndoDeleteResourceChange(rootDescription));

  pm.done();
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:48,代码来源:DeletePackageFragmentRootChange.java

示例10: addAddToBuildPropertiesProposal

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
private static boolean addAddToBuildPropertiesProposal(final ICompilationUnit cu, final Name name, final String fullyQualifiedName, Collection<ICommandAccess> proposals) throws CoreException {
	IProject project= cu.getJavaProject().getProject();
	final IFile buildProperties= project.getFile("build.properties"); //$NON-NLS-1$
	boolean isBundle= project.hasNature("org.eclipse.pde.PluginNature"); //$NON-NLS-1$
	if (!isBundle)
		return false;
	
	final String changeName= CorrectionMessages.UnresolvedElementsSubProcessor_add_annotation_bundle_description;
	final String buildPropertiesEntry= "additional.bundles = org.eclipse.jdt.annotation"; //$NON-NLS-1$
	
	ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(changeName, null, 0) {
		@Override
		protected Change createChange() throws CoreException {
			if (!buildProperties.exists()) {
				return new CreateFileChange(buildProperties.getFullPath(), buildPropertiesEntry, null);
				
			} else {
				TextFileChange change= new TextFileChange(changeName, buildProperties);
				change.setEdit(new MultiTextEdit());
				
				ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
				manager.connect(buildProperties.getFullPath(), LocationKind.IFILE, null);
				try {
					ITextFileBuffer textFileBuffer= manager.getTextFileBuffer(buildProperties.getFullPath(), LocationKind.IFILE);
					IDocument document= textFileBuffer.getDocument();
					String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
					
					IRegion match= new FindReplaceDocumentAdapter(document).find(0, "additional\\.bundles\\s*=\\s*", true, false, false, true); //$NON-NLS-1$
					if (match != null) {
						StringBuilder buf= new StringBuilder("org.eclipse.jdt.annotation,\\").append(lineDelim); //$NON-NLS-1$
						int spaces= match.getOffset() + match.getLength() - document.getLineOffset(document.getLineOfOffset(match.getOffset()));
						while (spaces-- > 0)
							buf.append(' ');
						change.addEdit(new InsertEdit(match.getOffset() + match.getLength(), buf.toString()));
					} else {
						String entry= buildPropertiesEntry + lineDelim;
						int len= document.getLength();
						if (len > 0 && document.getLineInformation(document.getNumberOfLines() - 1).getLength() != 0) {
							entry= lineDelim + entry;
						}
						change.addEdit(new InsertEdit(len, entry));
					}
					CompilationUnitChange addImportChange= createAddImportChange(cu, name, fullyQualifiedName);
					return new CompositeChange(changeName, new Change[] { change, addImportChange});
				} catch (BadLocationException e) {
					JavaPlugin.log(e);
					return new NullChange();
				} finally {
					manager.disconnect(buildProperties.getFullPath(), LocationKind.IFILE, null);
				}
			}
		}
		@Override
		public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
			return Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_annotation_bundle_info, buildPropertiesEntry);
		}
	};
	proposals.add(proposal);
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:61,代码来源:UnresolvedElementsSubProcessor.java

示例11: createFileChange

import org.eclipse.ltk.core.refactoring.TextFileChange; //导入方法依赖的package包/类
private TextChange createFileChange(IFile file, Pattern pattern, Collection<Match> matches,
        RefactoringStatus resultingStatus, Collection<MatchGroup> matchGroups)
                throws PatternSyntaxException, CoreException {
    PositionTracker tracker = InternalSearchUI.getInstance().getPositionTracker();

    TextFileChange change = new SynchronizedTextFileChange(MessageFormat.format(
            SearchMessages.ReplaceRefactoring_group_label_change_for_file, file.getName()), file);
    change.setEdit(new MultiTextEdit());

    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(file.getFullPath(), LocationKind.IFILE, null);
    try {
        ITextFileBuffer textFileBuffer = manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
        if (textFileBuffer == null) {
            resultingStatus
                    .addError(MessageFormat.format(SearchMessages.ReplaceRefactoring_error_accessing_file_buffer,
                            file.getName()));
            return null;
        }
        IDocument document = textFileBuffer.getDocument();
        String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);

        for (Iterator<Match> iterator = matches.iterator(); iterator.hasNext();) {
            Match match = iterator.next();
            int offset = match.getOffset();
            int length = match.getLength();
            Position currentPosition = tracker.getCurrentPosition(match);
            if (currentPosition != null) {
                offset = currentPosition.offset;
                if (length != currentPosition.length) {
                    resultingStatus.addError(MessageFormat.format(
                            SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
                    continue;
                }
            }

            String originalText = getOriginalText(document, offset, length);
            if (originalText == null) {
                resultingStatus.addError(MessageFormat.format(
                        SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
                continue;
            }

            String replacementString = computeReplacementString(pattern, originalText, fReplaceString,
                    lineDelimiter);
            if (replacementString == null) {
                resultingStatus.addError(MessageFormat.format(
                        SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
                continue;
            }

            ReplaceEdit replaceEdit = new ReplaceEdit(offset, length, replacementString);
            change.addEdit(replaceEdit);
            TextEditChangeGroup textEditChangeGroup = new TextEditChangeGroup(change, new TextEditGroup(
                    SearchMessages.ReplaceRefactoring_group_label_match_replace, replaceEdit));
            change.addTextEditChangeGroup(textEditChangeGroup);
            matchGroups.add(new MatchGroup(textEditChangeGroup, match));
        }
    } finally {
        manager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
    }
    return change;
}
 
开发者ID:fabioz,项目名称:Pydev,代码行数:64,代码来源:ReplaceRefactoring.java


注:本文中的org.eclipse.ltk.core.refactoring.TextFileChange.setEdit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。