Search in sources :

Example 11 with ErlModelException

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

the class StatsViewLabelProvider method getColumnImage.

@Override
public Image getColumnImage(final Object element, final int columnIndex) {
    Image img = null;
    final ICoverageObject statsEl = (ICoverageObject) element;
    switch(columnIndex) {
        case 0:
            final ObjectType type = statsEl.getType();
            switch(type) {
                case FUNCTION:
                    img = Activator.getImageDescriptor(Images.FUNCTION).createImage();
                    break;
                case MODULE:
                    IErlModule m;
                    try {
                        m = ErlangEngine.getInstance().getModel().findModule(statsEl.getLabel());
                    } catch (final ErlModelException e) {
                        ErlLogger.error(e);
                        return null;
                    }
                    img = ErlangElementImageProvider.getErlImageDescriptor(m, ErlangElementImageProvider.SMALL_ICONS).createImage();
                    break;
                case FOLDER:
                    img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER).createImage();
                    break;
                case PROJECT:
                    img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT).createImage();
                    break;
                default:
                    break;
            }
            break;
        case 3:
            img = drawPercentage(statsEl.getPercentage());
            break;
        default:
    }
    return img;
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) ObjectType(org.erlide.cover.views.model.ObjectType) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) Image(org.eclipse.swt.graphics.Image)

Example 12 with ErlModelException

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

the class DocumentationFormatter method getDocumentationString.

public static String getDocumentationString(final Collection<IErlComment> comments, final IErlTypespec typespec) {
    final StringBuilder stringBuilder = new StringBuilder();
    if (!comments.isEmpty()) {
        stringBuilder.append("<pre class='edoc'>");
        for (final IErlComment member : comments) {
            try {
                String source = "\n" + DocumentationFormatter.convertToHTML(member.getSource());
                source = source.replaceAll("\n%%%", "\n").replaceAll("\n%%", "\n").replaceAll("\n%", "\n").substring(1);
                source = source.replaceAll("\n( *([-=] *)+\n)+", "\n<hr/>\n").replaceAll("^ *([-=] *)+\n", "\n").replaceAll("\n *([-=] *)+$", "\n");
                stringBuilder.append(source);
                if (!source.endsWith("\n")) {
                    stringBuilder.append('\n');
                }
                stringBuilder.append('\n');
            } catch (final ErlModelException e) {
                ErlLogger.warn(e);
            }
        }
        stringBuilder.append("</pre>");
    }
    if (typespec != null) {
        try {
            stringBuilder.append("<hr/><pre class='typespec'>").append(DocumentationFormatter.convertToHTML(typespec.getSource())).append("</pre>");
        } catch (final ErlModelException e) {
            ErlLogger.warn(e);
        }
    }
    return stringBuilder.toString().replace("\n", "<br/>");
}
Also used : IErlComment(org.erlide.engine.model.erlang.IErlComment) ErlModelException(org.erlide.engine.model.ErlModelException)

Example 13 with ErlModelException

use of org.erlide.engine.model.ErlModelException 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 14 with ErlModelException

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

the class DefaultErlangFoldingStructureProvider method projectionEnabled.

/*
     * @seeorg.eclipse.jface.text.source.projection.IProjectionListener#
     * projectionEnabled()
     */
@Override
public void projectionEnabled() {
    // http://home.ott.oti.com/teams/wswb/anon/out/vms/index.html
    // projectionEnabled messages are not always paired with
    // projectionDisabled
    // i.e. multiple enabled messages may be sent out.
    // we have to make sure that we disable first when getting an enable
    // message.
    projectionDisabled();
    initialize();
    if (fEditor instanceof ErlangEditor && fModule != null) {
        boolean structureKnown = false;
        try {
            structureKnown = fModule.isStructureKnown();
        } catch (final ErlModelException e1) {
        }
        if (structureKnown) {
            final IErlElementDelta d = ErlangEngine.getInstance().getModel().createElementDelta(IErlElementDelta.CHANGED, IErlElementDelta.F_CONTENT, fModule);
            processDelta(d);
        } else {
            try {
                fModule.open(null);
            } catch (final ErlModelException e) {
                ErlLogger.error(e);
            }
        }
    }
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Example 15 with ErlModelException

use of org.erlide.engine.model.ErlModelException 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

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