コード例 #1
0
  private IMarker addMarker(
      IResource resource,
      String type,
      String message,
      int lineNumber,
      int severity,
      boolean isTransient) {
    IMarker marker = null;
    try {
      if (resource.isAccessible()) {
        if (lineNumber == -1) {
          lineNumber = 1;
        }

        // mkleint: this strongly smells like some sort of workaround for a problem with bad marker
        // cleanup.
        // adding is adding and as such shall always be performed.
        marker = findMarker(resource, type, message, lineNumber, severity, isTransient);
        if (marker != null) {
          // This marker already exists
          return marker;
        }
        marker = resource.createMarker(type);
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.SEVERITY, severity);
        marker.setAttribute(IMarker.TRANSIENT, isTransient);

        marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
        log.debug("Created marker '{}' on resource '{}'.", message, resource.getFullPath());
      }
    } catch (CoreException ex) {
      log.error("Unable to add marker; " + ex.toString(), ex); // $NON-NLS-1$
    }
    return marker;
  }
コード例 #2
0
 /** @since 2.7 */
 protected void addMarkerAndLogError(URI uri, Throwable e) {
   for (Pair<IStorage, IProject> storage : getStorage2UriMapper().getStorages(uri)) {
     IResource resource = null;
     if (storage.getFirst() instanceof IResource) {
       resource = (IResource) storage.getFirst();
     } else {
       resource = storage.getSecond();
     }
     if (resource != null) {
       try {
         IMarker marker = resource.createMarker(MarkerTypes.NORMAL_VALIDATION);
         marker.setAttribute(IMarker.MESSAGE, e.getMessage() + " - See error log for details");
         marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
         marker.setAttribute(IMarker.LINE_NUMBER, 1);
       } catch (CoreException ce) {
         logger.error("Could not create marker", ce);
       }
     }
   }
   Throwable cause = e;
   if (cause instanceof CoreException) {
     cause = cause.getCause();
   }
   if (uri == null) {
     logger.error("Error during compilation.", e);
   } else {
     logger.error("Error during compilation of '" + uri + "'.", e);
   }
 }
コード例 #3
0
  private final void handleOutputLine(String line) {
    Matcher m = warningErrorPattern.matcher(line);

    if (m.find()) {
      String filename = m.group(1);
      int lineNumber = Integer.parseInt(m.group(2));
      // int colNumber = Integer.parseInt(m.group(3));
      String msg = m.group(4);

      // Determine the severity
      int severity = IMarker.SEVERITY_INFO;
      if (msg.toLowerCase().contains("error")) severity = IMarker.SEVERITY_ERROR;
      else if (msg.toLowerCase().contains("warning")) severity = IMarker.SEVERITY_WARNING;

      // Find the resource and create a marker
      for (Resource r : sourceResources) {
        IResource res = getIResource(r);
        if (filename.equals(res.getName())) {
          IMarker marker;
          try {
            marker = res.createMarker(IMarker.PROBLEM);
            marker.setAttribute(IMarker.MESSAGE, msg);
            marker.setAttribute(IMarker.SEVERITY, severity);
            marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
            marker.setAttribute(PreferenceConstants.OCARINA_MARKER, "true");
          } catch (CoreException e) {
            throw new RuntimeException(e);
          }
        }
      }
    }

    out().println(line);
  }
コード例 #4
0
 /**
  * Create a marker on the given resource
  *
  * @param resource the resource
  * @param severity the severity constant
  * @param message the message
  * @param lineNumber the line number
  */
 public void createMarker(IResource resource, int severity, String message, Integer lineNumber) {
   try {
     IMarker marker = resource.createMarker(MARKER_TYPE);
     marker.setAttribute(IMarker.MESSAGE, message);
     marker.setAttribute(IMarker.SEVERITY, severity);
     marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
   } catch (CoreException e) {
     logException(e.getMessage(), e);
   }
 }
コード例 #5
0
ファイル: MarkerUtils.java プロジェクト: jakobc/erlide
 public static IMarker createErlangLineBreakpointMarker(
     final IResource resource, final int lineNumber, final String modelIdentifier)
     throws CoreException {
   final IMarker marker = resource.createMarker("org.erlide.core.erlang.lineBreakpoint.marker");
   marker.setAttribute(IBreakpoint.ENABLED, Boolean.TRUE);
   marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
   marker.setAttribute(IBreakpoint.ID, modelIdentifier);
   marker.setAttribute(
       IMarker.MESSAGE, "Line Breakpoint: " + resource.getName() + " [line: " + lineNumber + "]");
   return marker;
 }
