use of org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement in project erlide_eclipse by erlang.
the class DuplicateDetectionParser method parseDuplicates.
// { [{ {filename(), integer(), integer()} , {filename(), integer(),
// integer()} }], integer(), integer(), string()}
protected DuplicatedCodeElement parseDuplicates(final OtpErlangObject object) throws OtpErlangRangeException {
final OtpErlangTuple listElementTuple = (OtpErlangTuple) object;
final OtpErlangList duplicateCodeList = (OtpErlangList) listElementTuple.elementAt(0);
final Map<IFile, List<DuplicatedCodeInstanceElement>> values = new LinkedHashMap<>();
final OtpErlangString suggestion = (OtpErlangString) listElementTuple.elementAt(3);
final String suggStr = suggestion.stringValue();
final OtpErlangObject[] elements = duplicateCodeList.elements();
for (final OtpErlangObject element : elements) {
OtpErlangTuple elementPair = (OtpErlangTuple) element;
String replicationFunction = "";
final OtpErlangTuple checkable = (OtpErlangTuple) elementPair.elementAt(0);
if (checkable.elementAt(0) instanceof OtpErlangTuple) {
final OtpErlangString repFunStr = (OtpErlangString) elementPair.elementAt(1);
replicationFunction = repFunStr.stringValue();
elementPair = checkable;
}
final OtpErlangTuple firstElement = (OtpErlangTuple) elementPair.elementAt(0);
final OtpErlangTuple secondElement = (OtpErlangTuple) elementPair.elementAt(1);
final OtpErlangString fileName = (OtpErlangString) firstElement.elementAt(0);
final OtpErlangLong startLine = (OtpErlangLong) firstElement.elementAt(1);
final OtpErlangLong startCol = (OtpErlangLong) firstElement.elementAt(2);
final OtpErlangLong endLine = (OtpErlangLong) secondElement.elementAt(1);
final OtpErlangLong endCol = (OtpErlangLong) secondElement.elementAt(2);
final String fileNameStr = fileName.stringValue();
final IFile file = WranglerUtils.getFileFromPath(fileNameStr);
final DuplicatedCodeInstanceElement instance = new DuplicatedCodeInstanceElement(file, startLine.intValue(), startCol.intValue(), endLine.intValue(), endCol.intValue() + 1);
instance.setSuggestedCode(suggStr);
instance.setReplicationFunction(replicationFunction);
if (values.containsKey(file)) {
values.get(file).add(instance);
} else {
final List<DuplicatedCodeInstanceElement> dupList = new ArrayList<>();
dupList.add(instance);
values.put(file, dupList);
}
}
final DuplicatedCodeElement result = new DuplicatedCodeElement(values.entrySet().iterator().next().getValue().get(0));
result.setSuggestedCode(suggStr);
for (final Map.Entry<IFile, List<DuplicatedCodeInstanceElement>> entry : values.entrySet()) {
final DuplicatedFileElement dupFile = new DuplicatedFileElement(entry.getKey());
dupFile.setSuggestedCode(suggStr);
for (final DuplicatedCodeInstanceElement instance : entry.getValue()) {
dupFile.addChild(instance);
}
result.addChild(dupFile);
}
return result;
}
use of org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement in project erlide_eclipse by erlang.
the class SimilarExpressionSearchParser method parseDuplicates.
// { [{ {filename(), integer(), integer()} , {filename(), integer(),
// integer()} }], integer(), integer(), string()}
protected DuplicatedCodeElement parseDuplicates(final OtpErlangObject object) throws OtpErlangRangeException {
final OtpErlangTuple listElementTuple = (OtpErlangTuple) object;
final OtpErlangList duplicateCodeList = (OtpErlangList) listElementTuple.elementAt(0);
final Map<IFile, List<DuplicatedCodeInstanceElement>> values = new LinkedHashMap<>();
final OtpErlangString suggestion = (OtpErlangString) listElementTuple.elementAt(1);
final String suggStr = suggestion.stringValue();
final OtpErlangObject[] elements = duplicateCodeList.elements();
for (final OtpErlangObject element : elements) {
final OtpErlangTuple elementPair = (OtpErlangTuple) element;
final OtpErlangTuple firstElement = (OtpErlangTuple) elementPair.elementAt(0);
final OtpErlangTuple secondElement = (OtpErlangTuple) elementPair.elementAt(1);
final OtpErlangString fileName = (OtpErlangString) firstElement.elementAt(0);
final OtpErlangLong startLine = (OtpErlangLong) firstElement.elementAt(1);
final OtpErlangLong startCol = (OtpErlangLong) firstElement.elementAt(2);
final OtpErlangLong endLine = (OtpErlangLong) secondElement.elementAt(1);
final OtpErlangLong endCol = (OtpErlangLong) secondElement.elementAt(2);
final String fileNameStr = fileName.stringValue();
final IFile file = WranglerUtils.getFileFromPath(fileNameStr);
final DuplicatedCodeInstanceElement instance = new DuplicatedCodeInstanceElement(file, startLine.intValue(), startCol.intValue(), endLine.intValue(), endCol.intValue() + 1);
instance.setSuggestedCode(suggStr);
if (values.containsKey(file)) {
values.get(file).add(instance);
} else {
final List<DuplicatedCodeInstanceElement> dupList = new ArrayList<>();
dupList.add(instance);
values.put(file, dupList);
}
}
final DuplicatedCodeElement result = new DuplicatedCodeElement(values.entrySet().iterator().next().getValue().get(0));
result.setSuggestedCode(suggStr);
for (final Map.Entry<IFile, List<DuplicatedCodeInstanceElement>> entry : values.entrySet()) {
final DuplicatedFileElement dupFile = new DuplicatedFileElement(entry.getKey());
dupFile.setSuggestedCode(suggStr);
for (final DuplicatedCodeInstanceElement instance : entry.getValue()) {
dupFile.addChild(instance);
}
result.addChild(dupFile);
}
return result;
}
use of org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement in project erlide_eclipse by erlang.
the class DoubleClickListener method doubleClick.
@Override
public void doubleClick(final DoubleClickEvent event) {
final ISelection selection = event.getSelection();
final Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof DuplicatedCodeInstanceElement) {
higlightCodePart((DuplicatedCodeInstanceElement) obj);
} else if (obj instanceof DuplicatedCodeElement) {
higlightCodePart(((DuplicatedCodeElement) obj).getCodePart());
} else if (obj instanceof DuplicatedFileElement) {
final DuplicatedFileElement obj2 = (DuplicatedFileElement) obj;
WranglerUtils.openFile(obj2.getContainingFile());
}
}
Aggregations