Search in sources :

Example 91 with IErlProject

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

the class ErlangSourceViewerConfiguration method getContentAssistant.

@Override
public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) {
    final ContentAssistant contentAssistant = new ContentAssistant();
    contentAssistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
    final IErlModule module = getModule();
    final IErlProject project = getProject();
    contentAssistProcessor = new ErlContentAssistProcessor(sourceViewer, module, project, contentAssistant);
    contentAssistProcessorForStrings = new ErlStringContentAssistProcessor(sourceViewer, module, project, contentAssistant);
    contentAssistProcessor.setToPrefs();
    contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
    contentAssistant.setContentAssistProcessor(contentAssistProcessor, IErlangPartitions.ERLANG_QATOM);
    contentAssistant.setContentAssistProcessor(contentAssistProcessorForStrings, IErlangPartitions.ERLANG_STRING);
    contentAssistant.enableAutoInsert(true);
    contentAssistant.enablePrefixCompletion(false);
    contentAssistant.setDocumentPartitioning(IErlangPartitions.ERLANG_PARTITIONING);
    contentAssistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
    contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
    contentAssistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
    return contentAssistant;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlContentAssistProcessor(org.erlide.ui.editors.erl.completion.ErlContentAssistProcessor) IErlModule(org.erlide.engine.model.root.IErlModule) ErlStringContentAssistProcessor(org.erlide.ui.editors.erl.completion.ErlStringContentAssistProcessor) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant)

Example 92 with IErlProject

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

the class CompileAction method run.

@Override
public void run() {
    final AbstractErlangEditor editor = (AbstractErlangEditor) getSite().getPage().getActiveEditor();
    final IErlModule module = editor.getModule();
    if (module == null) {
        return;
    }
    final IResource resource = module.getResource();
    final IProject project = resource.getProject();
    if (project == null) {
        return;
    }
    final IErlProject eproject = ErlangEngine.getInstance().getModelUtilService().getProject(module);
    if (eproject == null) {
        return;
    }
    final IOtpRpc b = BackendCore.getBuildBackend(eproject);
    final BuildResource bres = new BuildResource(resource);
    final CompilerOptions prefs = new CompilerOptions(project);
    prefs.load();
    final OtpErlangList compilerOptions = prefs.export();
    final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(project);
    if ("erl".equals(resource.getFileExtension())) {
        helper.compileErl(project, bres, erlProject.getProperties().getOutputDir().toString(), b, compilerOptions);
    }
    if ("yrl".equals(resource.getFileExtension())) {
        helper.compileYrl(project, bres, b, compilerOptions);
    }
    final ErlEditorActionBarContributor status = (ErlEditorActionBarContributor) editor.getEditorSite().getActionBarContributor();
    status.displayMessage(String.format("File '%s' was compiled.", resource.getName()));
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IErlModule(org.erlide.engine.model.root.IErlModule) CompilerOptions(org.erlide.core.builder.CompilerOptions) ErlEditorActionBarContributor(org.erlide.ui.editors.erl.ErlEditorActionBarContributor) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) BuildResource(org.erlide.core.builder.BuildResource) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 93 with IErlProject

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

the class OpenAction method run.

@Override
public void run(final ITextSelection selection) {
    try {
        final IEditorPart activeEditor = getSite().getPage().getActiveEditor();
        final int offset = selection.getOffset();
        ITextEditor textEditor = null;
        OpenResult openResult = null;
        IErlElement element = null;
        IErlProject project = null;
        IErlModule module = null;
        final IErlModel model = ErlangEngine.getInstance().getModel();
        if (activeEditor instanceof AbstractErlangEditor) {
            final AbstractErlangEditor editor = (AbstractErlangEditor) activeEditor;
            textEditor = editor;
            editor.reconcileNow();
            final String scannerName = editor.getScannerName();
            module = editor.getModule();
            project = editor.getProject();
            openResult = ErlangEngine.getInstance().getOpenService().open(scannerName, offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), project.getProperties().getExternalModules(), model.getPathVars());
            ErlLogger.debug("open " + openResult);
            element = editor.getElementAt(offset, true);
        } else if (activeEditor instanceof ITextEditor) {
            textEditor = (ITextEditor) activeEditor;
            final String text = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()).get();
            openResult = ErlangEngine.getInstance().getOpenService().openText(text, offset);
            final IFile file = textEditor.getEditorInput().getAdapter(IFile.class);
            if (file != null) {
                final IProject p = file.getProject();
                if (p != null) {
                    project = model.findProject(p);
                }
            }
        }
        if (openResult != null) {
            helper.openOpenResult(textEditor, module, offset, project, openResult, element);
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IErlElement(org.erlide.engine.model.IErlElement) OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 94 with IErlProject

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

the class ErlangFileWizardPage method initialize.

/**
 * Tests if the current workbench selection is a suitable container to use.
 */
private void initialize() {
    if (fSelection instanceof IStructuredSelection && !fSelection.isEmpty()) {
        final IStructuredSelection ssel = (IStructuredSelection) fSelection;
        if (ssel.size() > 1) {
            return;
        }
        final Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            final IResource resource = (IResource) obj;
            IContainer container;
            if (resource instanceof IContainer) {
                container = (IContainer) resource;
            } else {
                container = resource.getParent();
            }
            final IProject project = resource.getProject();
            final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(project);
            String txt = container.getFullPath().toString();
            final Collection<IPath> sourceDirs = erlProject.getProperties().getSourceDirs();
            if (!sourceDirs.isEmpty()) {
                final IPath sourceDirWithinContainer = sourceDirWithinContainer(sourceDirs, container);
                if (sourceDirWithinContainer != null) {
                    txt = sourceDirWithinContainer.toString();
                }
            }
            containerText.setText(txt);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 95 with IErlProject

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

the class ModelUtilsTest method getExternalModuleWithPrefix.

@Test
public void getExternalModuleWithPrefix() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project and an external file not in any project
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external3.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external3).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
        ((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking via prefix
        final List<String> moduleNames0 = modelUtilService.findUnitsWithPrefix("ex", project, false, false);
        final List<String> modules1 = modelUtilService.findUnitsWithPrefix("ex", project, true, false);
        final List<String> listModules = modelUtilService.findUnitsWithPrefix("list", project, true, false);
        // then
        // we should find it iff we check externals
        assertEquals(0, moduleNames0.size());
        assertEquals(1, modules1.size());
        assertEquals(SystemConfiguration.withoutExtension(externalFileName), modules1.get(0));
        assertEquals(1, listModules.size());
        assertEquals("lists", listModules.get(0));
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) File(java.io.File) Test(org.junit.Test)

Aggregations

IErlProject (org.erlide.engine.model.root.IErlProject)123 IErlModule (org.erlide.engine.model.root.IErlModule)57 Test (org.junit.Test)47 IPath (org.eclipse.core.runtime.IPath)30 IProject (org.eclipse.core.resources.IProject)29 ErlProject (org.erlide.engine.internal.model.root.ErlProject)25 File (java.io.File)19 Path (org.eclipse.core.runtime.Path)16 CoreException (org.eclipse.core.runtime.CoreException)13 ErlModelException (org.erlide.engine.model.ErlModelException)13 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)13 IErlModel (org.erlide.engine.model.root.IErlModel)13 ArrayList (java.util.ArrayList)11 IErlElement (org.erlide.engine.model.IErlElement)10 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 HashSet (java.util.HashSet)7 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)6 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)6