コード例 #6
0
 private void addMarker(int lineNumber, String text, int severity) {
   try {
     IMarker m = resource.createMarker(IMarker.PROBLEM);
     m.setAttribute(IMarker.LINE_NUMBER, lineNumber + 1);
     m.setAttribute(IMarker.MESSAGE, text);
     m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
     m.setAttribute(IMarker.SEVERITY, severity);
   } catch (CoreException e) {
     e.printStackTrace();
   }
 }
コード例 #7
0
ファイル: HLintBuilder.java プロジェクト: prark/eclipsefp
 static void createMarker(final IResource resource, final Suggestion s) throws CoreException {
   if (s.getSeverity() != Severity.IGNORE) {
     IMarker marker = resource.createMarker(HaskellCorePlugin.ID_HLINT_MARKER);
     marker.setAttribute(IMarker.MESSAGE, s.getMessage());
     marker.setAttribute(
         IMarker.SEVERITY,
         s.getSeverity() == Severity.ERROR ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_INFO);
     // marker.setAttribute( IMarker.CHAR_START, 0 );
     // marker.setAttribute( IMarker.CHAR_END, 1 );
     marker.setAttribute(IMarker.LINE_NUMBER, s.getLocation().getLine());
   }
 }
コード例 #8
0
 /*
  * (non-Javadoc)
  *
  * @see featureide.core.internal.IMarkerHandler#createModelMarker(java.lang.String,
  *      int)
  */
 public void createModelMarker(String message, int severity, int lineNumber) {
   try {
     IResource resource = modelFile.exists() ? modelFile : project;
     IMarker marker = resource.createMarker(MODEL_MARKER);
     if (marker.exists()) {
       marker.setAttribute(IMarker.MESSAGE, message);
       marker.setAttribute(IMarker.SEVERITY, severity);
       marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
     }
   } catch (CoreException e) {
     e.printStackTrace();
   }
 }
コード例 #9
0
 /**
  * Creates a marker with the specified type on this resource. Marker type ids are the id of an
  * extension installed in the <code>org.eclipse.core.resources.markers</code> extension point. The
  * specified type string must not be <code>null</code>.
  *
  * @param resource An IResource for which a marker must be added
  * @param message The message of the marker we want to display in the Problem View.
  * @param severity The severity of the marker
  * @param type the type of the marker to create
  * @return an optional Marker (none if problem during creation).
  */
 public static Option<IMarker> addMarkerFor(
     final IResource resource, final String message, final int severity, String type) {
   try {
     if (resource != null) {
       final IMarker marker = resource.createMarker(type);
       marker.setAttribute(IMarker.SEVERITY, severity);
       marker.setAttribute(IMarker.MESSAGE, message);
       return Options.newSome(marker);
     }
   } catch (final CoreException e) {
     DslCommonPlugin.getDefault().getLog().log(e.getStatus());
   }
   return Options.newNone();
 }
コード例 #10
0
  /**
   * Create marker of missing end brace.
   *
   * @param resource Marker target resource.
   * @param model Block model.
   */
  private void createMissingBraceMarker(IResource resource, BlockModel model) {
    try {
      IMarker marker = resource.createMarker(PROBLEM_MARKER_KEY);
      Map<String, Object> attribute = new HashMap<String, Object>();

      attribute.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
      attribute.put(IMarker.MESSAGE, "Missing end brace.");
      attribute.put(IMarker.LINE_NUMBER, model.getLineNumber());
      attribute.put(IMarker.CHAR_START, model.getOffset());
      attribute.put(IMarker.CHAR_END, model.getOffset() + model.getStartBrace().length());

      marker.setAttributes(attribute);
    } catch (CoreException e) {
      // log.error(e.getMessage(), e);
    }
  }
