Search in sources :

Example 6 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class ErlTextHover method internalGetHoverInfo.

private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
    if (editor == null) {
        return null;
    }
    final StringBuffer result = new StringBuffer();
    OpenResult element = null;
    // TODO our model is too coarse, here we need access to expressions
    final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
    final int offset = hoverRegion.getOffset();
    final int length = hoverRegion.getLength();
    final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
    if (!debuggerVar.isEmpty()) {
        result.append(debuggerVar);
    }
    final IErlProject erlProject = editor.getProject();
    String docPath = "";
    String anchor = "";
    try {
        if (erlProject == null) {
            return null;
        }
        final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
        if (backend == null) {
            return null;
        }
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final String externalModulesString = erlProject.getProperties().getExternalModules();
        final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
        if (Util.isOk(t)) {
            element = new OpenResult(t.elementAt(2));
            final String docStr = Util.stringValue(t.elementAt(1));
            result.append(docStr);
            if (t.arity() > 4) {
                docPath = Util.stringValue(t.elementAt(3));
                anchor = Util.stringValue(t.elementAt(4));
            }
        } else {
            element = new OpenResult(t);
            final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
            if (found instanceof IErlFunction) {
                final IErlFunction function = (IErlFunction) found;
                final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
                if (comment.isEmpty()) {
                    return null;
                }
                result.append(comment);
            } else if (found instanceof IErlPreprocessorDef) {
                final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
                result.append(preprocessorDef.getExtra());
            }
        }
    } catch (final Exception e) {
        ErlLogger.warn(e);
        return null;
    }
    final String strResult = HoverUtil.getHTML(result);
    return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Point(org.eclipse.swt.graphics.Point) DebugException(org.eclipse.debug.core.DebugException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) ErlangBrowserInformationControlInput(org.erlide.ui.internal.information.ErlangBrowserInformationControlInput) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OpenUtils(org.erlide.ui.actions.OpenUtils) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 7 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class RenameModuleQuickFix method run.

@Override
public void run() throws Exception {
    final IMarker marker = getMarker();
    final List<String> margs = getQuickFix().getArgs();
    final String moduleName = margs.get(0);
    final IErlModel svc = ErlangEngine.getInstance().getModel();
    IErlModule newModule;
    newModule = svc.findModule(moduleName);
    if (newModule != null) {
        MessageDialog.openInformation(null, "Rename module quickfix", "A module with name '" + moduleName + "' already exists.");
        newModule.dispose();
        return;
    }
    final IFile file = (IFile) marker.getResource();
    final IErlModule oldModule = svc.findModule(file);
    if (oldModule == null) {
        return;
    }
    String in = Util.getInputStreamAsString(file.getContents(), file.getCharset());
    in = in.replaceFirst("-module\\([^)]+\\)\\.", "-module(" + moduleName + ").");
    file.setContents(new ByteArrayInputStream(in.getBytes()), IResource.FORCE, null);
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) ByteArrayInputStream(java.io.ByteArrayInputStream) IErlModule(org.erlide.engine.model.root.IErlModule) IMarker(org.eclipse.core.resources.IMarker)

Example 8 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class ErlProject method buildStructure.

@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
    final IResource r = getCorrespondingResource();
    // check whether the Erlang project can be opened
    if (!(r instanceof IContainer) || !r.isAccessible()) {
        ErlLogger.warn("Project %s has no resources: res:%s acc:%s cont:%s", getName(), r, r == null ? "?" : r.isAccessible(), r instanceof IContainer);
        throw new ErlModelException(new ErlModelStatus(ErlModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
    }
    addConfigurationChangeListeners();
    try {
        final IContainer c = (IContainer) r;
        final IResource[] elems = c.members();
        final List<IErlElement> children = new ArrayList<>(elems.length + 1);
        // ErlLogger.debug(">>adding externals");
        addExternals(children);
        // ErlLogger.debug("childcount %d", children.size());
        // ErlLogger.debug(">>adding otp");
        addOtpExternals(children);
        // ErlLogger.debug("childcount %d", children.size());
        final IErlModel model = ErlangEngine.getInstance().getModel();
        for (final IResource element : elems) {
            if (element instanceof IFolder) {
                final IFolder folder = (IFolder) element;
                final IErlFolder erlFolder = (IErlFolder) model.create(folder);
                children.add(erlFolder);
            } else if (element instanceof IFile) {
                final IFile file = (IFile) element;
                if (CommonUtils.isErlangFileContentFileName(file.getName())) {
                    final IErlModule m = (IErlModule) model.create(file);
                    children.add(m);
                }
            }
        }
        setChildren(children);
    } catch (final CoreException e) {
        ErlLogger.error(e);
        setChildren(new ArrayList<IErlModule>());
        return false;
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelStatus(org.erlide.engine.model.ErlModelStatus) ArrayList(java.util.ArrayList) IErlFolder(org.erlide.engine.model.root.IErlFolder) 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) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 9 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class ErlideTestUtils method createModuleFromText.

public static IErlModule createModuleFromText(final String initialText) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    final IErlModule module = model.getModuleFromText(model, "test1", initialText, null);
    ErlideTestUtils.modulesAndIncludes.add(module);
    return module;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 10 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class ErlideTestUtils method createModule.

public static IErlModule createModule(final String moduleName, final String moduleContents, final IFolder folder) throws CoreException {
    final IFile file = ErlideTestUtils.createFile(folder.getProject(), folder.getName() + "/" + moduleName, moduleContents);
    final IErlModel model = ErlangEngine.getInstance().getModel();
    IErlModule module = model.findModule(file);
    if (module == null) {
        final IPath path = file.getLocation();
        module = model.getModuleFromFile(model, file.getName(), path, Charset.defaultCharset());
    }
    return module;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IPath(org.eclipse.core.runtime.IPath) IErlModule(org.erlide.engine.model.root.IErlModule)

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