Search in sources :

Example 11 with IErlModel

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);
            }
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel)

Example 12 with IErlModel

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) ProjectSelectionDialog(org.erlide.ui.prefs.ProjectSelectionDialog) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Example 13 with IErlModel

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;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 14 with IErlModel

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) InputStream(java.io.InputStream) ITypedElement(org.eclipse.compare.ITypedElement) IOException(java.io.IOException) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ResourceNode(org.eclipse.compare.ResourceNode) IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource)

Example 15 with IErlModel

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;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IOpenable(org.erlide.engine.model.root.IOpenable) IErlModel(org.erlide.engine.model.root.IErlModel) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) IErlExternalRoot(org.erlide.engine.model.root.IErlExternalRoot) IErlModule(org.erlide.engine.model.root.IErlModule) Stopwatch(com.google.common.base.Stopwatch) IProject(org.eclipse.core.resources.IProject)

Aggregations

IErlModel (org.erlide.engine.model.root.IErlModel)36 IErlModule (org.erlide.engine.model.root.IErlModule)18 IErlProject (org.erlide.engine.model.root.IErlProject)13 IFile (org.eclipse.core.resources.IFile)11 ErlModelException (org.erlide.engine.model.ErlModelException)11 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)8 IErlElement (org.erlide.engine.model.IErlElement)8 IResource (org.eclipse.core.resources.IResource)7 IPath (org.eclipse.core.runtime.IPath)5 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IBackend (org.erlide.backend.api.IBackend)3 OpenResult (org.erlide.engine.services.search.OpenResult)3 File (java.io.File)2 IOException (java.io.IOException)2 IContainer (org.eclipse.core.resources.IContainer)2