use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class HandleEdocLinksLocationListener method changing.
@Override
public void changing(final LocationEvent event) {
ErlangBrowserInformationControlInput input = null;
if (control != null) {
input = control.getInput();
} else if (edocView != null) {
input = edocView.getInput();
}
if (input != null) {
final AbstractErlangEditor editor = input.getEditor();
String moduleName = "";
final Object inputElement = input.getInputElement();
if (inputElement instanceof OpenResult) {
final OpenResult or = (OpenResult) inputElement;
moduleName = or.getName();
}
final ErlangFunctionCall functionCall = HoverUtil.eventToErlangFunctionCall(moduleName, event);
if (functionCall != null) {
final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(editor.getModule());
if (project == null) {
return;
}
final IOtpRpc backend = BackendCore.getBuildBackend(project);
final OtpErlangTuple otpDoc = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, functionCall);
if (Util.isOk(otpDoc)) {
final String docStr = Util.stringValue(otpDoc.elementAt(1));
final StringBuffer result = new StringBuffer(docStr);
String docPath = "";
String anchor = "";
if (otpDoc.arity() > 4) {
docPath = Util.stringValue(otpDoc.elementAt(3));
anchor = Util.stringValue(otpDoc.elementAt(4));
}
if (result.length() > 0) {
final String html = HoverUtil.getHTML(result);
final Object element = new OpenResult(otpDoc.elementAt(2));
input = new ErlangBrowserInformationControlInput(input, editor, element, html, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
}
}
}
if (input != null) {
if (control != null) {
if (control.hasDelayedInputChangeListener()) {
control.notifyDelayedInputChange(input);
} else {
control.setInput(input);
}
} else if (edocView != null) {
edocView.setInfo(input);
}
}
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class AbstractErlSelection method getSearchPath.
@Override
public OtpErlangList getSearchPath() {
final IProject project = file.getProject();
final IErlModel model = ErlangEngine.getInstance().getModel();
final IErlProject actualProject = model.getErlangProject(project);
final IPath projectLocation = actualProject.getWorkspaceProject().getLocation();
final Collection<IPath> sourcDirs = actualProject.getProperties().getSourceDirs();
final OtpErlangString[] searchPath = new OtpErlangString[sourcDirs.size()];
int i = 0;
for (final IPath src : sourcDirs) {
searchPath[i++] = new OtpErlangString(projectLocation.append(src).toOSString());
}
return new OtpErlangList(searchPath);
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class IErlModelTest method findIncludeFromModule.
// IErlModule findIncludeFromModule(IErlModule module, String includeName,
// String includePath, Scope scope) throws ErlModelException;
@Test
public void findIncludeFromModule() throws Exception {
File externalIncludeFile = null;
final IErlProject myProject = ErlModelTestBase.projects[0];
final IProject workspaceProject = myProject.getWorkspaceProject();
final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
final Collection<IPath> includeDirs = myProject.getProperties().getIncludeDirs();
// directory as the module
try {
final String xxHrl = "xx.hrl";
externalIncludeFile = ErlideTestUtils.createTmpFile(xxHrl, "-record(rec2, {field, another=def}.");
final String externalIncludePath = externalIncludeFile.getAbsolutePath();
final IPath p = new Path(externalIncludePath).removeLastSegments(1);
final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
newIncludeDirs.add(p);
((ErlProject) myProject).setIncludeDirs(newIncludeDirs);
final IErlModule include = ErlideTestUtils.createInclude(myProject, "yy.hrl", "-define(Y, include).\n");
final IErlProject project1 = ErlModelTestBase.projects[1];
final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, "zz.hrl", "-define(Z, referenced).\n");
final IErlModule includeInModuleDir = ErlideTestUtils.createModule(myProject, "ww.hrl", "-define(WW, x).\n");
myProject.open(null);
// when
// looking for includes
final String xx = "xx";
final IErlModule x1 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule x2 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule x3 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String yy = "yy";
final IErlModule y1 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule y2 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule y3 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String zz = "zz";
final IErlModule z1 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z2 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z3 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
workspaceProject.setDescription(description, null);
myProject.open(null);
final IErlModule z4 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z5 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z6 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String ww = "ww";
final IErlModule w1 = model.findIncludeFromModule(module, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlElementLocator mymodel = ErlangEngine.getInstance().getModel();
final IErlModule w2 = mymodel.findIncludeFromProject(myProject, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
// then
// scope should be respected
assertNotNull(x1);
assertEquals(xxHrl, x1.getName());
assertNotNull(x2);
assertEquals(xxHrl, x2.getName());
assertNotNull(x3);
assertEquals(xxHrl, x3.getName());
assertEquals(include, y1);
assertEquals(include, y2);
assertEquals(include, y3);
assertNull(z1);
assertEquals(referencedInclude, z2);
assertNull(z3);
assertNull(z4);
assertEquals(referencedInclude, z5);
assertEquals(referencedInclude, z6);
assertEquals(includeInModuleDir, w1);
assertNull(w2);
} finally {
if (externalIncludeFile != null && externalIncludeFile.exists()) {
externalIncludeFile.delete();
}
((ErlProject) myProject).setIncludeDirs(includeDirs);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(referencedProjects);
workspaceProject.setDescription(description, null);
}
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class IErlModelTest method findModuleFromProject.
// enum Scope {
// PROJECT_ONLY, REFERENCED_PROJECTS, ALL_PROJECTS
// }
// IErlModule findModuleFromProject(IErlProject project, String moduleName,
// String modulePath, Scope scope) throws ErlModelException;
@Test
public void findModuleFromProject() throws Exception {
File externalModuleFile = null;
File externalsFile = null;
final IErlProject aProject = ErlModelTestBase.projects[0];
final IProject workspaceProject = aProject.getWorkspaceProject();
final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
final String externalModulesString = aProject.getProperties().getExternalModules();
// referenced project with a module
try {
final String xxErl = "xx.erl";
externalModuleFile = ErlideTestUtils.createTmpFile(xxErl, "-module(xx).\n");
final String externalModulePath = externalModuleFile.getAbsolutePath();
externalsFile = ErlideTestUtils.createTmpFile(IErlModelTest.XX_ERLIDEX, externalModulePath);
((ErlProject) aProject).setExternalModulesFile(externalsFile.getAbsolutePath());
final IErlModule aModule = ErlideTestUtils.createModule(aProject, "yy.erl", "-module(yy).\n");
final IErlProject project1 = ErlModelTestBase.projects[1];
final IErlModule referencedModule = ErlideTestUtils.createModule(project1, "zz.erl", "-module(zz).\n");
aProject.open(null);
// when
// looking for modules
final String xx = "xx";
final IErlModule x1 = model.findModuleFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule x2 = model.findModuleFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule x3 = model.findModuleFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String yy = "yy";
final IErlModule y1 = model.findModuleFromProject(aProject, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule y2 = model.findModuleFromProject(aProject, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule y3 = model.findModuleFromProject(aProject, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IErlModule y4 = model.findModuleFromProject(project1, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule y5 = model.findModuleFromProject(project1, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule y6 = model.findModuleFromProject(project1, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final String zz = "zz";
final IErlModule z1 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z2 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z3 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
workspaceProject.setDescription(description, null);
aProject.open(null);
final IErlModule z4 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule z5 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule z6 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
// then
// scope should be respected
assertNotNull(x1);
assertEquals(xxErl, x1.getName());
assertNotNull(x2);
assertEquals(xxErl, x2.getName());
assertNotNull(x3);
assertEquals(xxErl, x3.getName());
assertEquals(aModule, y1);
assertEquals(aModule, y2);
assertEquals(aModule, y3);
assertNull(y4);
assertEquals(aModule, y5);
assertNull(y6);
assertNull(z1);
assertEquals(referencedModule, z2);
assertNull(z3);
assertNull(z4);
assertEquals(referencedModule, z5);
assertEquals(referencedModule, z6);
} finally {
if (externalModuleFile != null && externalModuleFile.exists()) {
externalModuleFile.delete();
}
if (externalsFile != null && externalsFile.exists()) {
externalsFile.delete();
}
((ErlProject) aProject).setExternalModulesFile(externalModulesString);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(referencedProjects);
workspaceProject.setDescription(description, null);
}
}
use of org.erlide.engine.model.root.IErlProject in project erlide_eclipse by erlang.
the class IErlModelTest method findModuleFromProject_preferProjectFile.
@Test
public void findModuleFromProject_preferProjectFile() throws Exception {
File externalModuleFile = null;
File externalsFile = null;
final IErlProject aProject = ErlModelTestBase.projects[0];
final IProject workspaceProject = aProject.getWorkspaceProject();
final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
final String externalModulesString = aProject.getProperties().getExternalModules();
// referenced project with an include, both have same name
try {
final String zzErl = "zz.erl";
final String xxxContents = "-module(zz).\n";
externalModuleFile = ErlideTestUtils.createTmpFile(zzErl, xxxContents);
final String externalModulePath = externalModuleFile.getAbsolutePath();
externalsFile = ErlideTestUtils.createTmpFile(IErlModelTest.XX_ERLIDEX, externalModulePath);
((ErlProject) aProject).setExternalModulesFile(externalsFile.getAbsolutePath());
final IErlProject project1 = ErlModelTestBase.projects[1];
final IErlModule referencedModule = ErlideTestUtils.createModule(project1, zzErl, xxxContents);
aProject.open(null);
// when
// looking for module
final String zz = "zz";
final IErlModule zz1 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule zz2 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule zz3 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
workspaceProject.setDescription(description, null);
aProject.open(null);
final IErlModule zz4 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
final IErlModule zz5 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
final IErlModule zz6 = model.findModuleFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
// then
// the non-external should be preferred
assertNotNull(zz1);
assertEquals(zzErl, zz1.getName());
assertNotSame(referencedModule, zz1);
assertEquals(referencedModule, zz2);
assertNotNull(zz3);
assertEquals(zzErl, zz3.getName());
assertNotSame(referencedModule, zz3);
assertNotNull(zz4);
assertNotSame(referencedModule, zz4);
assertEquals(referencedModule, zz5);
assertEquals(referencedModule, zz6);
} finally {
if (externalModuleFile != null && externalModuleFile.exists()) {
externalModuleFile.delete();
}
if (externalsFile != null && externalsFile.exists()) {
externalsFile.delete();
}
final IProjectDescription description = workspaceProject.getDescription();
description.setReferencedProjects(referencedProjects);
workspaceProject.setDescription(description, null);
((ErlProject) aProject).setExternalModulesFile(externalModulesString);
}
}
Aggregations