public SearchPatternData tryErlangTextSelection(
     final SearchPatternData initData0, final IEditorPart activePart) throws ErlModelException {
   final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) activePart;
   final IErlModule module = erlangEditor.getModule();
   SearchPatternData initData = initData0;
   if (module != null) {
     final ISelection ssel = erlangEditor.getSite().getSelectionProvider().getSelection();
     final ITextSelection textSel = (ITextSelection) ssel;
     final int offset = textSel.getOffset();
     OpenResult res;
     try {
       res =
           ErlangEngine.getInstance()
               .getService(OpenService.class)
               .open(
                   module.getScannerName(),
                   offset,
                   ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module),
                   "",
                   ErlangEngine.getInstance().getModel().getPathVars());
     } catch (final RpcException e) {
       res = null;
     }
     ErlLogger.debug("searchPage(open) " + res);
     initData = determineInitValuesFrom(module, offset, res);
   }
   return initData;
 }
Esempio n. 2
0
  private void testBuilder(final BuilderTool builderTool) throws CoreException {
    ErlangNature.setErlangProjectBuilder(prj, builderTool);
    final String targetBeamPath = "ebin/mod.beam";

    final IResource beam0 = prj.findMember(targetBeamPath);
    assertThat("beam existed before test", beam0, nullValue());

    final ErlangBuilder builder = ErlangBuilderFactory.get(builderTool);
    final BuildNotifier notifier = new BuildNotifier(null, prj);
    final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(prj);

    builder.build(BuildKind.FULL, erlProject, notifier);
    prj.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitJobsToFinish(ResourcesPlugin.FAMILY_MANUAL_REFRESH);

    final IResource beam = prj.findMember(targetBeamPath);
    assertThat("beam was not created", beam, notNullValue());

    builder.clean(erlProject, notifier);
    prj.refreshLocal(IResource.DEPTH_INFINITE, null);
    waitJobsToFinish(ResourcesPlugin.FAMILY_MANUAL_REFRESH);

    final IResource beam2 = prj.findMember(targetBeamPath);
    assertThat("beam was not removed", beam2, nullValue());
  }
Esempio n. 3
0
 public static IErlProject createProject(final IPath path, final String name)
     throws CoreException {
   final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   final IProject project2 = root.getProject(name);
   try {
     project2.delete(true, null);
   } catch (final CoreException x) {
     // ignore
   }
   final IErlProject erlProject =
       ErlangEngine.getInstance().getModel().newProject(name, path.toPortableString());
   final IProject project = erlProject.getWorkspaceProject();
   final IErlangProjectProperties prefs = new OldErlangProjectProperties(project);
   final List<IPath> srcDirs = new ArrayList<IPath>();
   srcDirs.add(new Path("src"));
   prefs.setSourceDirs(srcDirs);
   buildPaths(root, project, srcDirs);
   final List<IPath> includeDirs = new ArrayList<IPath>();
   includeDirs.add(new Path("include"));
   buildPaths(root, project, includeDirs);
   prefs.setIncludeDirs(includeDirs);
   final List<IPath> ebinDirs = new ArrayList<IPath>();
   ebinDirs.add(new Path("ebin"));
   buildPaths(root, project, ebinDirs);
   prefs.setOutputDir(ebinDirs.get(0));
   projects.add(erlProject);
   return erlProject;
 }
Esempio n. 4
0
 public static void initProjects() throws CoreException {
   projects = Lists.newArrayList();
   final IErlModel model = ErlangEngine.getInstance().getModel();
   model.open(null);
   final List<IErlElement> children = model.getChildren();
   for (final IErlElement child : children) {
     if (child instanceof IErlProject) {
       final IErlProject project = (IErlProject) child;
       if (project.getName().startsWith("testproject")) {
         deleteProject(project);
       }
     }
   }
 }
Esempio n. 5
0
 public static void deleteProject(final IErlProject erlProject) throws CoreException {
   final IProject project = erlProject.getWorkspaceProject();
   final IPath location = project.getLocation();
   project.delete(true, null);
   if (location != null) {
     new File(location.toPortableString()).delete();
   }
   if (modulesAndIncludes != null) {
     final List<IErlModule> list = Lists.newArrayList(modulesAndIncludes);
     for (final IErlModule module : list) {
       if (ErlangEngine.getInstance().getModelUtilService().getProject(module) == erlProject) {
         deleteModule(module);
       }
     }
   }
   erlProject.dispose();
   if (projects != null) {
     projects.remove(ErlangEngine.getInstance().getModel().findProject(project));
   }
   final IErlModel model = ErlangEngine.getInstance().getModel();
   model.resourceChanged(null);
   model.open(null);
 }