コード例 #11
0
ファイル: MarkerUtils.java プロジェクト: jakobc/erlide
 public static IMarker createSearchResultMarker(
     final IErlModule module, final String type, final int offset, final int length)
     throws CoreException {
   boolean setPath = false;
   IResource resource = module.getCorrespondingResource();
   if (resource == null) {
     resource = ResourcesPlugin.getWorkspace().getRoot();
     setPath = true;
   }
   final IMarker marker = resource.createMarker(type);
   marker.setAttribute(IMarker.CHAR_START, offset);
   marker.setAttribute(IMarker.CHAR_END, offset + length);
   if (setPath) {
     marker.setAttribute(PATH_ATTRIBUTE, module.getFilePath());
   }
   return marker;
 }
コード例 #12
0
  /**
   * Create marker of duplicate Map Entry error.
   *
   * @param resource Marker target resource.
   * @param model Map Entry model.
   */
  private void createDuplicateKeyMarker(IResource resource, NamedModel model) {
    try {
      IMarker marker = resource.createMarker(PROBLEM_MARKER_KEY);
      Map<String, Object> attribute = new HashMap<String, Object>();

      attribute.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
      attribute.put(
          IMarker.MESSAGE, "The value of the key " + model.getNameText() + " is duplicated.");
      attribute.put(IMarker.LINE_NUMBER, model.getLineNumber());
      attribute.put(IMarker.CHAR_START, model.getOffset());
      attribute.put(IMarker.CHAR_END, model.getOffset() + model.getNameText().length());

      marker.setAttributes(attribute);
    } catch (CoreException e) {
      // log.error(e.getMessage(), e);
    }
  }
コード例 #13
0
  /**
   * Create marker of statement error.
   *
   * @param resource Marker target resource.
   * @param lineNumber start line number.
   * @param charStart marker start position.
   * @param charEnd marker end position.
   */
  private void createStatementErrorMarker(
      IResource resource, int lineNumber, int charStart, int charEnd) {
    try {
      IMarker marker = resource.createMarker(PROBLEM_MARKER_KEY);
      Map<String, Object> attribute = new HashMap<String, Object>();

      attribute.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
      attribute.put(IMarker.MESSAGE, "Position of statement is invalid.");
      attribute.put(IMarker.LINE_NUMBER, lineNumber);
      attribute.put(IMarker.CHAR_START, charStart);
      attribute.put(IMarker.CHAR_END, charEnd);

      marker.setAttributes(attribute);
    } catch (CoreException e) {
      // log.error(e.getMessage(), e);
    }
  }
コード例 #14
0
ファイル: MarkerHelper.java プロジェクト: pdorobisz/erlide
 public static void addTaskMarker(
     final IResource file,
     final IResource compiledFile,
     final String message,
     int lineNumber,
     final int priority) {
   try {
     final IMarker marker = file.createMarker(TASK_MARKER);
     marker.setAttribute(IMarker.MESSAGE, message);
     marker.setAttribute(IMarker.PRIORITY, priority);
     marker.setAttribute(IMarker.SOURCE_ID, compiledFile.getFullPath().toString());
     if (lineNumber == -1) {
       lineNumber = 1;
     }
     marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
   } catch (final CoreException e) {
   }
 }
コード例 #15
0
ファイル: MarkerHelper.java プロジェクト: pdorobisz/erlide
 public static void addProblemMarker(
     final IResource file,
     final IResource compiledFile,
     final String message,
     int lineNumber,
     final int severity) {
   try {
     final IMarker marker = file.createMarker(PROBLEM_MARKER);
     marker.setAttribute(IMarker.MESSAGE, message);
     marker.setAttribute(IMarker.SEVERITY, severity);
     if (compiledFile != null) {
       marker.setAttribute(IMarker.SOURCE_ID, compiledFile.getFullPath().toString());
     }
     if (lineNumber == -1) {
       lineNumber = 1;
     }
     marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
   } catch (final CoreException e) {
   }
 }
