Exemple #1
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 #2
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 #3
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 (!BuilderHelper.samePath(resource.getLocation().toString(), fileName)) {
          final IProject project = resource.getProject();
          res = BuilderHelper.findResourceByLocation(project, fileName);
          if (res == null) {
            try {
              final IErlModel model = ErlangCore.getModel();
              final String includeFile =
                  ModelUtils.findIncludeFile(
                      project, fileName, model.getExternalIncludes(model.findProject(project)));
              if (includeFile != null) {
                final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                res = workspaceRoot;
              }
            } 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, fileName, resource, msg, line, sev, "");
        } else {
          addMarker(
              resource.getProject(),
              null,
              null,
              "can't find " + fileName,
              0,
              IMarker.SEVERITY_ERROR,
              "");
          addMarker(resource, null, null, "?? " + msg, line, sev, "");
        }
      } catch (final Exception e) {
        ErlLogger.warn(e);
        ErlLogger.warn("got: %s", odata);
      }
    }
  }