Search in sources :

Example 21 with IErlModule

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

the class MarkOccurencesSupport method installOccurrencesFinder.

protected void installOccurrencesFinder(final boolean forceUpdate) {
    fMarkOccurrenceAnnotations = true;
    fPostSelectionListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            editor.markOccurencesHandler.updateOccurrenceAnnotations((ITextSelection) selection, editor.getModule());
        }
    };
    final ISelectionProvider selectionProvider = editor.getSelectionProvider();
    if (selectionProvider != null) {
        ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(fPostSelectionListener);
        if (forceUpdate) {
            fForcedMarkOccurrencesSelection = selectionProvider.getSelection();
            final IErlModule module = editor.getModule();
            if (module != null) {
                editor.markOccurencesHandler.updateOccurrenceAnnotations((ITextSelection) fForcedMarkOccurrencesSelection, module);
            }
        }
    }
    if (fOccurrencesFinderJobCanceler == null) {
        fOccurrencesFinderJobCanceler = new OccurrencesFinderJobCanceler();
        fOccurrencesFinderJobCanceler.install();
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) IErlModule(org.erlide.engine.model.root.IErlModule) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 22 with IErlModule

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

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

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

the class ErlProject method getModulesAndIncludes.

@Override
public Collection<IErlModule> getModulesAndIncludes() throws ErlModelException {
    final List<IErlModule> result = new ArrayList<>();
    final ErlModelCache erlModelCache = ErlModelCache.getDefault();
    final List<IErlModule> modulesForProject = erlModelCache.getModulesForProject(this);
    final List<IErlModule> includesForProject = erlModelCache.getIncludesForProject(this);
    if (modulesForProject != null && includesForProject != null) {
        result.addAll(modulesForProject);
        result.addAll(includesForProject);
    } else {
        final List<IErlModule> cached = erlModelCache.getModulesForProject(this);
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        if (cached == null) {
            final List<IErlModule> modules = ErlProject.getModulesOrIncludes(fProject, model, getProperties().getSourceDirs(), true);
            result.addAll(modules);
        } else {
            result.addAll(cached);
        }
        final Collection<IErlModule> includes = getIncludes();
        result.addAll(includes);
    }
    return result;
}
Also used : ErlModelCache(org.erlide.engine.internal.model.cache.ErlModelCache) IErlModule(org.erlide.engine.model.root.IErlModule) ArrayList(java.util.ArrayList) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator)

Example 25 with IErlModule

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

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