コード例 #16
0
  public static IMarker createOrUpdateKbProblemMarker(
      IMarker m, IResource r, String message, int kind) throws CoreException {
    String preferenceValue = getPreference(r.getProject(), kind);

    String s =
        KBSeverityPreferences.getInstance()
            .getProjectPreference(
                r.getProject(), ELSeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME);

    if (SeverityPreferences.IGNORE.equals(preferenceValue) || JavaCore.DISABLED.equals(s)) {
      if (m != null) {
        m.delete();
      }
      return null;
    }

    if (m == null) {
      m = r.createMarker(KB_BUILDER_PROBLEM_MARKER_TYPE);
      m.setAttribute(KbBuilderMarker.ATTR_KIND, KbBuilderMarker.KIND_KB_NATURE_OR_BUILDER_MISSING);
      if (kind == KIND_KB_NATURE_OR_BUILDER_MISSING) {
        r.setPersistentProperty(KbProjectFactory.NATURE_MOCK, "true"); // $NON-NLS-1$
        KbProjectFactory.getKbProject(r.getProject(), true);
      }
    }

    int severity = IMarker.SEVERITY_WARNING;

    if (SeverityPreferences.ERROR.equals(preferenceValue)) {
      severity = IMarker.SEVERITY_ERROR;
    }
    String location =
        MessageFormat.format(
            KbMessages.KBPROBLEM_LOCATION, new Object[] {r.getProject().getName()});

    m.setAttribute(ATTR_KIND, kind);
    m.setAttribute(IMarker.LOCATION, location);
    m.setAttribute(IMarker.MESSAGE, message);
    m.setAttribute(IMarker.SEVERITY, severity);
    m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
    return m;
  }
  @Override
  public void connectorXReferenceAdded(final Connector connector, final IXReference xref) {
    //    	Thread thread = new Thread(new Runnable() {
    //
    //			@Override
    //			public void run() {
    if (connector.isEnvisaged()
        || ignoreViolations()
        || !isAttachedToProject(xref.getSource().getResource().getProject())) return;

    IResource resource = xref.getSource().getResource();

    try {
      IMarker marker = resource.createMarker(defaults.MARKER_TYPE);
      marker.setAttribute(IMarker.SEVERITY, getViolationSeverity());
      marker.setAttribute(
          IMarker.MESSAGE,
          "Element "
              + xref.getTarget().getName()
              + " should not be accessed in this context "
              + "("
              + connector.getSource().getName()
              + "->"
              + connector.getTarget().getName()
              + ")");

      marker.setAttribute(IMarker.CHAR_START, xref.getOffset());
      marker.setAttribute(IMarker.CHAR_END, xref.getOffset() + xref.getLength());
      marker.setAttribute(IMarker.LINE_NUMBER, xref.getLine());
      marker.setAttribute(defaults.MODEL, model.getResource().getFullPath());
      marker.setAttribute(defaults.CONNECTOR_ID, connector.toString());
      violations.put(ArchitectureModel.xrefStringFactory.toString(xref), marker.getId());
    } catch (CoreException ex) {
      // TODO: Do something better here;
      ex.printStackTrace();
    }

    //			}
    //		});thread.start();

  }
コード例 #18
0
ファイル: MarkerHelper.java プロジェクト: pdorobisz/erlide
  public void createProblemFor(
      final IResource resource,
      final IErlFunction erlElement,
      final String message,
      final int problemSeverity)
      throws CoreException {
    try {
      final IMarker marker = resource.createMarker(PROBLEM_MARKER);
      final int severity = problemSeverity;

      final ISourceRange range = erlElement == null ? null : erlElement.getNameRange();
      final int start = range == null ? 0 : range.getOffset();
      final int end = range == null ? 1 : start + range.getLength();
      marker.setAttributes(
          new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END},
          new Object[] {
            message, Integer.valueOf(severity), Integer.valueOf(start), Integer.valueOf(end)
          });
    } catch (final CoreException e) {
      throw e;
    }
  }
コード例 #19
0
ファイル: MarkerUtils.java プロジェクト: jakobc/erlide
 public static void addDialyzerWarningMarker(
     final IResource file,
     final String path,
     final String message,
     int lineNumber,
     final int severity) {
   try {
     final IMarker marker;
     if (file != null) {
       marker = file.createMarker(DIALYZE_WARNING_MARKER);
     } else {
       final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
       marker = workspaceRoot.createMarker(DIALYZE_WARNING_MARKER);
       marker.setAttribute(PATH_ATTRIBUTE, path);
     }
     marker.setAttribute(IMarker.MESSAGE, message);
     marker.setAttribute(IMarker.SEVERITY, severity);
     if (lineNumber == -1) {
       lineNumber = 1;
     }
     marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
   } catch (final CoreException e) {
   }
 }
