use of org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement 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.DuplicatedCodeInstanceElement in project erlide_eclipse by erlang.
the class ExpressionSearchParser method parse.
@Override
public void parse(final OtpErlangObject object) {
try {
final OtpErlangTuple res = (OtpErlangTuple) object;
if (!"ok".equals(res.elementAt(0).toString())) {
setUnSuccessful(((OtpErlangString) res.elementAt(1)).stringValue());
return;
}
if (res.elementAt(1).equals(new OtpErlangList())) {
setUnSuccessful("No more instances found!");
return;
}
final OtpErlangList posList = (OtpErlangList) res.elementAt(1);
OtpErlangTuple actPos;
OtpErlangLong startLine;
OtpErlangLong startColumn;
OtpErlangLong endLine;
OtpErlangLong endColumn;
final List<DuplicatedCodeInstanceElement> instances = new ArrayList<>();
for (final OtpErlangObject aPosList : posList) {
actPos = (OtpErlangTuple) aPosList;
startLine = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(0)).elementAt(0);
startColumn = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(0)).elementAt(1);
endLine = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(1)).elementAt(0);
endColumn = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(1)).elementAt(1);
final IErlSelection sel = GlobalParameters.getWranglerSelection();
instances.add(new DuplicatedCodeInstanceElement((IFile) sel.getErlElement().getResource(), startLine.intValue(), startColumn.intValue(), endLine.intValue(), endColumn.intValue() + 1));
}
final DuplicatedCodeInstanceElement defaultInstance = instances.get(0);
final DuplicatedCodeElement result = new DuplicatedCodeElement(defaultInstance);
for (final DuplicatedCodeInstanceElement instance : instances) {
result.addChild(instance);
}
isSuccessful = true;
errorMessage = null;
duplicates = new ArrayList<>();
duplicates.add(result);
} catch (final Exception e) {
setUnSuccessful(e.getMessage());
}
}
use of org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement 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.DuplicatedCodeInstanceElement 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());
}
}
use of org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement in project erlide_eclipse by erlang.
the class DuplicatesView method makeActions.
private void makeActions() {
copyGeneralisedToClipboard = new ClipboardAction(PlatformUI.getWorkbench().getDisplay());
copyGeneralisedToClipboard.setToolTipText("Copy generalised function to the clipboard");
copyGeneralisedToClipboard.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
copyFunCallToClipboard.setToolTipText("Copy FunCall to the clipboard");
copyFunCallToClipboard.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
final ISelection sel = event.getSelection();
if (sel == null || sel.isEmpty()) {
return;
}
final TreeSelection tsel = (TreeSelection) sel;
final AbstractResultTreeObject selection = (AbstractResultTreeObject) tsel.getFirstElement();
copyGeneralisedToClipboard.setText(selection.getSuggestedCode());
if (selection instanceof DuplicatedCodeInstanceElement) {
final DuplicatedCodeInstanceElement dcie = (DuplicatedCodeInstanceElement) selection;
copyFunCallToClipboard.setText(dcie.getReplicationFunction());
}
}
});
}
Aggregations