Java 类org.eclipse.xtext.ui.MarkerTypes 实例源码

项目:n4js    文件:ProjectUtils.java   
/**
 * Asserts that the given resource (usually an N4JS file) contains issues with the given messages and no other
 * issues. Each message given should be prefixed with the line numer where the issues occurs, e.g.:
 *
 * <pre>
 * line 5: Couldn't resolve reference to identifiable element 'unknown'.
 * </pre>
 *
 * Column information is not provided, so this method is not intended for several issues within a single line.
 */
public static void assertIssues(final IResource resource, String... expectedMessages) throws CoreException {
    final IMarker[] markers = resource.findMarkers(MarkerTypes.ANY_VALIDATION, true, IResource.DEPTH_INFINITE);
    final String[] actualMessages = new String[markers.length];
    for (int i = 0; i < markers.length; i++) {
        final IMarker m = markers[i];
        actualMessages[i] = "line " + MarkerUtilities.getLineNumber(m) + ": " + m.getAttribute(IMarker.MESSAGE);
    }
    if (!Objects.equals(
            new HashSet<>(Arrays.asList(actualMessages)),
            new HashSet<>(Arrays.asList(expectedMessages)))) {
        final Joiner joiner = Joiner.on("\n    ");
        final String msg = "expected these issues:\n"
                + "    " + joiner.join(expectedMessages) + "\n"
                + "but got these:\n"
                + "    " + joiner.join(actualMessages);
        System.out.println("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
        System.out.println(msg);
        System.out.println("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
        Assert.fail(msg);
    }
}
项目:n4js    文件:ListBasePluginTest.java   
@SuppressWarnings("javadoc")
@Test
public void testListBase() throws Exception {
    IProject project = ProjectUtils.importProject(new File("probands"), "ListBase");
    IResourcesSetupUtil.waitForBuild();
    IFile underscore_js = project.getFile("src/underscore/underscore.n4js");
    assertTrue(underscore_js.exists());
    assertMarkers(underscore_js + " should have no errors, one unused variable warning", underscore_js, 1);

    IFile listbase_js = project.getFile("src/n4/lang/ListBase.n4js");

    assertTrue(listbase_js.exists());

    final Collection<IMarker> allMarkers = newHashSet(listbase_js.findMarkers(MarkerTypes.ANY_VALIDATION, true,
            IResource.DEPTH_INFINITE));
    assertTrue(format(EXPECTED_NUMBER_OF_ISSUE_TEMPLATE, allMarkers.size()),
            NUMBER_OF_EXPECTED_ISSUES == allMarkers.size());

    long unexpectedMarkerCount = allMarkers.stream()
            .filter(EXPECTED_VALIDATION_PREDICATE.negate())
            .count();

    assertTrue("Unexpected validation issues were found. " + toString(allMarkers), unexpectedMarkerCount == 0);
}
项目:dsl-devkit    文件:ValidMarkerUpdateJob.java   
/**
 * Validate the given resource and create the corresponding markers. The CheckMode is a constant calculated from the constructor
 * parameters.
 *
 * @param resourceValidator
 *          the resource validator (not null)
 * @param file
 *          the EFS file (not null)
 * @param resource
 *          the EMF resource (not null)
 * @param monitor
 *          the monitor (not null)
 */
protected void validate(final IResourceValidator resourceValidator, final IFile file, final Resource resource, final IProgressMonitor monitor) {
  try {
    monitor.subTask("validating " + file.getName()); //$NON-NLS-1$

    final List<Issue> list = resourceValidator.validate(resource, checkMode, getCancelIndicator(monitor));
    if (list != null) {
      // resourceValidator.validate returns null if canceled (and not an empty list)
      file.deleteMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
      file.deleteMarkers(MarkerTypes.NORMAL_VALIDATION, true, IResource.DEPTH_ZERO);
      if (performExpensiveValidation) {
        file.deleteMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);
      }
      for (final Issue issue : list) {
        markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
      }
    }
  } catch (final CoreException e) {
    LOGGER.error(e.getMessage(), e);
  } finally {
    monitor.worked(1);
  }
}
项目:bts    文件:LanguageAwareMarkerTypeProvider.java   
protected void setMarkerTypes(String baseName) {
    MarkerTypesModel markerTypesModel = MarkerTypesModel.getInstance();
    String markerType = baseName + ".check.fast";
    if (markerTypesModel.getType(markerType) == null) {
        markerType = MarkerTypes.FAST_VALIDATION;
    }
    fastValidationMarker = markerType;
    markerType = baseName + ".check.normal";
    if (markerTypesModel.getType(markerType) == null) {
        markerType = MarkerTypes.NORMAL_VALIDATION;
    }
    normalValidationMarker = markerType;
    markerType = baseName + ".check.expensive";
    if (markerTypesModel.getType(markerType) == null) {
        markerType = MarkerTypes.EXPENSIVE_VALIDATION;
    }
    expensiveValidationMarker = markerType;
}
项目:bts    文件:MarkerResolutionGenerator.java   
public IMarkerResolution[] getResolutions(IMarker marker) {
    final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
    try {
        if(!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION))
            return emptyResult;
    } catch (CoreException e) {
        return emptyResult;
    }
    if(!languageResourceHelper.isLanguageResource(marker.getResource())) {
        return emptyResult;
    }
    XtextEditor editor = getEditor(marker.getResource());
    if(editor == null)
        return emptyResult;

    IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
    if(annotationModel != null && !isMarkerStillValid(marker, annotationModel))
        return emptyResult;

    final Iterable<IssueResolution> resolutions = getResolutions(getIssueUtil().createIssue(marker), editor.getDocument());
    return getAdaptedResolutions(Lists.newArrayList(resolutions));
}
项目:dsl-devkit    文件:CheckMarkerUpdateJob.java   
/**
 * Validate the given resource and create the corresponding markers. The CheckMode is a constant calculated from the constructor
 * parameters.
 * 
 * @param resourceValidator
 *          the resource validator (not null)
 * @param markerCreator
 *          the marker creator
 * @param file
 *          the EFS file (not null)
 * @param resource
 *          the EMF resource (not null)
 * @param monitor
 *          the monitor (not null)
 */
