use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class SearchTest method findCallAfterRecordRef.
@Test
public void findCallAfterRecordRef() throws Exception {
// given
// a module a with an exported function f
// and a module b which calls a:f()
final IErlModule moduleA = ErlideTestUtils.createModule(SearchTest.projects[0], "a.erl", "-module(a).\n-export([f/0]).\nf() ->\n ok.\n");
final IErlModule moduleB = ErlideTestUtils.createModule(SearchTest.projects[0], "b.erl", "-module(b).\n-export([f/0]).\nf() ->\n #a.b,\n a:f().\n");
moduleA.open(null);
moduleB.open(null);
// when
// searching for the call to a:f
final ErlangSearchPattern ref = new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPattern(SearchFor.FUNCTION, "a", "f", 0, LimitTo.REFERENCES, moduleA);
final ErlSearchScope scope = new ErlSearchScope(moduleA);
scope.addModule(moduleB);
final ErlSearchQuery query = new ErlSearchQuery(ref, scope, "");
query.run(new NullProgressMonitor());
// then
// it should be found in module b
final ErlangSearchResult searchResult = (ErlangSearchResult) query.getSearchResult();
assertEquals(1, searchResult.getMatchCount());
final List<ErlangSearchElement> result = searchResult.getResult();
assertTrue(hasModule(moduleB, result));
assertFalse(hasModule(moduleA, result));
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class SearchTest method findExternalCallsTestAux.
private void findExternalCallsTestAux(final LimitTo limitTo, final int nFoundExpected) throws CoreException, ErlModelException, OperationCanceledException {
// given
// a module a with an exported function f
// and a module b which calls a:f()
final IErlModule moduleA = ErlideTestUtils.createModule(SearchTest.projects[0], "a.erl", "-module(a).\n-export([f/0]).\nf() ->\n ok.\n");
final IErlModule moduleB = ErlideTestUtils.createModule(SearchTest.projects[0], "b.erl", "-module(b).\n-export([f/0]).\nf() ->\n a:f().\n");
moduleA.open(null);
moduleB.open(null);
// when
// searching for the call to a:f
final ErlangSearchPattern ref = new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPattern(SearchFor.FUNCTION, "a", "f", 0, limitTo, moduleA);
final ErlSearchScope scope = new ErlSearchScope(moduleA);
scope.addModule(moduleB);
final ErlSearchQuery query = new ErlSearchQuery(ref, scope, "");
query.run(new NullProgressMonitor());
// then
// it should be found in module b
final ErlangSearchResult searchResult = (ErlangSearchResult) query.getSearchResult();
assertEquals(nFoundExpected, searchResult.getMatchCount());
final List<ErlangSearchElement> result = searchResult.getResult();
if (limitTo == LimitTo.REFERENCES) {
// f is only referred in moduleB, but declarations matches in any
// module as long as arity and name are equal
assertFalse(hasModule(moduleA, result));
} else {
assertTrue(hasModule(moduleA, result));
}
assertTrue(hasModule(moduleB, result));
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class GlobalParameters method setSelection.
/**
* Stores a selection marked 'current'
*
* @param selection
* Erlang selection
*/
public static void setSelection(final ISelection selection) throws WranglerException {
// TODO:: if the module is selected it is not handled
try {
if (GlobalParameters.editor == null) {
final IWorkbench instance = PlatformUI.getWorkbench();
final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
}
if (selection instanceof ITextSelection) {
final IWorkbench instance = PlatformUI.getWorkbench();
final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
GlobalParameters.wranglerSelection = new ErlTextMemberSelection((ITextSelection) selection, (ITextEditor) GlobalParameters.editor);
} else if (selection instanceof ITreeSelection) {
final Object firstElement = ((ITreeSelection) selection).getFirstElement();
if (firstElement instanceof IErlElement) {
final IErlElement element = (IErlElement) firstElement;
final IFile file = (IFile) element.getResource();
GlobalParameters.wranglerSelection = new ErlMemberSelection(element, file, WranglerUtils.getDocument(file));
} else if (firstElement instanceof IFile) {
final IFile file = (IFile) firstElement;
final IErlModule module = ErlangEngine.getInstance().getModel().findModule(file);
GlobalParameters.wranglerSelection = new ErlModuleSelection(module, file);
} else {
GlobalParameters.wranglerSelection = null;
throw new WranglerException("Please select an Erlang element!");
}
} else {
GlobalParameters.wranglerSelection = null;
throw new WranglerException("Please select an Erlang element!");
}
} catch (final ClassCastException e) {
ErlLogger.error(e);
}
/*
* System.out.println(wranglerSelection.getStartLine() + "," +
* wranglerSelection.getStartCol() + ";" +
* wranglerSelection.getEndLine() + "," +
* wranglerSelection.getEndCol());
*/
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class WranglerUtils method highlightSelection.
/**
* Highlights the given function clause
*
* @param clause
* erlang function clause
*/
public static void highlightSelection(final IErlFunctionClause clause) {
int offset;
int length;
offset = clause.getNameRange().getOffset();
length = clause.getNameRange().getLength();
final IErlModule module = ErlangEngine.getInstance().getModelUtilService().getModule(clause);
final IEditorPart editor = WranglerUtils.openFile((IFile) module.getResource());
WranglerUtils.highlightSelection(offset, length, (ITextEditor) editor);
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method extractModule.
private IErlModule extractModule(final OtpErlangObject m) throws ErlModelException {
String name = "";
if (m instanceof OtpErlangString) {
final OtpErlangString element = (OtpErlangString) m;
name = element.stringValue();
} else if (m instanceof OtpErlangAtom) {
final OtpErlangAtom atom = (OtpErlangAtom) m;
name = atom.atomValue();
}
final String[] modNameParts = name.split("/");
final IErlModule mod = ErlangEngine.getInstance().getModel().findModule(modNameParts[modNameParts.length - 1]);
return mod;
}
Aggregations