use of org.python.pydev.ast.codecompletion.revisited.modules.ASTEntryWithSourceModule in project Pydev by fabioz.
the class RefactoringRenameTestBase method asStr.
@SuppressWarnings("unchecked")
protected String asStr(Map<Tuple<String, File>, HashSet<ASTEntry>> referencesForModuleRename) throws Exception {
Set<Entry<Tuple<String, File>, HashSet<ASTEntry>>> entrySet = referencesForModuleRename.entrySet();
FastStringBuffer buf = new FastStringBuffer();
ArrayList<Entry<Tuple<String, File>, HashSet<ASTEntry>>> lst = new ArrayList<>(entrySet);
Comparator<Entry<Tuple<String, File>, HashSet<ASTEntry>>> c = new Comparator<Entry<Tuple<String, File>, HashSet<ASTEntry>>>() {
@Override
public int compare(Entry<Tuple<String, File>, HashSet<ASTEntry>> o1, Entry<Tuple<String, File>, HashSet<ASTEntry>> o2) {
return o1.getKey().o1.compareTo(o2.getKey().o1);
}
};
Collections.sort(lst, c);
for (Entry<Tuple<String, File>, HashSet<ASTEntry>> entry : lst) {
HashSet<ASTEntry> value = entry.getValue();
if (value.size() > 0) {
ArrayList<ASTEntry> lst2 = new ArrayList<>(value);
Comparator<ASTEntry> c2 = new Comparator<ASTEntry>() {
@Override
public int compare(ASTEntry o1, ASTEntry o2) {
return o1.toString().compareTo(o2.toString());
}
};
Collections.sort(lst2, c2);
File f = entry.getKey().o2;
String fileContents = FileUtils.getFileContents(f);
Document initialDoc = new Document(fileContents);
buf.append(entry.getKey().o1).append("\n");
for (ASTEntry e : lst2) {
buf.append(" ");
buf.append(e.toString()).append("\n");
List<TextEdit> edits = (List<TextEdit>) e.getAdditionalInfo(AstEntryScopeAnalysisConstants.AST_ENTRY_REPLACE_EDIT, null);
if (edits == null) {
if (!(e instanceof ASTEntryWithSourceModule)) {
throw new AssertionError("Only ASTEntryWithSourceModule can have null edits. Found: " + e);
}
} else {
Document changedDoc = new Document(fileContents);
for (TextEdit textEdit : edits) {
textEdit.apply(changedDoc);
}
List<String> changedLines = getChangedLines(initialDoc, changedDoc);
for (String i : changedLines) {
buf.append(" ");
buf.append(StringUtils.rightTrim(i)).append("\n");
}
}
}
buf.append("\n");
}
}
return buf.toString();
}
use of org.python.pydev.ast.codecompletion.revisited.modules.ASTEntryWithSourceModule in project Pydev by fabioz.
the class PyRenameImportProcess method onModuleRenameRefactoringRequest.
private void onModuleRenameRefactoringRequest(RefactoringRequest request) {
moduleToFind = (SourceModule) request.getModule();
List<ASTEntry> lst = new ArrayList<ASTEntry>();
lst.add(new ASTEntryWithSourceModule(moduleToFind));
addOccurrences(lst, moduleToFind.getFile(), moduleToFind.getName());
}
Aggregations