Exemple #1
0
 /*
  * (non-Javadoc) Method declared on SelectionDispatchAction.
  */
 @Override
 public void run(final ITextSelection selection) {
   final ErlangEditor editor = (ErlangEditor) getSite().getPage().getActiveEditor();
   editor.reconcileNow();
   final IErlModule module = editor.getModule();
   if (module == null) {
     return;
   }
   final Backend b = ErlangCore.getBackendManager().getIdeBackend();
   final int offset = selection.getOffset();
   try {
     final IErlProject erlProject = module.getErlProject();
     final IErlModel model = ErlangCore.getModel();
     final OpenResult res =
         ErlideOpen.open(
             b,
             ErlangToolkit.createScannerModuleName(module),
             offset,
             ErlModelUtils.getImportsAsList(module),
             model.getExternalModules(erlProject),
             model.getPathVars());
     ErlLogger.debug("open " + res);
     openOpenResult(editor, module, b, offset, erlProject, res);
   } catch (final Exception e) {
     ErlLogger.warn(e);
   }
 }
  public OtpErlangList getSearchPath() {
    IProject project = file.getProject();
    IErlModel model = ErlangCore.getModel();
    IErlProject actualProject = model.getErlangProject(project.getName());
    OldErlangProjectProperties prop = actualProject.getProperties();
    IPath projectLocation = actualProject.getProject().getLocation();

    List<String> sourcDirs = prop.getSourceDirs();
    OtpErlangString[] searchPath = new OtpErlangString[sourcDirs.size()];
    for (int i = 0; i < sourcDirs.size(); ++i) {
      searchPath[i] = new OtpErlangString(projectLocation.append(sourcDirs.get(i)).toOSString());
    }
    return new OtpErlangList(searchPath);
  }
Exemple #3
0
 public static void openOpenResult(
     final ErlangEditor editor,
     final IErlModule module,
     final Backend backend,
     final int offset,
     final IErlProject erlProject,
     final OpenResult res)
     throws CoreException, ErlModelException, PartInitException, BadLocationException,
         OtpErlangRangeException, BackendException {
   final IErlModel model = ErlangCore.getModel();
   final IProject project = erlProject == null ? null : erlProject.getProject();
   final IErlElement element = editor.getElementAt(offset, true);
   IErlElement foundElement = null;
   ISourceRange foundSourceRange = null;
   final boolean checkAllProjects = NavigationPreferencePage.getCheckAllProjects();
   if (res.isExternalCall()) {
     foundElement = findExternalCallOrType(module, res, project, element, checkAllProjects);
   } else if (res.isInclude()) {
     foundElement = findInclude(module, erlProject, res, model, project);
   } else if (res.isLocalCall()) {
     foundElement =
         findLocalCall(module, backend, erlProject, res, project, element, checkAllProjects);
   } else if (res.isVariable() && element instanceof ISourceReference) {
     final ISourceReference sref = (ISourceReference) element;
     final ISourceRange range = sref.getSourceRange();
     final String elementText = editor.getDocument().get(range.getOffset(), range.getLength());
     foundSourceRange = ErlModelUtils.findVariable(backend, range, res.getName(), elementText);
   } else if (res.isRecord() || res.isMacro()) {
     final IErlElement.Kind kind =
         res.isMacro() ? IErlElement.Kind.MACRO_DEF : IErlElement.Kind.RECORD_DEF;
     foundElement =
         ErlModelUtils.findPreprocessorDef(
             backend, project, module, res.getName(), kind, model.getExternalIncludes(erlProject));
   }
   if (foundElement != null) {
     ErlModelUtils.openElement(foundElement);
   } else if (foundSourceRange != null) {
     ErlModelUtils.openSourceRange(module, foundSourceRange);
   }
 }
