Search in sources :

Example 61 with IErlModule

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

the class EditorUtility method isOpenInEditor.

/**
 * Tests if a CU is currently shown in an editor
 *
 * @return the IEditorPart if shown, null if element is not open in an
 *         editor
 */
public static IEditorPart isOpenInEditor(final Object inputElement) {
    final Collection<IEditorPart> allErlangEditors = EditorUtility.getAllErlangEditors();
    for (final IEditorPart editorPart : allErlangEditors) {
        if (inputElement instanceof IErlElement) {
            final IErlElement element = (IErlElement) inputElement;
            final IErlModule module = ErlangEngine.getInstance().getModelUtilService().getModule(element);
            final AbstractErlangEditor editor = (AbstractErlangEditor) editorPart;
            if (module.equals(editor.getModule())) {
                return editorPart;
            }
        }
    }
    final IEditorInput input = EditorUtility.getEditorInput(inputElement);
    if (input != null) {
        for (final IEditorPart editorPart : allErlangEditors) {
            if (editorPart.getEditorInput().equals(input)) {
                return editorPart;
            }
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 62 with IErlModule

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

the class ErlangExternalEditorInputFactory method createElement.

@Override
public IAdaptable createElement(final IMemento memento) {
    // Get the file name.
    final String externalModulePath = memento.getString(ErlangExternalEditorInputFactory.TAG_EXTERNAL_MODULE_PATH);
    if (externalModulePath == null) {
        return null;
    }
    IErlModule module;
    try {
        final IErlModel model = ErlangEngine.getInstance().getModel();
        module = ErlangEngine.getInstance().getModelUtilService().getModuleFromExternalModulePath(model, externalModulePath);
    } catch (final ErlModelException e1) {
        return null;
    }
    if (module == null) {
        return null;
    }
    // Get the file name.
    final String uriString = memento.getString(ErlangExternalEditorInputFactory.TAG_URI);
    if (uriString == null) {
        return null;
    }
    URI uri;
    try {
        uri = new URI(uriString);
    } catch (final URISyntaxException e) {
        return null;
    }
    try {
        return new ErlangExternalEditorInput(EFS.getStore(uri), module);
    } catch (final CoreException e) {
        return null;
    }
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 63 with IErlModule

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

the class RemoteFunctionClauseDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    final Tree functionClausesTree;
    final Label label = new Label(composite, SWT.WRAP);
    label.setText("Please select the function clause which against should fold!");
    final GridData minToksData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    minToksData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(minToksData);
    label.setFont(parent.getFont());
    functionClausesTree = new Tree(composite, SWT.BORDER);
    final GridData treeData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    treeData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    functionClausesTree.setLayoutData(treeData);
    try {
        final Collection<IErlModule> erlmodules = ErlangEngine.getInstance().getModelUtilService().getProject(GlobalParameters.getWranglerSelection().getErlElement()).getModules();
        for (final IErlModule m : erlmodules) {
            // must refresh the scanner!
            m.open(null);
            final TreeItem moduleName = new TreeItem(functionClausesTree, 0);
            moduleName.setText(m.getModuleName());
            moduleName.setData(m);
            final List<IErlFunction> functions = filterFunctions(m.getChildren());
            for (final IErlFunction f : functions) {
                final TreeItem functionName = new TreeItem(moduleName, 0);
                functionName.setText(f.getNameWithArity());
                final List<IErlFunctionClause> clauses = filterClauses(f.getChildren());
                functionName.setData(f);
                for (final IErlFunctionClause c : clauses) {
                    final TreeItem clauseName = new TreeItem(functionName, 0);
                    clauseName.setText(String.valueOf(c.getName()));
                    clauseName.setData(c);
                }
            }
        }
        // listen to treeitem selection
        functionClausesTree.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetDefaultSelected(final SelectionEvent e) {
            }

            // if a function or a function clause is selected, then
            // highlight it
            // and store the selection
            @Override
            public void widgetSelected(final SelectionEvent e) {
                final TreeItem[] selectedItems = functionClausesTree.getSelection();
                if (selectedItems.length > 0) {
                    final TreeItem treeItem = selectedItems[0];
                    final Object data = treeItem.getData();
                    if (data instanceof IErlFunctionClause) {
                        // enable the ok button
                        okButton.setEnabled(true);
                        // highlight
                        WranglerUtils.highlightSelection((IErlFunctionClause) data);
                        // store
                        functionClause = (IErlFunctionClause) data;
                    } else {
                        okButton.setEnabled(false);
                    }
                }
            }
        });
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
    }
    applyDialogFont(composite);
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) Label(org.eclipse.swt.widgets.Label) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) ErlModelException(org.erlide.engine.model.ErlModelException) GridData(org.eclipse.swt.layout.GridData) IErlModule(org.erlide.engine.model.root.IErlModule) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 64 with IErlModule

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

the class WranglerUtils method notifyErlide.

/**
 * Notifies Erlide about the changed files.
 *
 * @param changedFiles
 *            changed files
 */
public static void notifyErlide(final List<ChangedFile> changedFiles) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    for (final ChangedFile f : changedFiles) {
        IFile file;
        try {
            file = WranglerUtils.getFileFromPath(f.getNewPath());
            final IErlElement element = model.findElement(file);
            final IErlModule m = (IErlModule) element;
            m.resourceChanged(null);
            final IEditorPart editor = GlobalParameters.getEditor();
            if (editor instanceof ErlangEditor) {
                ((ErlangEditor) editor).resetAndCacheScannerAndParser();
            }
            model.notifyChange(m);
        } catch (final Exception e) {
            ErlLogger.error(e);
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Example 65 with IErlModule

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

the class AddRefacHandler method checkType.

// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
    try {
        final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
        final ScannerService scanner = module.getScanner();
        try {
            module.resetAndCacheScannerAndParser(null);
        } finally {
            scanner.dispose();
        }
        for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
            final IErlAttribute attr = (IErlAttribute) el;
            if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
                if (attr.getValue().toString().contains("gen_refac")) {
                    return RefacType.ELEMENTARY;
                } else if (attr.getValue().toString().contains("gen_composite_refac")) {
                    return RefacType.COMPOSITE;
                }
            }
        }
        return null;
    } catch (final ErlModelException e) {
        return null;
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ScannerService(org.erlide.engine.services.parsing.ScannerService)

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