本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility.addTextEdit方法的典型用法代码示例。如果您正苦于以下问题:Java TextChangeCompatibility.addTextEdit方法的具体用法?Java TextChangeCompatibility.addTextEdit怎么用?Java TextChangeCompatibility.addTextEdit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility
的用法示例。
在下文中一共展示了TextChangeCompatibility.addTextEdit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addConstructorRenames
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addConstructorRenames(TextChangeManager manager) throws CoreException {
ICompilationUnit cu = fType.getCompilationUnit();
IMethod[] methods = fType.getMethods();
int typeNameLength = fType.getElementName().length();
for (int i = 0; i < methods.length; i++) {
if (methods[i].isConstructor()) {
/*
* constructor declarations cannot be fully qualified so we can use simple replace here
*
* if (methods[i].getNameRange() == null), then it's a binary file so it's wrong anyway
* (checked as a precondition)
*/
String name = RefactoringCoreMessages.RenameTypeRefactoring_rename_constructor;
TextChangeCompatibility.addTextEdit(
manager.get(cu),
name,
new ReplaceEdit(
methods[i].getNameRange().getOffset(), typeNameLength, getNewElementName()));
}
}
}
示例2: addReferenceUpdates
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
pm.beginTask("", fReferences.length); // $NON-NLS-1$
for (int i = 0; i < fReferences.length; i++) {
ICompilationUnit cu = fReferences[i].getCompilationUnit();
if (cu == null) continue;
String name = RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
SearchMatch[] results = fReferences[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
ReplaceEdit replaceEdit =
new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
TextChangeCompatibility.addTextEdit(
manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
}
pm.worked(1);
}
}
示例3: addTextEditFromRewrite
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
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);
}
}
示例4: insert
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
/**
* 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);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:25,代码来源:PropertyFileDocumentModel.java
示例5: addConstructorRenames
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addConstructorRenames(TextChangeManager manager) throws CoreException {
ICompilationUnit cu= fType.getCompilationUnit();
IMethod[] methods= fType.getMethods();
int typeNameLength= fType.getElementName().length();
for (int i= 0; i < methods.length; i++){
if (methods[i].isConstructor()) {
/*
* constructor declarations cannot be fully qualified so we can use simple replace here
*
* if (methods[i].getNameRange() == null), then it's a binary file so it's wrong anyway
* (checked as a precondition)
*/
String name= RefactoringCoreMessages.RenameTypeRefactoring_rename_constructor;
TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(methods[i].getNameRange().getOffset(), typeNameLength, getNewElementName()));
}
}
}
示例6: removeKeys
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
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;
}
示例7: addReferenceUpdates
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
pm.beginTask("", fReferences.length); //$NON-NLS-1$
for (int i= 0; i < fReferences.length; i++){
ICompilationUnit cu= fReferences[i].getCompilationUnit();
if (cu == null)
continue;
String name= RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
SearchMatch[] results= fReferences[i].getSearchResults();
for (int j= 0; j < results.length; j++){
SearchMatch match= results[j];
ReplaceEdit replaceEdit= new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
TextChangeCompatibility.addTextEdit(manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
}
pm.worked(1);
}
}
示例8: createChange
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
/** {@inheritDoc} */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
if (fEditGroups == null || fEditGroups.length == 0) return null;
CompilationUnitChange result = new CompilationUnitChange(getDisplayString(), fCompilationUnit);
for (int i = 0; i < fEditGroups.length; i++) {
TextEdit[] edits = fEditGroups[i].getTextEdits();
String groupName = fEditGroups[i].getName();
for (int j = 0; j < edits.length; j++) {
TextChangeCompatibility.addTextEdit(result, groupName, edits[j]);
}
}
return result;
}
示例9: addTextUpdates
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addTextUpdates(ICompilationUnit cu, Set<TextMatch> matches) {
for (Iterator<TextMatch> resultIter = matches.iterator(); resultIter.hasNext(); ) {
TextMatch match = resultIter.next();
if (!match.isQualified() && fOnlyQualified) continue;
int matchStart = match.getStartPosition();
ReplaceEdit edit = new ReplaceEdit(matchStart, fCurrentNameLength, fNewName);
try {
TextChangeCompatibility.addTextEdit(
fManager.get(cu), TEXT_EDIT_LABEL, edit, TEXTUAL_MATCHES);
} catch (MalformedTreeException e) {
// conflicting update -> omit text match
}
}
}
示例10: addTypeDeclarationUpdate
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addTypeDeclarationUpdate(TextChangeManager manager) throws CoreException {
String name = RefactoringCoreMessages.RenameTypeRefactoring_update;
int typeNameLength = fType.getElementName().length();
ICompilationUnit cu = fType.getCompilationUnit();
TextChangeCompatibility.addTextEdit(
manager.get(cu),
name,
new ReplaceEdit(fType.getNameRange().getOffset(), typeNameLength, getNewElementName()));
}
示例11: rewriteImports
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
public void rewriteImports(TextChangeManager changeManager, IProgressMonitor pm)
throws CoreException {
for (Iterator<Entry<ICompilationUnit, ImportChange>> iter =
fImportChanges.entrySet().iterator();
iter.hasNext(); ) {
Entry<ICompilationUnit, ImportChange> entry = iter.next();
ICompilationUnit cu = entry.getKey();
ImportChange importChange = entry.getValue();
ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true);
importRewrite.setFilterImplicitImports(false);
for (Iterator<String> iterator = importChange.fStaticToRemove.iterator();
iterator.hasNext(); ) {
importRewrite.removeStaticImport(iterator.next());
}
for (Iterator<String> iterator = importChange.fToRemove.iterator(); iterator.hasNext(); ) {
importRewrite.removeImport(iterator.next());
}
for (Iterator<String[]> iterator = importChange.fStaticToAdd.iterator();
iterator.hasNext(); ) {
String[] toAdd = iterator.next();
importRewrite.addStaticImport(toAdd[0], toAdd[1], true);
}
for (Iterator<String> iterator = importChange.fToAdd.iterator(); iterator.hasNext(); ) {
importRewrite.addImport(iterator.next());
}
if (importRewrite.hasRecordedChanges()) {
TextEdit importEdit = importRewrite.rewriteImports(pm);
String name = RefactoringCoreMessages.RenamePackageRefactoring_update_imports;
try {
TextChangeCompatibility.addTextEdit(changeManager.get(cu), name, importEdit);
} catch (MalformedTreeException e) {
JavaPlugin.logErrorMessage(
"MalformedTreeException while processing cu " + cu); // $NON-NLS-1$
throw e;
}
}
}
}
示例12: createChange
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
pm.beginTask("", 1); // $NON-NLS-1$
try {
if (fFieldName.length() == 0) {
fFieldName = getInitialFieldName();
}
ASTRewrite rewrite = ASTRewrite.create(fCompilationUnitNode.getAST());
if (fInitializeIn == INITIALIZE_IN_METHOD && tempHasInitializer())
addLocalDeclarationSplit(rewrite);
else addLocalDeclarationRemoval(rewrite);
if (fInitializeIn == INITIALIZE_IN_CONSTRUCTOR) addInitializersToConstructors(rewrite);
addTempRenames(rewrite);
addFieldDeclaration(rewrite);
CompilationUnitChange result =
new CompilationUnitChange(
RefactoringCoreMessages.PromoteTempToFieldRefactoring_name, fCu);
result.setDescriptor(new RefactoringChangeDescriptor(getRefactoringDescriptor()));
TextEdit resultingEdits = rewrite.rewriteAST();
TextChangeCompatibility.addTextEdit(
result, RefactoringCoreMessages.PromoteTempToFieldRefactoring_editName, resultingEdits);
return result;
} finally {
pm.done();
}
}
示例13: addImportRewriteUpdates
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
private void addImportRewriteUpdates(TextChangeManager changeManager) throws CoreException {
for (Iterator<ICompilationUnit> iter = fImportRewrites.keySet().iterator(); iter.hasNext(); ) {
ICompilationUnit cu = iter.next();
ImportRewrite importRewrite = fImportRewrites.get(cu);
if (importRewrite != null && importRewrite.hasRecordedChanges()) {
TextChangeCompatibility.addTextEdit(
changeManager.get(cu),
RefactoringCoreMessages.MoveCuUpdateCreator_update_imports,
importRewrite.rewriteImports(null));
}
}
}
示例14: acceptPatternMatch
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
@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();
TextChange change = fResult.getChange(file);
TextChangeCompatibility.addTextEdit(
change,
RefactoringCoreMessages.QualifiedNameFinder_update_name,
new ReplaceEdit(start, length, fNewValue),
QUALIFIED_NAMES);
return true;
}
示例15: createChange
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
if (fEditGroups == null || fEditGroups.length == 0)
return null;
CompilationUnitChange result= new CompilationUnitChange(getDisplayString(), fCompilationUnit);
for (int i= 0; i < fEditGroups.length; i++) {
TextEdit[] edits= fEditGroups[i].getTextEdits();
String groupName= fEditGroups[i].getName();
for (int j= 0; j < edits.length; j++) {
TextChangeCompatibility.addTextEdit(result, groupName, edits[j]);
}
}
return result;
}