Search in sources :

Example 1 with DuplicatedFileElement

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ArrayList(java.util.ArrayList) DuplicatedCodeElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeElement) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) LinkedHashMap(java.util.LinkedHashMap) DuplicatedFileElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) List(java.util.List) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) DuplicatedCodeInstanceElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 2 with DuplicatedFileElement

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ArrayList(java.util.ArrayList) DuplicatedCodeElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeElement) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) LinkedHashMap(java.util.LinkedHashMap) DuplicatedFileElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) List(java.util.List) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) DuplicatedCodeInstanceElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 3 with DuplicatedFileElement

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());
    }
}
Also used : DuplicatedFileElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement) ISelection(org.eclipse.jface.viewers.ISelection) DuplicatedCodeElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DuplicatedCodeInstanceElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement)

Aggregations

DuplicatedCodeElement (org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeElement)3 DuplicatedCodeInstanceElement (org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement)3 DuplicatedFileElement (org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedFileElement)3 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 IFile (org.eclipse.core.resources.IFile)2 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1