Search in sources :

Example 51 with IErlModule

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

the class ErlStructureCreator method getPath.

@Override
protected String[] getPath(final Object element, final Object input) {
    if (element instanceof IErlElement) {
        IErlElement e = (IErlElement) element;
        // build a path starting at the given element and walk
        // up the parent chain until we reach a module
        final List<String> args = new ArrayList<>();
        while (e != null) {
            // each path component has a name that uses the same
            // conventions as a ErlNode name
            final String name = ErlangCompareUtilities.getErlElementID(e);
            if (name == null) {
                return null;
            }
            args.add(name);
            if (e instanceof IErlModule) {
                break;
            }
            e = (IErlElement) e.getParent();
        }
        Collections.reverse(args);
        return args.toArray(new String[args.size()]);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ArrayList(java.util.ArrayList) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 52 with IErlModule

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

the class DefaultErlangFoldingStructureProvider method processDelta.

protected void processDelta(final IErlElementDelta delta) {
    if (!isInstalled()) {
        return;
    }
    if ((delta.getFlags() & (IErlElementDelta.F_CONTENT | IErlElementDelta.F_CHILDREN)) == 0) {
        return;
    }
    final IErlElement de = delta.getElement();
    if (de instanceof IErlModule && de != fModule) {
        return;
    }
    final ProjectionAnnotationModel model = fEditor.getAdapter(ProjectionAnnotationModel.class);
    if (model == null) {
        return;
    }
    final IDocumentProvider provider = fEditor.getDocumentProvider();
    try {
        fCachedModel = model;
        fCachedDocument = provider.getDocument(fEditor.getEditorInput());
        if (fCachedDocument.getNumberOfLines() > PerformanceTuning.get().getFoldingLimit()) {
            // disable folding for files larger than this
            model.removeAllAnnotations();
            return;
        }
        final Map<ErlangProjectionAnnotation, Position> additions = new HashMap<>();
        final List<ErlangProjectionAnnotation> deletions = new ArrayList<>();
        final List<ErlangProjectionAnnotation> updates = new ArrayList<>();
        // use a linked map to maintain ordering of comments
        final Map<ErlangProjectionAnnotation, Position> updated = new LinkedHashMap<>();
        computeAdditions(fModule, updated);
        final Map<Object, List<Tuple>> previous = createAnnotationMap(model);
        for (final Entry<ErlangProjectionAnnotation, Position> entry : updated.entrySet()) {
            final ErlangProjectionAnnotation newAnnotation = entry.getKey();
            final IErlElement element = newAnnotation.getElement();
            final Position newPosition = entry.getValue();
            final List<Tuple> annotations = previous.get(element);
            if (annotations == null) {
                additions.put(newAnnotation, newPosition);
            } else {
                final Iterator<Tuple> x = annotations.iterator();
                boolean matched = false;
                while (x.hasNext()) {
                    final Tuple tuple = x.next();
                    final ErlangProjectionAnnotation existingAnnotation = tuple.annotation;
                    final Position existingPosition = tuple.position;
                    if (newAnnotation.isComment() == existingAnnotation.isComment()) {
                        if (existingPosition != null && !newPosition.equals(existingPosition)) {
                            existingPosition.setOffset(newPosition.getOffset());
                            existingPosition.setLength(newPosition.getLength());
                            updates.add(existingAnnotation);
                        }
                        matched = true;
                        x.remove();
                        break;
                    }
                }
                if (!matched) {
                    additions.put(newAnnotation, newPosition);
                }
                if (annotations.isEmpty()) {
                    previous.remove(element);
                }
            }
        }
        for (final List<Tuple> l : previous.values()) {
            for (final Tuple t : l) {
                deletions.add(t.annotation);
            }
        }
        match(deletions, additions, updates);
        final Annotation[] removals = new Annotation[deletions.size()];
        deletions.toArray(removals);
        final Annotation[] changes = new Annotation[updates.size()];
        updates.toArray(changes);
        model.modifyAnnotations(removals, additions, changes);
        fFirstTimeInitialCollapse = false;
    } finally {
        fCachedDocument = null;
        fCachedModel = null;
    // fFirstType= null;
    // fHasHeaderComment = false;
    }
}
Also used : Position(org.eclipse.jface.text.Position) IProjectionPosition(org.eclipse.jface.text.source.projection.IProjectionPosition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Annotation(org.eclipse.jface.text.source.Annotation) ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) LinkedHashMap(java.util.LinkedHashMap) IErlElement(org.erlide.engine.model.IErlElement) ProjectionAnnotationModel(org.eclipse.jface.text.source.projection.ProjectionAnnotationModel) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IErlModule(org.erlide.engine.model.root.IErlModule) List(java.util.List) ArrayList(java.util.ArrayList)

Example 53 with IErlModule

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

the class DebugTab method createControl.

/**
 * @wbp.parser.entryPoint
 */
@Override
public void createControl(final Composite parent) {
    final Composite comp = new Composite(parent, SWT.NONE);
    setControl(comp);
    final GridLayout topLayout = new GridLayout();
    comp.setLayout(topLayout);
    distributedDebugCheck = createCheckButton(comp, "Debug all connected nodes");
    final Group attachGroup = SWTUtil.createGroup(comp, "Auto Attach", 1, GridData.FILL_BOTH);
    attachGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    attachOnFirstCallCheck = createCheckButton(attachGroup, "First &call");
    attachOnBreakpointCheck = createCheckButton(attachGroup, "&Breakpoint");
    attachOnExitCheck = createCheckButton(attachGroup, "E&xit");
    distributedDebugCheck.addSelectionListener(fBasicSelectionListener);
    attachOnFirstCallCheck.addSelectionListener(fBasicSelectionListener);
    attachOnBreakpointCheck.addSelectionListener(fBasicSelectionListener);
    attachOnExitCheck.addSelectionListener(fBasicSelectionListener);
    final Group interpretedModulesGroup = new Group(comp, SWT.NONE);
    final GridData gd_interpretedModulesGroup = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    gd_interpretedModulesGroup.widthHint = 387;
    interpretedModulesGroup.setLayoutData(gd_interpretedModulesGroup);
    interpretedModulesGroup.setText("Interpreted modules");
    interpretedModulesGroup.setLayout(new GridLayout(2, false));
    // final Label anyModuleHavingLabel = new Label(interpretedModulesGroup,
    // SWT.WRAP);
    // anyModuleHavingLabel.setLayoutData(new GridData(279, SWT.DEFAULT));
    // anyModuleHavingLabel
    // .setText("Any module having breakpoints enabled will be dynamically added to
    // the list.\n\nThis widget is disabled for now, it takes 100%CPU for large
    // projects. If you need to use \"attach on first call\" or \"attach on exit\",
    // please mark the modules by setting a dummy breakpoint in them. Sorry for the
    // inconvenience!");
    listViewer = new ListViewer(interpretedModulesGroup, SWT.BORDER | SWT.MULTI);
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            removeButton.setEnabled(!selection.isEmpty());
        }
    });
    // checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {
    // @Override
    // @SuppressWarnings("synthetic-access")
    // public void checkStateChanged(final CheckStateChangedEvent event) {
    // final DebugTreeItem dti = (DebugTreeItem) event.getElement();
    // checkboxTreeViewer.setGrayed(dti, false);
    // final boolean checked = event.getChecked();
    // setSubtreeChecked(dti, checked);
    // // checkUpwards(checkboxTreeViewer, dti, checked, false);
    // updateLaunchConfigurationDialog();
    // }
    // 
    // });
    listViewer.setLabelProvider(new ModuleItemLabelProvider());
    contentProvider = new InterpretedModuleListContentProvider();
    listViewer.setContentProvider(contentProvider);
    final Control control = listViewer.getControl();
    final GridData gd_list = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd_list.minimumWidth = 250;
    gd_list.minimumHeight = 120;
    gd_list.widthHint = 256;
    gd_list.heightHint = 220;
    control.setLayoutData(gd_list);
    addButton = createPushButton(interpretedModulesGroup, "Add...", null);
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final List<IErlModule> result = DebugTab.getModulesFromAddModulesDialog(getShell());
            contentProvider.addModules(result);
            listViewer.refresh();
            updateLaunchConfigurationDialog();
        }
    });
    removeButton = createPushButton(interpretedModulesGroup, "Remove", null);
    removeButton.setEnabled(false);
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
            for (final Object o : selection.toArray()) {
                contentProvider.removeModule((IErlModule) o);
            }
            listViewer.refresh();
            updateLaunchConfigurationDialog();
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) InterpretedModuleListContentProvider(org.erlide.debug.ui.views.InterpretedModuleListContentProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ModuleItemLabelProvider(org.erlide.debug.ui.utils.ModuleItemLabelProvider) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IErlModule(org.erlide.engine.model.root.IErlModule) ArrayList(java.util.ArrayList) List(java.util.List)

Example 54 with IErlModule

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

the class DebugTab method performApply.

@Override
public void performApply(final ILaunchConfigurationWorkingCopy config) {
    config.setAttribute(ErlRuntimeAttributes.DEBUG_FLAGS, ErlDebugFlags.getFlag(getFlagCheckboxes()));
    final List<String> r = new ArrayList<>();
    for (final Object o : contentProvider.getElements(null)) {
        final IErlModule module = (IErlModule) o;
        r.add(ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ":" + module.getName());
    }
    config.setAttribute(ErlRuntimeAttributes.DEBUG_INTERPRET_MODULES, r);
}
Also used : ArrayList(java.util.ArrayList) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 55 with IErlModule

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

the class ErlangNodeLaunchShortcut method getProjectAndModuleNames.

private List<String> getProjectAndModuleNames(final Collection<IErlProject> projects) throws ErlModelException {
    final List<String> moduleNames = Lists.newArrayList();
    for (final IErlProject project : projects) {
        final Collection<IErlModule> modules = project.getModules();
        final String projectNameColon = project.getName() + ":";
        for (final IErlModule module : modules) {
            moduleNames.add(projectNameColon + module.getName());
        }
    }
    return moduleNames;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule)

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