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());
}
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;
}
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());
}
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;
}
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());
}
Aggregations