Search in sources :

Example 36 with ErlModelException

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

the class ErlangCompletionService method getRecordFieldCompletions.

List<CompletionData> getRecordFieldCompletions(final String recordName, final int offset, final String prefix, final int hashMarkPos, final List<String> fieldsSoFar) {
    if (module == null) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    IErlPreprocessorDef pd;
    try {
        pd = ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(module, recordName, ErlElementKind.RECORD_DEF);
    } catch (final CoreException e) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    if (pd instanceof IErlRecordDef) {
        final List<CompletionData> result = new ArrayList<>();
        try {
            for (final IErlElement i : pd.getChildren()) {
                final IErlRecordField field = (IErlRecordField) i;
                final String fieldName = field.getFieldName();
                if (!fieldsSoFar.contains(fieldName)) {
                    addIfMatches(fieldName, prefix, offset, result);
                }
            }
        } catch (final ErlModelException e) {
        }
        return result;
    }
    return ErlangCompletionService.EMPTY_COMPLETIONS;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CoreException(org.eclipse.core.runtime.CoreException) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlRecordField(org.erlide.engine.model.erlang.IErlRecordField)

Example 37 with ErlModelException

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

the class ErlangCompletionService method addFunctionsFromModule.

boolean addFunctionsFromModule(final int offset, final String prefix, final boolean arityOnly, final List<CompletionData> proposals, final IErlModule m) {
    boolean result = false;
    try {
        m.open(null);
        for (final IErlElement e : m.getChildren()) {
            if (e instanceof IErlFunction) {
                final IErlFunction f = (IErlFunction) e;
                if (f.isExported()) {
                    addFunctionCompletion(offset, prefix, proposals, f, arityOnly);
                    result = true;
                }
            }
        }
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlFunction(org.erlide.engine.model.erlang.IErlFunction)

Example 38 with ErlModelException

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

the class ErlParser method attachFunctionComments.

/**
 * attach local function documentation with heuristics: if a comment is within 3 lines
 * before function, or a sequence of comment, -spec, comment, then they should be
 * added to function documentation
 *
 * If any typespec is available for the function (wherever it is located), then it
 * should be attached too.
 *
 * @param module
 */
private void attachFunctionComments(final IErlModule module) {
    // TODO rewrite in Erlang? would be so much less code...
    try {
        final Collection<IErlComment> comments = module.getComments();
        final List<IErlElement> children = module.getChildren();
        final List<IErlMember> all = Lists.newArrayListWithCapacity(children.size() + comments.size());
        all.addAll(comments);
        for (final IErlElement element : children) {
            if (element instanceof IErlMember) {
                all.add((IErlMember) element);
            }
        }
        all.sort(new SourceOffsetComparator());
        for (int i = 1; i < all.size(); i++) {
            checkForComment(all, i);
        }
    } catch (final ErlModelException e) {
        ErlLogger.warn(e);
    }
}
Also used : IErlComment(org.erlide.engine.model.erlang.IErlComment) IErlElement(org.erlide.engine.model.IErlElement) IErlMember(org.erlide.engine.model.erlang.IErlMember) ErlModelException(org.erlide.engine.model.ErlModelException)

Example 39 with ErlModelException

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

the class InterpretedModuleListContentProvider method addModules.

/**
 * Find modules from string list add to IFile-list
 *
 * @param interpret
 *            the list of strings from prefs (projectName:fileName;... or
 *            moduleName;...)
 */
public void addModules(final Collection<String> interpret) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    for (final String projectColonModule : interpret) {
        // project:module | module
        final String[] projectModule = projectColonModule.split(":");
        IErlModule module = null;
        if (projectModule.length > 1) {
            final IErlProject project = (IErlProject) model.getChildNamed(projectModule[0]);
            if (project != null) {
                final String mName = projectModule[1];
                try {
                    final boolean isErlangFile = CommonUtils.isErlangFileContentFileName(mName);
                    final String s = isErlangFile ? mName : mName + ".erl";
                    module = project.getModule(s);
                } catch (final ErlModelException e) {
                    ErlLogger.warn(e);
                }
            }
        } else {
            try {
                module = model.findModule(projectColonModule);
            } catch (final ErlModelException e) {
            }
        }
        addModule(module);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 40 with ErlModelException

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

the class RunDialyzerHandler method collectModulesFromSelection.

private Set<IErlModule> collectModulesFromSelection(final ISelection selection) {
    final Set<IErlModule> modules = Sets.newHashSet();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        final IErlModel model = ErlangEngine.getInstance().getModel();
        try {
            model.open(null);
            for (final Object i : structuredSelection.toList()) {
                if (i instanceof IResource) {
                    final IResource r = (IResource) i;
                    modules.addAll(DialyzerUtils.collectModulesFromResource(model, r));
                }
            }
        } catch (final ErlModelException e) {
            ErlLogger.debug(e);
        }
    }
    return modules;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Aggregations

ErlModelException (org.erlide.engine.model.ErlModelException)45 IErlElement (org.erlide.engine.model.IErlElement)21 IErlModule (org.erlide.engine.model.root.IErlModule)21 IErlModel (org.erlide.engine.model.root.IErlModel)9 IErlProject (org.erlide.engine.model.root.IErlProject)9 ArrayList (java.util.ArrayList)8 IOpenable (org.erlide.engine.model.root.IOpenable)7 CoreException (org.eclipse.core.runtime.CoreException)6 IProject (org.eclipse.core.resources.IProject)5 IResource (org.eclipse.core.resources.IResource)5 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)4 IFile (org.eclipse.core.resources.IFile)4 IParent (org.erlide.engine.model.IParent)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 Composite (org.eclipse.swt.widgets.Composite)3 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)3 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2