protected void validate(final IResourceValidator resourceValidator, final MarkerCreator markerCreator, final IFile file, final Resource resource, final IProgressMonitor monitor) {
  try {
    monitor.subTask("validating " + file.getName()); //$NON-NLS-1$

    final List<Issue> list = resourceValidator.validate(resource, checkMode, getCancelIndicator(monitor));
    if (list != null) {
      // resourceValidator.validate returns null if canceled (and not an empty list)
      file.deleteMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
      file.deleteMarkers(MarkerTypes.NORMAL_VALIDATION, true, IResource.DEPTH_ZERO);
      file.deleteMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);

      if (markerCreator != null) {
        for (final Issue issue : list) {
          markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
        }
      } else {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.error("Could not create markers. The marker creator is null."); //$NON-NLS-1$
        }
      }
    }
  } catch (final CoreException e) {
    LOGGER.error(e.getMessage(), e);
  } finally {
    monitor.worked(1);
  }
}
项目:bts    文件:MarkerEraser.java   
/**
 * Deletes {@link IFile}'s markers which type matches the given {@link CheckType}s represented by the
 * {@link CheckMode}.
 * 
 * @see CheckType
 * @see CheckMode#shouldCheck(CheckType)
 * @see MarkerTypes#forCheckType(CheckType)
 */
public final void deleteMarkers(final IFile file, final CheckMode checkMode, final IProgressMonitor monitor)
        throws CoreException {
    for (CheckType chkType : CheckType.values()) {
        if (checkMode.shouldCheck(chkType)) {
            String markerType = MarkerTypes.forCheckType(chkType);
            file.deleteMarkers(markerType, true, IResource.DEPTH_ZERO);
        }
    }
}
项目:bts    文件:IssueUtil.java   
/**
 * @since 2.3
 */