Exemple #4
0
 private static IErlElement findLocalCall(
     final IErlModule module,
     final Backend backend,
     final IErlProject erlProject,
     final OpenResult res,
     final IProject project,
     final IErlElement element,
     final boolean checkAllProjects)
     throws ErlModelException, BackendException {
   if (ErlModelUtils.isTypeDefOrRecordDef(element)) {
     return ModelUtils.findTypespec(module, res.getFun());
   }
   final IErlFunction foundElement = ModelUtils.findFunction(module, res.getFunction());
   if (foundElement != null) {
     return foundElement;
   }
   // not local imports
   OtpErlangObject res2 = null;
   String moduleName = null;
   if (module != null) {
     final IErlImport ei = module.findImport(res.getFunction());
     if (ei != null) {
       moduleName = ei.getImportModule();
       final IErlModel model = ErlangCore.getModel();
       res2 =
           ErlideOpen.getSourceFromModule(
               backend, model.getPathVars(), moduleName, model.getExternalModules(erlProject));
     }
   }
   if (res2 instanceof OtpErlangString && moduleName != null) {
     final OtpErlangString otpErlangString = (OtpErlangString) res2;
     final String modulePath = otpErlangString.stringValue();
     return ErlModelUtils.findExternalFunction(
         moduleName, res.getFunction(), modulePath, project, checkAllProjects, module);
   } else {
     return ErlModelUtils.findExternalFunction(
         moduleName, res.getFunction(), null, project, checkAllProjects, module);
   }
 }
Exemple #5
0
 private static IErlElement findInclude(
     final IErlModule module,
     final IErlProject erlProject,
     final OpenResult res,
     final IErlModel model,
     final IProject project)
     throws CoreException {
   final IContainer parent = module == null ? null : module.getResource().getParent();
   IResource r =
       ResourceUtil.recursiveFindNamedResourceWithReferences(
           project, res.getName(), PluginUtils.getIncludePathFilter(project, parent));
   if (r == null) {
     final String includeFile =
         ModelUtils.findIncludeFile(project, res.getName(), model.getExternalIncludes(erlProject));
     if (includeFile != null) {
       r = ResourceUtil.openExternal(includeFile);
     }
   }
   if (r instanceof IFile) {
     final IFile file = (IFile) r;
     return model.findModule(file);
   }
   return null;
 }
Exemple #6
0
  /**
   * Add error markers from a list of error tuples
   *
   * @param resource
   * @param errorList
   */
  public static void addErrorMarkers(final IResource resource, final OtpErlangList errorList) {
    for (final OtpErlangObject odata : errorList.elements()) {
      try {
        final OtpErlangTuple data = (OtpErlangTuple) odata;

        String msg = ErlUtils.asString(data.elementAt(2));
        if (msg.length() > 1000) {
          msg = msg.substring(0, 1000) + "......";
        }
        final String fileName = (String) TypeConverter.erlang2java(data.elementAt(1), String.class);
        IResource res = resource;
        if (!BuilderUtils.samePath(resource.getLocation().toString(), fileName)) {
          final IProject project = resource.getProject();
          res = BuilderUtils.findResourceByLocation(project, fileName);
          if (res == null) {
            try {
              final IErlModel model = ErlangCore.getModel();
              final String includeFile =
                  ModelUtils.findIncludeFile(
                      project,
                      fileName,
                      model.getExternal(model.findProject(project), ErlangCore.EXTERNAL_INCLUDES));
              if (includeFile != null) {
                res = ResourceUtil.openExternal(includeFile);
              }
            } catch (final Exception e) {
              ErlLogger.warn(e);
            }
          }
        }
        int line = 0;
        if (data.elementAt(0) instanceof OtpErlangLong) {
          try {
            line = ((OtpErlangLong) data.elementAt(0)).intValue();
          } catch (final OtpErlangRangeException e) {
          }
        }
        int sev = IMarker.SEVERITY_INFO;
        try {
          switch (((OtpErlangLong) data.elementAt(3)).intValue()) {
            case 0:
              sev = IMarker.SEVERITY_ERROR;
              break;
            case 1:
              sev = IMarker.SEVERITY_WARNING;
              break;
            default:
              sev = IMarker.SEVERITY_INFO;
              break;
          }
        } catch (final OtpErlangRangeException e) {
        }

        if (res != null) {
          addMarker(res, resource, msg, line, sev, "");
        } else {
          addMarker(
              resource.getProject(), null, "can't find " + fileName, 0, IMarker.SEVERITY_ERROR, "");
          addMarker(resource, null, "?? " + msg, line, sev, "");
        }
      } catch (final Exception e) {
        ErlLogger.warn(e);
        ErlLogger.warn("got: %s", odata);
      }
    }
  }
 /**
  * Create the PropertiesContentProvider instance.
  *
  * <p>Adds the content provider as a resource change listener to track changes on disk.
  */
 public ErlangFileContentProvider() {
   ResourcesPlugin.getWorkspace()
       .addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
   final IErlModel mdl = ErlangCore.getModel();
   mdl.addModelChangeListener(this);
 }