Search in sources :

Example 46 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 47 with IErlModule

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

the class MarkerUtils method findResourceForFileName.

private static IResource findResourceForFileName(final IResource resource, final Entry<String, List<OtpErlangTuple>> entry, final String fileName) {
    IResource res = resource;
    if (!ResourceUtil.samePath(resource.getLocation().toString(), fileName)) {
        final IProject project = resource.getProject();
        res = ResourceUtil.findResourceByLocation(project, fileName);
        if (res == null) {
            try {
                final IErlElementLocator model = ErlangEngine.getInstance().getModel();
                final IErlProject erlProject = model.findProject(project);
                if (erlProject != null) {
                    final IErlModule includeFile = model.findIncludeFromProject(erlProject, fileName, fileName, IErlElementLocator.Scope.REFERENCED_PROJECTS);
                    if (includeFile == null) {
                        res = resource;
                    } else {
                        res = includeFile.getResource();
                    }
                } else {
                    res = resource;
                }
            } catch (final Exception e) {
                ErlLogger.warn(e);
            }
        }
    }
    return res;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException)

Example 48 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 49 with IErlModule

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

the class ErlNode method createErlNode.

public static ErlNode createErlNode(final ErlNode parent, final IErlElement element, final IDocument doc) {
    int start = 0;
    int length = 0;
    String name = element.toString();
    if (element instanceof IErlModule) {
        final IErlModule m = (IErlModule) element;
        length = doc.getLength();
        name = m.getModuleName();
    } else if (element instanceof ISourceReference) {
        final ISourceReference sourceReference = (ISourceReference) element;
        final ISourceRange sr = sourceReference.getSourceRange();
        start = sr.getOffset();
        length = sr.getLength();
    }
    return new ErlNode(parent, element.getKind(), name, ErlangCompareUtilities.getErlElementID(element), doc, start, length);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Example 50 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9