protected CheckType getCheckType(IMarker marker) {
    String markerType = MarkerUtilities.getMarkerType(marker);
    if (markerTypeProvider != null)
        return markerTypeProvider.getCheckType(markerType);
    return MarkerTypes.toCheckType(markerType);
}
项目:bts    文件:AnnotationIssueProcessor.java   
protected void updateMarkerAnnotations(IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return;
    }

    Iterator<MarkerAnnotation> annotationIterator = Iterators.filter(annotationModel.getAnnotationIterator(),
            MarkerAnnotation.class);

    // every markerAnnotation produced by fast validation can be marked as deleted.
    // If its predicate still holds, the validation annotation will be covered anyway.
    while (annotationIterator.hasNext() && !monitor.isCanceled()) {
        final MarkerAnnotation annotation = annotationIterator.next();
        if (!annotation.isMarkedDeleted())
            try {
                if (isRelevantAnnotationType(annotation.getType())) {
                    boolean markAsDeleted = annotation.getMarker().isSubtypeOf(MarkerTypes.FAST_VALIDATION);
                    if (markAsDeleted) {
                        annotation.markDeleted(true);
                        queueOrFireAnnotationChangedEvent(annotation);
                    }
                }
            } catch (CoreException e) {
                // marker type cannot be resolved - keep state of annotation
            }
    }
    fireQueuedEvents();
}
项目:n4js    文件:ProjectUtils.java   
/***/
public static IMarker[] assertMarkers(String assertMessage, final IProject project, int count)
        throws CoreException {

    return assertMarkers(assertMessage, project, MarkerTypes.ANY_VALIDATION, count);
}
项目:n4js    文件:ProjectUtils.java   
/***/
public static IMarker[] assertMarkers(String assertMessage, final IResource resource, int count)
        throws CoreException {
    return assertMarkers(assertMessage, resource, MarkerTypes.ANY_VALIDATION, count);
}
项目:n4js    文件:ProjectUtils.java   
/***/
public static IMarker[] assertMarkers(String assertMessage, final IResource resource, int count,
        final Predicate<IMarker> markerPredicate) throws CoreException {

    return assertMarkers(assertMessage, resource, MarkerTypes.ANY_VALIDATION, count, markerPredicate);
}
项目:n4js    文件:N4JSIssue.java   
@Override
public Issue createIssue(IMarker marker) {
    final N4JSIssue issue = new N4JSIssue();
    issue.setMarker(marker);

    // ---- BEGIN: copied from super class ----

    try {
        Map<String, Object> attributes = marker.getAttributes();
        String markerType = marker.getType();
        Object message = attributes.get(IMarker.MESSAGE);
        issue.setMessage(message instanceof String ? (String) message : null);
        Object lineNumber = attributes.get(IMarker.LINE_NUMBER);
        issue.setLineNumber(lineNumber instanceof Integer ? (Integer) lineNumber - 1 : null);
        Object offset = attributes.get(IMarker.CHAR_START);
        Object endOffset = attributes.get(IMarker.CHAR_END);
        if (offset instanceof Integer && endOffset instanceof Integer) {
            issue.setOffset((Integer) offset);
            issue.setLength((Integer) endOffset - (Integer) offset);
        } else {
            issue.setOffset(-1);
            issue.setLength(0);
        }
        Object code = attributes.get(Issue.CODE_KEY);
        issue.setCode(code instanceof String ? (String) code : null);
        Object data = attributes.get(Issue.DATA_KEY);
        issue.setData(data instanceof String ? Strings.unpack((String) data) : null);
        Object uri = attributes.get(Issue.URI_KEY);
        issue.setUriToProblem(uri instanceof String ? URI.createURI((String) uri) : null);
        Object severity = attributes.get(IMarker.SEVERITY);
        Severity translatedSeverity = translateSeverity(severity instanceof Integer ? (Integer) severity : 0);
        if (translatedSeverity == null)
            throw new IllegalArgumentException(marker.toString());
        issue.setSeverity(translatedSeverity);
        if (markerTypeProvider != null)
            issue.setType(markerTypeProvider.getCheckType(markerType));
        else
            issue.setType(MarkerTypes.toCheckType(markerType));
    } catch (CoreException e) {
        return null;
    }
    return issue;

    // ---- END: copied from super class ----
}
项目:bts    文件:MarkerTypeProvider.java   
public String getMarkerType(Issue issue) {
    return MarkerTypes.forCheckType(issue.getType());
}
项目:bts    文件:MarkerTypeProvider.java   
public CheckType getCheckType(String markerType) {
    return MarkerTypes.toCheckType(markerType);
}
项目:CooperateModelingEnvironment    文件:CooperateAnnotationModelListener.java   
private static Collection<String> getAvailableMarkerTypes() {
    return Collections.unmodifiableCollection(
            Arrays.asList(CheckType.values()).stream().map(MarkerTypes::forCheckType).collect(Collectors.toSet()));
}