use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlideTestUtils method initProjects.
public static void initProjects() throws CoreException {
ErlideTestUtils.projects = Lists.newArrayList();
final IErlModel model = ErlangEngine.getInstance().getModel();
model.open(null);
final List<IErlElement> children = model.getChildren();
for (final IErlElement child : children) {
if (child instanceof IErlProject) {
final IErlProject project = (IErlProject) child;
if (project.getName().startsWith("testproject")) {
ErlideTestUtils.deleteProject(project);
}
}
}
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class DialyzerPreferencePage method doLinkActivated.
void doLinkActivated(final Link widget) {
if (isProjectPreferencePage()) {
openWorkspacePreferences(null);
} else {
final List<IProject> erlProjects = new ArrayList<>();
final Set<IProject> projectsWithSpecifics = new HashSet<>();
final IErlModel model = ErlangEngine.getInstance().getModel();
try {
for (final IErlProject ep : model.getErlangProjects()) {
final IProject p = ep.getWorkspaceProject();
if (hasProjectSpecificOptions(p)) {
projectsWithSpecifics.add(p);
}
erlProjects.add(p);
}
} catch (final ErlModelException e) {
}
final ProjectSelectionDialog dialog = new ProjectSelectionDialog(getShell(), erlProjects, projectsWithSpecifics);
if (dialog.open() == Window.OK) {
final IProject res = (IProject) dialog.getFirstResult();
openProjectProperties(res);
}
}
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class OpenUtils method findLocalCall.
private IErlElement findLocalCall(final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlElement element, final IErlElementLocator.Scope scope) throws RpcException, CoreException {
if (isTypeDefOrRecordDef(element, res)) {
return modelFindService.findTypespec(module, res.getFun());
}
final IErlFunction foundElement = module.findFunction(res.getFunction());
if (foundElement != null) {
return foundElement;
}
// imported functions
OtpErlangObject res2 = null;
String moduleName = null;
final IErlImport ei = module.findImport(res.getFunction());
if (ei != null) {
final IErlModel model = ErlangEngine.getInstance().getModel();
moduleName = ei.getImportModule();
res2 = ErlangEngine.getInstance().getOpenService().getSourceFromModule(model.getPathVars(), moduleName, erlProject.getProperties().getExternalModules());
}
if (res2 instanceof OtpErlangString && moduleName != null) {
// imported from otp module
final OtpErlangString otpErlangString = (OtpErlangString) res2;
final String modulePath = otpErlangString.stringValue();
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
return modelFindService.findFunction(model, erlProject, module, moduleName, modulePath, res.getFunction(), scope);
}
// functions defined in include files
final Collection<IErlModule> allIncludedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
for (final IErlModule includedModule : allIncludedFiles) {
final IErlFunction function = includedModule.findFunction(res.getFunction());
if (function != null) {
return function;
}
}
return null;
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlStructureCreator method createStructureComparator.
@Override
protected IStructureComparator createStructureComparator(final Object element, final IDocument document0, final ISharedDocumentAdapter sharedDocumentAdapter, final IProgressMonitor monitor) throws CoreException {
IErlModule module = null;
final IErlModel model = ErlangEngine.getInstance().getModel();
String s = "";
IDocument document = document0;
if (element instanceof ResourceNode) {
final ResourceNode rn = (ResourceNode) element;
final IResource r = rn.getResource();
if (r instanceof IFile) {
final IFile f = (IFile) r;
final IErlElement e = model.findElement(r);
if (e instanceof IErlModule) {
module = (IErlModule) e;
}
if (document == null) {
try {
s = ErlStructureCreator.readString(f.getContents());
document = new Document(s);
} catch (final CoreException e1) {
}
}
}
} else if (document == null && element instanceof IStreamContentAccessor) {
try {
try (final InputStream contents = ((IStreamContentAccessor) element).getContents()) {
s = ErlStructureCreator.readString(contents);
} catch (final IOException e) {
}
document = new Document(s);
} catch (final CoreException ex) {
}
} else if (document != null) {
s = document.get();
}
if (module == null) {
String name = "comptemp";
if (element instanceof ITypedElement) {
final ITypedElement typedElement = (ITypedElement) element;
name = typedElement.getName();
}
module = model.getModuleFromText(model, name, s, null);
}
ErlNode root = null;
if (element != null && document != null) {
try {
module.open(null);
root = new RootErlNode(document, element);
recursiveMakeErlNodes(module, root, document);
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
return root;
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlangExternalsContentProvider method hasChildren.
@Override
public boolean hasChildren(final Object element0) {
Object element = element0;
if (element instanceof IProject) {
final IProject project = (IProject) element;
if (project.isOpen()) {
element = ErlangEngine.getInstance().getModel().findProject(project);
}
}
if (element instanceof IErlModule) {
return erlangFileContentProvider.hasChildren(element);
}
if (element instanceof IParent) {
if (element instanceof IErlExternalRoot || element instanceof IErlProject || element instanceof IErlModel) {
// we know these have children
return true;
}
final Stopwatch clock = Stopwatch.createStarted();
if (element instanceof IOpenable) {
final IOpenable openable = (IOpenable) element;
try {
openable.open(null);
} catch (final ErlModelException e) {
}
}
final IParent parent = (IParent) element;
final boolean result = parent.hasChildrenOfKind(ErlElementKind.EXTERNAL_ROOT, ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER, ErlElementKind.MODULE);
if (clock.elapsed(TimeUnit.MILLISECONDS) > 100) {
ErlLogger.debug("TIME open " + element.getClass() + " " + element + " " + clock.elapsed(TimeUnit.MILLISECONDS) + " ms");
}
return result;
}
return false;
}
Aggregations