コード例 #20
0
ファイル: AlexBuilder.java プロジェクト: baldo/eclipsefp
 static void createMarker(final IResource resource, final ProcessorError e) throws CoreException {
   IMarker marker = resource.createMarker(HaskellCorePlugin.ID_ALEX_MARKER);
   marker.setAttribute(IMarker.MESSAGE, e.getMessage());
   marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
   marker.setAttribute(IMarker.LINE_NUMBER, e.getLine());
 }
コード例 #21
0
  /** This method adds a message to a resource in the task list. */
  public static IMarker addTask(
      String pluginId,
      IResource resource,
      String location,
      String messageId,
      String message,
      int markerType,
      String markerName,
      String targetObjectName,
      String groupName,
      int offset,
      int length)
      throws CoreException {

    if ((message == null) || (resource == null) || (!resource.exists())) {
      return null;
    }

    int severity = getSeverity(markerType);

    // Allow duplicate entries in the task list.
    // Prior to a full validation, the validation framework will remove all messages owned
    // by a validator before it is executed.
    // Prior to an incremental validation, the validation framework will remove all messages,
    // on each of the changed resources, owned by a validator before it is invoked.
    //
    // It is up to the validator to make sure that it is not adding the same message
    // in more than one place, and also to clear out any old messages which are not cleared
    // by the validation framework.
    IMarker item = null;
    MarkerManager.getDefault().hook(resource);
    if (markerName != null && markerName.length() > 0)
      item = resource.createMarker(markerName); // add a validation marker
    else item = resource.createMarker(VALIDATION_MARKER); // add a validation marker

    // For performance reasons, replace the multiple setAttribute
    // calls above with a single setAttributes call.
    boolean offsetSet = ((offset != IMessage.OFFSET_UNSET) && (length != IMessage.OFFSET_UNSET));
    int size = (offsetSet) ? 10 : 8; // add CHAR_START, CHAR_END only if the offset is set. If
    // the offset is set, it takes precendence over the line
    // number. (eclipse's rule, not mine.)
    String[] attribNames = new String[size];
    Object[] attribValues = new Object[size];

    // Very first thing, add the owner. That way, if the code dies
    // before things are persisted, hopefully this marker will be persisted.
    // Hopefully, eclipse WILL persist this field, as requested.
    attribNames[0] = VALIDATION_MARKER_OWNER;
    attribValues[0] = pluginId;
    attribNames[1] = VALIDATION_MARKER_SEVERITY; // this validation severity is stored, in
    // addition to the marker severity, to enable
    // more than one severity of message to be
    // displayed. e.g. ERROR | WARNING (using
    // binary OR). The IMarker constants are
    // regular decimal constants.
    attribValues[1] = new Integer(markerType);
    attribNames[2] = VALIDATION_MARKER_TARGETOBJECT; // to distinguish between messages which
    // are registered on an IResource, but
    // against different target objects
    attribValues[2] = ((targetObjectName == null) ? "" : targetObjectName); // $NON-NLS-1$
    attribNames[3] = VALIDATION_MARKER_GROUP;
    attribValues[3] = ((groupName == null) ? "" : groupName); // $NON-NLS-1$
    attribNames[4] = IMarker.MESSAGE;
    attribValues[4] = message;
    attribNames[5] = VALIDATION_MARKER_MESSAGEID;
    attribValues[5] = messageId;

    attribNames[6] = IMarker.SEVERITY; // IMarker.SEVERITY_ERROR, IMarker.SEVERITY_WARNING,
    // IMarker.SEVERITY_INFO
    attribValues[6] = new Integer(severity);
    try {
      // If the location is a line number, store it as a line number
      Integer lineNumber = Integer.valueOf(location);
      attribNames[7] = IMarker.LINE_NUMBER;
      attribValues[7] = lineNumber;
    } catch (NumberFormatException exc) {
      // Otherwise, store it as a text location
      attribNames[7] = IMarker.LOCATION;
      attribValues[7] = location;
    }

    if (offsetSet) {
      attribNames[8] = IMarker.CHAR_START;
      attribValues[8] = new Integer(offset);
      attribNames[9] = IMarker.CHAR_END;
      attribValues[9] = new Integer(offset + length);
    }

    item.setAttributes(attribNames, attribValues);

    return item;
  }