public static void deleteModule(final IErlModule module) throws CoreException {
   final String scannerName = module.getScannerName();
   final IFile file = (IFile) module.getResource();
   if (file != null) {
     file.delete(true, null);
   }
   final IPath stateDir = new Path(ErlangEngine.getInstance().getStateDir());
   // FIXME this code should not know about caches!
   final String cacheExts[] = {".noparse", ".refs", ".scan"};
   for (final String ext : cacheExts) {
     final IPath p = stateDir.append(scannerName + ext);
     final File f = new File(p.toOSString());
     f.delete();
   }
   module.dispose();
   modulesAndIncludes.remove(module);
 }
Beispiel #2
0
 /**
  * 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 = getEditorInput(inputElement);
   if (input != null) {
     for (final IEditorPart editorPart : allErlangEditors) {
       if (editorPart.getEditorInput().equals(input)) {
         return editorPart;
       }
     }
   }
   return null;
 }
  @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!
        if (
        /* !m.isStructureKnown() */ true) {
          // FIXME: not permitted operation
          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;
  }