Esempio n. 6
0
 public static IErlModule createModule(
     final String moduleName, final String moduleContents, final IFolder folder)
     throws CoreException {
   final IFile file = createFile(moduleName, moduleContents, folder);
   final IErlModel model = ErlangEngine.getInstance().getModel();
   IErlModule module = model.findModule(file);
   if (module == null) {
     final String path = file.getLocation().toPortableString();
     module =
         model.getModuleFromFile(
             model, file.getName(), path, Charset.defaultCharset().name(), path);
   }
   return module;
 }
 private SearchPatternData determineInitValuesFrom(final IErlElement e) {
   final ErlangSearchPattern pattern =
       new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService())
           .getSearchPatternFromErlElementAndLimitTo(e, getLimitTo());
   if (pattern == null) {
     return null;
   }
   return new SearchPatternData(
       pattern.patternString(),
       ISearchPageContainer.WORKSPACE_SCOPE,
       LimitTo.REFERENCES,
       pattern.getSearchFor(),
       null,
       getLastIncludeMask());
 }
  public void interpretOrDeinterpret(final IErlModule module, final boolean checked) {
    if (erlangDebugTarget == null) {
      ErlLogger.warn("erlangDebugTarget is null ?!?!");
      return;
    }
    final String moduleWoExtension = module.getModuleName();
    final IProject project =
        ErlangEngine.getInstance().getModelUtilService().getProject(module).getWorkspaceProject();
    final boolean interpret = checked;

    if (erlangDebugTarget.getInterpretedModules().contains(moduleWoExtension) != interpret) {
      // FIXME this isn't correct!!!
      erlangDebugTarget.interpret(project, moduleWoExtension, distributed, interpret);
    }
    addRemove(module, checked);
  }
Esempio n. 9
0
 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);
 }
Esempio n. 10
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;
 }
Esempio n. 11
0
 public static IErlModule createModuleFromText(final String initialText) {
   final IErlModel model = ErlangEngine.getInstance().getModel();
   final IErlModule module = model.getModuleFromText(model, "test1", initialText, "test1");
   modulesAndIncludes.add(module);
   return module;
 }
Esempio n. 12
0
 public static IErlProject getExistingProject(final String name) {
   final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   final IProject project = root.getProject(name);
   return ErlangEngine.getInstance().getModel().getErlangProject(project);
 }
Esempio n. 13
0
  @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;
  }
 public ErlangProjectProperties decodeConfig(final String config) {
   ErlangProjectProperties _xblockexpression = null;
   {
     final ErlangProjectProperties result = new ErlangProjectProperties();
     Path _path = new Path("ebin");
     result.setOutputDir(_path);
     result.setSourceDirs();
     IErlangEngine _instance = ErlangEngine.getInstance();
     SimpleParserService _simpleParserService = _instance.getSimpleParserService();
     final List<OtpErlangObject> content = _simpleParserService.parse(config);
     boolean _isEmpty = content.isEmpty();
     if (_isEmpty) {
       return result;
     }
     final Procedure1<OtpErlangObject> _function =
         new Procedure1<OtpErlangObject>() {
           public void apply(final OtpErlangObject erl_opts) {
             try {
               final Bindings bindings = ErlUtils.match("{Src,Opts}", erl_opts);
               boolean _tripleNotEquals = (bindings != null);
               if (_tripleNotEquals) {
                 final String src = bindings.getAtom("Src");
                 String _xifexpression = null;
                 boolean _contains = src.contains("/");
                 if (_contains) {
                   String[] _split = src.split("/");
                   _xifexpression =
                       IterableExtensions.<String>head(
                           ((Iterable<String>) Conversions.doWrapArray(_split)));
                 } else {
                   _xifexpression = "src";
                 }
                 final String path = _xifexpression;
                 Collection<IPath> _sourceDirs = result.getSourceDirs();
                 final ArrayList<IPath> sd = new ArrayList<IPath>(_sourceDirs);
                 Path _path = new Path(path);
                 sd.add(_path);
                 result.setSourceDirs(sd);
                 final Collection<OtpErlangObject> opts = bindings.getList("Opts");
                 boolean _tripleNotEquals_1 = (opts != null);
                 if (_tripleNotEquals_1) {
                   final Procedure1<OtpErlangObject> _function =
                       new Procedure1<OtpErlangObject>() {
                         public void apply(final OtpErlangObject opt) {
                           try {
                             final Bindings b = ErlUtils.match("{Tag,Arg}", opt);
                             boolean _tripleNotEquals = (b != null);
                             if (_tripleNotEquals) {
                               EmakeConfigurationSerializer.this.parseOption(b, result);
                             }
                           } catch (Throwable _e) {
                             throw Exceptions.sneakyThrow(_e);
                           }
                         }
                       };
                   IterableExtensions.<OtpErlangObject>forEach(opts, _function);
                 }
               }
             } catch (Throwable _e) {
               throw Exceptions.sneakyThrow(_e);
             }
           }
         };
     IterableExtensions.<OtpErlangObject>forEach(content, _function);
     _xblockexpression = result;
   }
   return _xblockexpression;
 }