Search in sources :

Example 1 with IErlPreprocessorDef

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

the class ParserDB method handleModule.

public void handleModule(final IErlModule module) throws ErlModelException {
    module.open(null);
    final int numForms = module.getChildCount();
    final String path = module.getResource().getLocation().toPortableString();
    ParserDB.out.println(path + " " + numForms + " " + isTest(path));
    System.out.println(path + " " + numForms + " " + isTest(path));
    for (final IErlElement form : module.getChildren()) {
        ParserDB.out.print(" " + form.getKind() + " ");
        if (form instanceof IErlImportExport) {
            final IErlImportExport export = (IErlImportExport) form;
            ParserDB.out.println(export.getFunctions().size());
        } else if (form instanceof IErlPreprocessorDef) {
            final IErlPreprocessorDef def = (IErlPreprocessorDef) form;
            ParserDB.out.println(fix(def.getDefinedName()));
        } else if (form instanceof IErlTypespec) {
            final IErlTypespec attribute = (IErlTypespec) form;
            ParserDB.out.println("TYPESPEC " + fix(attribute.getName()));
        } else if (form instanceof IErlAttribute) {
            final IErlAttribute attribute = (IErlAttribute) form;
            ParserDB.out.println(fix(attribute.getName()));
        } else if (form instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) form;
            int numClauses = function.getChildCount();
            numClauses = numClauses == 0 ? 1 : numClauses;
            ParserDB.out.println(fix(function.getName()) + " " + function.getArity() + " " + numClauses);
        } else {
            ParserDB.out.println("?? " + form.getClass().getName());
        }
    }
    module.close();
    module.dispose();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlImportExport(org.erlide.engine.model.erlang.IErlImportExport) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute)

Example 2 with IErlPreprocessorDef

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

the class IndexedErlangValue method checkRecord.

private IErlRecordDef checkRecord(final OtpErlangObject o) {
    if (o instanceof OtpErlangTuple) {
        final OtpErlangTuple t = (OtpErlangTuple) o;
        final OtpErlangObject h = t.elementAt(0);
        if (h instanceof OtpErlangAtom) {
            final OtpErlangAtom a = (OtpErlangAtom) h;
            final ErlangDebugTarget target = getErlangDebugTarget();
            IErlPreprocessorDef pd;
            try {
                pd = ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(getErlProjects(target.getProjects()), moduleName, a.atomValue(), ErlElementKind.RECORD_DEF);
                if (pd instanceof IErlRecordDef) {
                    final IErlRecordDef r = (IErlRecordDef) pd;
                    if (r.hasChildren() && r.getChildCount() + 1 == t.arity()) {
                        return r;
                    }
                }
            } catch (final CoreException e) {
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef)

Example 3 with IErlPreprocessorDef

use of org.erlide.engine.model.erlang.IErlPreprocessorDef 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 4 with IErlPreprocessorDef

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

the class ErlangCompletionService method getAllPreprocessorDefs.

public static List<IErlPreprocessorDef> getAllPreprocessorDefs(final IErlModule module, final ErlElementKind kind) throws CoreException {
    final List<IErlPreprocessorDef> result = Lists.newArrayList();
    final List<IErlModule> modulesWithIncludes = Lists.newArrayList(ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module));
    modulesWithIncludes.add(module);
    for (final IErlModule m : modulesWithIncludes) {
        result.addAll(m.getPreprocessorDefs(kind));
    }
    return result;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef)

Example 5 with IErlPreprocessorDef

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

the class ModelFindUtil method findPreprocessorDef.

@Override
public IErlPreprocessorDef findPreprocessorDef(final IErlModule module, final String definedName, final ErlElementKind kind) throws CoreException {
    String unquoted = StringUtils.unquote(definedName);
    final String quoted = StringUtils.quote(definedName);
    final Set<String> names = new HashSet<>(3);
    if (kind == ErlElementKind.RECORD_DEF) {
        while (names.add(unquoted)) {
            unquoted = resolveMacroValue(unquoted, module);
        }
    } else {
        names.add(unquoted);
    }
    names.add(quoted);
    names.add(definedName);
    final List<IErlModule> allIncludedFiles = Lists.newArrayList(findAllIncludedFiles(module));
    allIncludedFiles.add(0, module);
    for (final IErlModule includedFile : allIncludedFiles) {
        for (final String name : names) {
            includedFile.open(null);
            final IErlPreprocessorDef preprocessorDef = includedFile.findPreprocessorDef(name, kind);
            if (preprocessorDef != null) {
                return preprocessorDef;
            }
        }
    }
    return null;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) HashSet(java.util.HashSet)

Aggregations

IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)14 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlProject (org.erlide.engine.model.root.IErlProject)6 Test (org.junit.Test)5 IErlRecordDef (org.erlide.engine.model.erlang.IErlRecordDef)4 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ErlProject (org.erlide.engine.internal.model.root.ErlProject)2 IErlElement (org.erlide.engine.model.IErlElement)2 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)2 CompletionData (org.erlide.engine.services.codeassist.CompletionData)2 FunctionCompletionData (org.erlide.engine.services.codeassist.FunctionCompletionData)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 HashSet (java.util.HashSet)1 IPath (org.eclipse.core.runtime.IPath)1