org.eclipse.wst.validation.internal.provisional.core.IMessage Java Examples

The following examples show how to use org.eclipse.wst.validation.internal.provisional.core.IMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlSourceValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidate_noProblemElements() throws IOException, CoreException {
  XmlSourceValidator validator = new XmlSourceValidator();
  validator.setHelper(new AppEngineWebXmlValidator());
  String xml = "<appengine-web-app xmlns='http://appengine.google.com/ns/1.0'>"
      + "<runtime>java8</runtime>"
      + "</appengine-web-app>";
  
  IProject project = appEngineStandardProject.getProject();
  IFile file = project.getFile("testdata.xml");
  
  file.create(ValidationTestUtils.stringToInputStream(xml), 0, null);
  
  validator.validate(reporter, file, xml.getBytes(StandardCharsets.UTF_8));
  List<IMessage> messages = reporter.getMessages();
  if (!messages.isEmpty()) {
    Assert.fail(messages.get(0).getText());
  }
}
 
Example #2
Source File: ValidationUtilsTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetOffsetMap_mixedXml() {
  problems.clear();
  byte[] bytes = MIXED_XML_WITH_PROJECT_ID.getBytes(StandardCharsets.UTF_8);
  DocumentLocation start = new DocumentLocation(3, 13);
  ElementProblem problem = new ElementProblem(
      "application", 
      "", 
      IMarker.SEVERITY_WARNING, 
      IMessage.NORMAL_SEVERITY, 
      start, 
      1, 
      null);
  problems.add(problem);
  Map<ElementProblem, Integer> map = ValidationUtils.getOffsetMap(bytes, problems, "UTF-8");
  assertEquals(1, map.size());
  int offset = map.get(problem);
  assertEquals(21, offset);
}
 
Example #3
Source File: XmlValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateMarker() throws CoreException {
  IFile file = createBogusProjectFile();
  String message = "Project ID should be specified at deploy time.";
  ElementProblem element = new ElementProblem(
      message,
      IMarker.PROBLEM,
      IMarker.SEVERITY_WARNING,
      IMessage.NORMAL_SEVERITY,
      new DocumentLocation(0, 0),
      0,
      null);
  XmlValidator.createMarker(file, element);
  IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
  ArrayAssertions.assertSize(1, markers);
  assertEquals(message, markers[0].getAttribute(IMarker.MESSAGE));
}
 
Example #4
Source File: ElementProblemTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testElementProblemConstructor_nullElementName() {
  try {
    new ElementProblem(
        null,
        "org.eclipse.core.resources.problemmarker",
        IMarker.SEVERITY_WARNING,
        IMessage.NORMAL_SEVERITY,
        new DocumentLocation(4, 4),
        0,
        null);
    fail();
  } catch (NullPointerException ex) {
    assertNotNull(ex.getMessage());
  }
}
 
Example #5
Source File: ElementProblemTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testElementProblemConstructor_nullLocation() {
  try {
    new ElementProblem(
        "test",
        "org.eclipse.core.resources.problemmarker",
        IMarker.SEVERITY_WARNING,
        IMessage.NORMAL_SEVERITY,
        null,
        0,
        null);
    fail();
  } catch (NullPointerException ex) {
    assertNotNull(ex.getMessage());
  }
}
 
Example #6
Source File: ReporterMessagePlacementStrategy.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public IMessage placeValidationResult(IResource resource, IDocument document,
    IRegion position, String message, int severity) {
  IMessage validationMessage = new LocalizedMessage(
      severityFromIMarkerSeverity(severity), message);
  validationMessage.setLength(position.getLength());
  validationMessage.setOffset(position.getOffset());

  reporter.addMessage(validator, validationMessage);
  return validationMessage;
}
 
Example #7
Source File: ReporterMessagePlacementStrategy.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static int severityFromIMarkerSeverity(int imarkerSeverity) {
  switch (imarkerSeverity) {
    case IMarker.SEVERITY_ERROR:
      return IMessage.HIGH_SEVERITY;

    case IMarker.SEVERITY_WARNING:
      return IMessage.NORMAL_SEVERITY;

    case IMarker.SEVERITY_INFO:
      return IMessage.LOW_SEVERITY;

    default:
      return IMessage.LOW_SEVERITY;
  }
}
 
