Exemplo n.º 1
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);
   }
 }
 /** Return the model elements for a *.erl IFile or NO_CHILDREN for otherwise. */
 public Object[] getChildren(Object parentElement) {
   try {
     if (parentElement instanceof IFile) {
       parentElement = ModelUtils.getModule((IFile) parentElement);
     }
     if (parentElement instanceof IOpenable) {
       final IOpenable openable = (IOpenable) parentElement;
       openable.open(null);
     }
     if (parentElement instanceof IParent) {
       final IParent parent = (IParent) parentElement;
       final List<IErlElement> children = parent.getChildren();
       return children.toArray(new IErlElement[children.size()]);
     }
   } catch (final ErlModelException e) {
     ErlLogger.warn(e);
   }
   return NO_CHILDREN;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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);
      }
    }
  }