本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility类的典型用法代码示例。如果您正苦于以下问题:Java TextChangeCompatibility类的具体用法?Java TextChangeCompatibility怎么用?Java TextChangeCompatibility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextChangeCompatibility类属于org.eclipse.jdt.internal.corext.refactoring.changes包,在下文中一共展示了TextChangeCompatibility类的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: 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()));
}
}
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: 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;
}
示例9: addReplaceEdits
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入依赖的package包/类
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);
}
}
}
}
示例10: addAccessor
import org.eclipse.jdt.internal.corext.refactoring.changes.TextChangeCompatibility; //导入依赖的package包/类
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);
}
}
示例11: 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;
}
示例12: 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
}
}
}
示例13: 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()));
}
示例14: 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;
}
}
}
}
示例15: 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();
}
}