Example #8
Source File: TypeScriptReporterCollector.java    From typescript.java with MIT License 5 votes vote down vote up
private int getSeverity(DiagnosticCategory category) {
	switch(category) {
	case Message:
		return IMessage.LOW_SEVERITY;
	case Warning:
		return IMessage.NORMAL_SEVERITY;
	default:
		return IMessage.HIGH_SEVERITY;
	}
}
 
Example #9
Source File: XmlSourceValidator.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a message from a given {@link ElementProblem}.
 */
@VisibleForTesting
void createMessage(IReporter reporter, ElementProblem problem, int offset) {
  IMessage message = new LocalizedMessage(problem.getIMessageSeverity(), problem.getMessage());
  message.setTargetObject(this);
  message.setMarkerId(problem.getMarkerId());
  // TODO offset by line
  int lineNumber = problem.getStart().getLineNumber() + 1;
  message.setLineNo(lineNumber);
  message.setOffset(offset);
  message.setLength(problem.getLength());
  message.setAttribute(IQuickAssistProcessor.class.getName(), problem.getQuickAssistProcessor());
  reporter.addMessage(this, message);
}
 
Example #10
Source File: AppEngineDeprecatedElement.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
AppEngineDeprecatedElement(String elementName, DocumentLocation start, int length) {
  super(
    AppEngineWebProblems.getDeprecatedElementMessage(elementName),
    AppEngineWebProblems.getMarkerId(elementName),
    IMarker.SEVERITY_WARNING,
    IMessage.NORMAL_SEVERITY,
    start,
    length,
    AppEngineWebProblems.getQuickAssistProcessor(elementName));
}
 
Example #11
Source File: ElementProblemTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testHashCode() {
  ElementProblem element1 = new ElementProblem(
      "message",
      "marker",
      IMarker.SEVERITY_WARNING,
      IMessage.NORMAL_SEVERITY,
      new DocumentLocation(4, 4),
      0,
      null);
  ElementProblem element2 = new ElementProblem(
      "message",
      "marker",
      IMarker.SEVERITY_WARNING,
      IMessage.NORMAL_SEVERITY,
      new DocumentLocation(4, 4),
      0,
      null);;
  ElementProblem element3 = new ElementProblem(
      "message",
      "marker2",
      IMarker.SEVERITY_WARNING,
      IMessage.NORMAL_SEVERITY,
      new DocumentLocation(4, 4),
      0,
      null);;
  assertEquals(element1.hashCode(), element2.hashCode());
  assertNotEquals(element1.hashCode(), element3.hashCode());
}
 
Example #12
Source File: XmlSourceValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateMessage() {
  XmlSourceValidator validator = new XmlSourceValidator();
  validator.setHelper(new AppEngineWebXmlValidator());
  ElementProblem element =
      new AppEngineDeprecatedElement("application", new DocumentLocation(5, 17), 0);
  validator.createMessage(reporter, element, 0);
  List<IMessage> messages = reporter.getMessages();
  assertEquals(1, messages.size());
  IMessage iMessage = messages.get(0);
  String markerId = "com.google.cloud.tools.eclipse.appengine.validation.applicationMarker";
  assertEquals(markerId, iMessage.getMarkerId());
}
 
Example #13
Source File: XmlSourceValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidate() throws IOException {
  XmlSourceValidator validator = new XmlSourceValidator();
  validator.setHelper(new WebXmlValidator());
  String xml = "<web-app xmlns='http://xmlns.jcp.org/xml/ns/javaee' version='3.1'></web-app>";
  IFile file = Mockito.mock(IFile.class);
  when(file.getProject()).thenReturn(appEngineStandardProject.getProject());
  validator.validate(reporter, file, xml.getBytes(StandardCharsets.UTF_8));
  List<IMessage> messages = reporter.getMessages();
  assertEquals(1, messages.size());
  assertEquals(
      "App Engine Standard does not support this servlet version", messages.get(0).getText());
}
 
Example #14
Source File: ServletMappingElement.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public ServletMappingElement(String servletMapping, DocumentLocation start, int length) {
  super(Messages.getString("undefined.servlet.mapping", servletMapping),
      MARKERID, IMarker.SEVERITY_ERROR, IMessage.HIGH_SEVERITY, start, length, null /* Null IQuickAssistProcessor */);
  this.servletMapping = servletMapping;
}
 
