Search in sources :

Example 16 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class DuplicateDetectionAction method callRefactoring.

@SuppressWarnings("boxing")
@Override
protected IResultParser callRefactoring() throws WranglerRpcParsingException, CoreException, IOException, WranglerWarningException {
    String functionName;
    RpcResult result;
    // getting the path of the fragment
    final String suffixPath = getSuffixPath();
    ErlLogger.debug("Suffix binary at: " + suffixPath);
    final WranglerRefactoringBackend backend = WranglerBackendManager.getRefactoringBackend();
    final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
    if (onlyInfile) {
        functionName = "duplicated_code_eclipse";
        final OtpErlangString fp = new OtpErlangString(sel.getFilePath());
        final OtpErlangString[] fpa = new OtpErlangString[1];
        fpa[0] = fp;
        final OtpErlangList fpl = new OtpErlangList(fpa);
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiis", fpl, minToks, minClones, GlobalParameters.getTabWidth(), suffixPath);
    } else {
        functionName = "duplicated_code_eclipse";
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiis", sel.getSearchPath(), minToks, minClones, GlobalParameters.getTabWidth(), suffixPath);
    }
    if (!result.isOk()) {
        throw new WranglerRpcParsingException("Rpc error");
    }
    return new DuplicateDetectionParser(result.getValue());
}
Also used : WranglerRefactoringBackend(org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 17 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString 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 18 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class SimilarDetectionAction method callRefactoring.

@Override
protected IResultParser callRefactoring() throws WranglerRpcParsingException, CoreException, IOException, WranglerWarningException {
    final WranglerRefactoringBackend backend = WranglerBackendManager.getRefactoringBackend();
    final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
    RpcResult result;
    final String functionName = "sim_code_detection_eclipse";
    if (onlyInFile) {
        final OtpErlangString fp = new OtpErlangString(sel.getFilePath());
        final OtpErlangString[] fpa = new OtpErlangString[1];
        fpa[0] = fp;
        final OtpErlangList fpl = new OtpErlangList(fpa);
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiiidxi", fpl, minLen, minToks, minFreq, maxNewVars, simScore, sel.getSearchPath(), GlobalParameters.getTabWidth());
    } else {
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiiidxi", sel.getSearchPath(), minLen, minToks, minFreq, maxNewVars, simScore, sel.getSearchPath(), GlobalParameters.getTabWidth());
    }
    if (!result.isOk()) {
        throw new WranglerRpcParsingException("Rpc error");
    }
    return new DuplicateDetectionParser(result.getValue());
}
Also used : WranglerRefactoringBackend(org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 19 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString 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 20 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class UserRefactoringsManager method scanForUserRefactorings.

/**
 * Looks for user defined refactorings (in order to generate menu items for
 * them)
 */
@SuppressWarnings("rawtypes")
private void scanForUserRefactorings() {
    elementaryRefacs = new LinkedList<>();
    compositeRefacs = new LinkedList<>();
    myElementaryRefacs = new LinkedList<>();
    myCompositeRefacs = new LinkedList<>();
    final Bundle coreBundle = Platform.getBundle(Activator.CORE_ID);
    final Enumeration modules = coreBundle.findEntries("wrangler/ebin", "*.beam", false);
    // modules that origin from repository
    final List<OtpErlangObject> erlModules = new LinkedList<>();
    while (modules != null && modules.hasMoreElements()) {
        final String next = modules.nextElement().toString();
        final String module = next.substring(next.lastIndexOf('/') + 1, next.lastIndexOf('.'));
        erlModules.add(new OtpErlangString(module));
    }
    RpcResult res = WranglerBackendManager.getRefactoringBackend().callWithoutParser("get_user_refactorings", "x", new OtpErlangList(erlModules.toArray(new OtpErlangObject[0])));
    if (res.isOk() && res.getValue() instanceof OtpErlangList) {
        final OtpErlangList genRefac = (OtpErlangList) ((OtpErlangTuple) ((OtpErlangList) res.getValue()).elementAt(0)).elementAt(1);
        final OtpErlangList genCompositeRefac = (OtpErlangList) ((OtpErlangTuple) ((OtpErlangList) res.getValue()).elementAt(1)).elementAt(1);
        for (final OtpErlangObject obj : genRefac) {
            elementaryRefacs.add(new UserRefactoringInfo(obj.toString()));
        }
        for (final OtpErlangObject obj : genCompositeRefac) {
            compositeRefacs.add(new UserRefactoringInfo(obj.toString()));
        }
    }
    ErlLogger.info("Refac modules found " + res.toString());
    // user's own refactoring
    final Enumeration userModules = coreBundle.findEntries("wrangler/ebin/my_gen_refac", "*.beam", false);
    while (userModules != null && userModules.hasMoreElements()) {
        final String next = userModules.nextElement().toString();
        myElementaryRefacs.add(new UserRefactoringInfo(next.substring(next.lastIndexOf('/') + 1, next.lastIndexOf('.'))));
    }
    // user's own composite refactorings
    final Enumeration userCompositeModules = coreBundle.findEntries("wrangler/ebin/my_gen_composite_refac", "*.beam", false);
    while (userCompositeModules != null && userCompositeModules.hasMoreElements()) {
        final String next = userCompositeModules.nextElement().toString();
        myCompositeRefacs.add(new UserRefactoringInfo(next.substring(next.lastIndexOf('/') + 1, next.lastIndexOf('.'))));
    }
    // load refactorings
    res = WranglerBackendManager.getRefactoringBackend().callWithoutParser("load_user_refactorings", "s", getEbinPath());
    ErlLogger.debug(res.toString());
}
Also used : Enumeration(java.util.Enumeration) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) Bundle(org.osgi.framework.Bundle) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) LinkedList(java.util.LinkedList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Aggregations

OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)56 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)36 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)31 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)22 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)15 ArrayList (java.util.ArrayList)9 RpcResult (org.erlide.runtime.rpc.RpcResult)8 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)7 RpcException (org.erlide.runtime.rpc.RpcException)7 Test (org.junit.Test)7 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)6 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)5 IPath (org.eclipse.core.runtime.IPath)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 IErlElement (org.erlide.engine.model.IErlElement)5 WranglerRpcParsingException (org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)5 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)5 CoreException (org.eclipse.core.runtime.CoreException)4 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)4 Map (java.util.Map)3