Пример #1
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;
 }
Пример #2
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);
      }
    }
  }