Example #15
Source File: UndefinedServletElement.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public UndefinedServletElement(String servletClassName, DocumentLocation start, int length) {
  super(Messages.getString("undefined.servlet.class", servletClassName),
      MARKERID, IMarker.SEVERITY_ERROR, IMessage.HIGH_SEVERITY, start, length, null /* Null IQuickAssistProcessor */);
  this.servletClassName = servletClassName;
}
 
Example #16
Source File: MavenPluginElement.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public MavenPluginElement(DocumentLocation start, int length) {
  super(message, markerId, IMarker.SEVERITY_WARNING, IMessage.NORMAL_SEVERITY,
      start, length, null /* Null IQuickAssistProcessor */);
}
 
Example #17
Source File: JavaServletElement.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public JavaServletElement(DocumentLocation start, int length) {
  super(MESSAGE, MARKERID, IMarker.SEVERITY_ERROR, 
      IMessage.HIGH_SEVERITY, start, length, null /* No source quick fix */);
}
 
Example #18
Source File: JspFileElement.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public JspFileElement(String jspFileName, DocumentLocation start, int length) {
  super(Messages.getString("unresolved.jsp.file", jspFileName),
      MARKER_ID, IMarker.SEVERITY_ERROR, IMessage.HIGH_SEVERITY, start, length, null /* Null IQuickAssistProcessor */);
  this.jspFileName = jspFileName;
}
 
Example #19
Source File: ObsoleteRuntime.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
ObsoleteRuntime(String message, DocumentLocation start, int length) {
  super(message, "com.google.cloud.tools.eclipse.appengine.validation.runtimeMarker",
      IMarker.SEVERITY_ERROR,
      IMessage.NORMAL_SEVERITY,
      start, length, AppEngineWebProblems.getQuickAssistProcessor("runtime"));
}
 
Example #20
Source File: ElementProblemTest.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unlikely-arg-type")
@Test
public void testEquals() {
  ElementProblem element1 = new ElementProblem(
      "message",
      "marker",
      IMarker.SEVERITY_WARNING,
      IMessage.NORMAL_SEVERITY,
      new DocumentLocation(4, 4),
      0,
      null);
  assertEquals(element1, element1);
  
  ElementProblem element2 = new ElementProblem(
      "message",
      "marker",
      IMarker.SEVERITY_WARNING,
      IMessage.NORMAL_SEVERITY,
      new DocumentLocation(4, 4),
      0,
      null);
  assertTrue(element1.equals(element2));
  assertTrue(element2.equals(element1));
  
  ElementProblem element3 =
      new ElementProblem(
        "message", 
        "markerId_1", 
        IMarker.SEVERITY_WARNING, 
        IMessage.NORMAL_SEVERITY,
        new DocumentLocation(1, 1),
        20,
        null);
  ElementProblem element4 =
      new ElementProblem(
        "message",
        "markerId_2",
        IMarker.SEVERITY_WARNING, 
        IMessage.NORMAL_SEVERITY, 
        new DocumentLocation(1, 1), 
        20, 
        null);
  assertFalse(element3.equals(element4));
  
  ElementProblem element5 =
      new ElementProblem(
        "message",
        "markerId", 
        IMarker.SEVERITY_WARNING, 
        IMessage.NORMAL_SEVERITY, 
        new DocumentLocation(1, 1),
        20, 
        null);
  ElementProblem element6 =
      new ElementProblem("message",
        "markerId", 
        IMarker.SEVERITY_WARNING, 
        IMessage.NORMAL_SEVERITY, 
        new DocumentLocation(1, 15),
        20, 
        null);
  assertFalse(element5.equals(element6));
  
  ElementProblem element7 =
      new ElementProblem("message_1",
        "markerId", 
        IMarker.SEVERITY_WARNING, 
        IMessage.NORMAL_SEVERITY, 
        new DocumentLocation(1, 1), 
        20,
        null);
  ElementProblem element8 =
      new ElementProblem("message_2", 
        "markerId", 
        IMarker.SEVERITY_WARNING, 
        IMessage.NORMAL_SEVERITY, 
        new DocumentLocation(1, 1), 
        20, 
        null);
  assertFalse(element7.equals(element8));
  
  assertFalse(element1.equals(null));
  assertFalse(element1.equals("test"));
}