当前位置: 首页>>代码示例>>Java>>正文


Java MessageLevel类代码示例

本文整理汇总了Java中com.google.caja.reporting.MessageLevel的典型用法代码示例。如果您正苦于以下问题:Java MessageLevel类的具体用法?Java MessageLevel怎么用?Java MessageLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MessageLevel类属于com.google.caja.reporting包,在下文中一共展示了MessageLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkElementNameIsValid

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
/**
 * Checks that the element name is valid.
 *
 * @param elName Element name.
 * @param pos The current file position.
 * @return True if elName is a valid w3c element name, false otherwise.
 */
public boolean checkElementNameIsValid(ElementName elName, FilePosition pos) {
  if (!elName.custom) {
    return true;
  }

  // Custom element. We should validate it.
  try {
    return doc.createElement(elName.name) != null;
  } catch (DOMException e) {
    // Ignore DOMException's like INVALID_CHARACTER_ERR since its an html
    // document.
    mq.addMessage(MessageType.INVALID_TAG_NAME, MessageLevel.WARNING,
                  FilePosition.startOf(pos),
                  MessagePart.Factory.valueOf(elName.name));
    return false;
  }
}
 
开发者ID:google,项目名称:caja,代码行数:25,代码来源:Html5ElementStack.java

示例2: testMaskedExceptionVariablesErrorB

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testMaskedExceptionVariablesErrorB() throws Exception {
  Block n = js(fromString(
      "try { } catch (e) { function foo() { var e; } }"));

  TryStmt t = (TryStmt)n.children().get(0);
  CatchStmt c = (CatchStmt)t.children().get(1);
  Declaration d = findNodeWithIdentifier(n, Declaration.class, "foo");
  FunctionConstructor fc = (FunctionConstructor)d.getInitializer();

  Scope s0 = fromProgram(n);
  Scope s1 = Scope.fromCatchStmt(s0, c);
  Scope.fromFunctionConstructor(s1, fc);

  assertEquals(1, mq.getMessages().size());
  assertMsgType(MessageType.MASKING_SYMBOL, mq.getMessages().get(0));
  assertMsgLevel(MessageLevel.LINT, mq.getMessages().get(0));
}
 
开发者ID:google,项目名称:caja,代码行数:18,代码来源:ScopeTest.java

示例3: assertFunctionRedefined

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
private void assertFunctionRedefined(
    String code,
    boolean recurseIntoFunction,
    MessageType type,
    MessageLevel level)
    throws Exception {
  Block b = js(fromString(code));
  Scope s0 = fromProgram(b);
  if (recurseIntoFunction) {
    Scope.fromFunctionConstructor(
        s0, findFunctionConstructor(b, "foo"));
  }

  assertFalse(mq.getMessages().size() == 0);
  assertMsgType(type, mq.getMessages().get(0));
  assertMsgLevel(level, mq.getMessages().get(0));
}
 
开发者ID:google,项目名称:caja,代码行数:18,代码来源:ScopeTest.java

示例4: testDebuggerKeyword

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testDebuggerKeyword() {
  // The debugger keyword can appear in a statement context
  assertParseSucceeds("{ debugger; }");
  // but not in an expression context
  assertParseFails("(debugger);");
  assertMessage(
      MessageType.RESERVED_WORD_USED_AS_IDENTIFIER,
      MessageLevel.ERROR);
  assertParseFails("debugger();");
  assertMessage(
      MessageType.EXPECTED_TOKEN,
      MessageLevel.ERROR,
      MessagePart.Factory.valueOf(";"),
      MessagePart.Factory.valueOf("("));
  // or as an identifier.
  assertParseFails("var debugger;");
  assertMessage(
      MessageType.RESERVED_WORD_USED_AS_IDENTIFIER,
      MessageLevel.ERROR);
  assertParseFails("debugger: foo();");
  assertMessage(
      MessageType.EXPECTED_TOKEN,
      MessageLevel.ERROR,
      MessagePart.Factory.valueOf(";"),
      MessagePart.Factory.valueOf(":"));
}
 
开发者ID:google,项目名称:caja,代码行数:27,代码来源:ParserTest.java

示例5: testUnicodeInKeywords

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testUnicodeInKeywords() throws Exception {
  String[] templates = {
      "function @@ (a){}",
      "function foo(@@) {}",
      "function foo(a, @@) {}",
      "function foo(a, b) { @@(){}; }",
      "function foo(a, b) { @@: bar(){}; }"
  };
  for (Keyword k : Keyword.values()) {
    for (String template : templates) {
      String mungedKeyword = unicodeMunge(k.toString());
      String candidate = expand(template, mungedKeyword);
      try {
        js(fromString(candidate));
      } catch (Exception e) {
        assertTrue(e instanceof ParseException);
      }
      assertMessage(true, MessageType.RESERVED_WORD_USED_AS_IDENTIFIER,
                    MessageLevel.ERROR);
    }
  }
}
 
开发者ID:google,项目名称:caja,代码行数:23,代码来源:ParserTest.java

示例6: testEncodedLiterals

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testEncodedLiterals() throws Exception {
  assertEquals("255",render(jsExpr(fromString("0xff"))));
  assertEquals(Long.toString(1L << 50),
      render(jsExpr(fromString("0x" + Long.toHexString(1L << 50)))));

  assertEquals("57",render(jsExpr(fromString("071"))));
  assertMessage(
      MessageType.OCTAL_LITERAL, MessageLevel.LINT);
  mq.getMessages().clear();

  jsExpr(fromString("0x" + Long.toHexString(1L << 51)));
  assertMessage(
      MessageType.UNREPRESENTABLE_INTEGER_LITERAL, MessageLevel.WARNING);
  mq.getMessages().clear();

  assertParseFails(
      "var o = { 1E111111111111111111111111111111111111111111111111111:123};"
      );
  assertMessage(
      MessageType.MALFORMED_NUMBER,
      MessageLevel.FATAL_ERROR);
}
 
开发者ID:google,项目名称:caja,代码行数:23,代码来源:ParserTest.java

示例7: testRedundantEscapeSequences

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testRedundantEscapeSequences() throws Exception {
  // Should issue a warning if there is an escape sequence in a string where
  // the escaped character is not interpreted differently, and the escaped
  // character has a special meaning in a regular expression.

  jsExpr(fromString(" new RegExp('foo\\s+bar') "));
  assertMessage(
      MessageType.REDUNDANT_ESCAPE_SEQUENCE, MessageLevel.LINT,
      FilePosition.instance(is, 1, 13, 13, 11),
      MessagePart.Factory.valueOf("\\s"));
  mq.getMessages().clear();

  jsExpr(fromString(" new RegExp('foo\\\\s+bar') "));
  assertMessagesLessSevereThan(MessageLevel.LINT);
  mq.getMessages().clear();

  jsExpr(fromString(" '<\\/script>' "));
  assertMessagesLessSevereThan(MessageLevel.LINT);
  mq.getMessages().clear();

  jsExpr(fromString(" '\\v' "));
  assertMessage(MessageType.AMBIGUOUS_ESCAPE_SEQUENCE, MessageLevel.WARNING);
  mq.getMessages().clear();
}
 
开发者ID:google,项目名称:caja,代码行数:25,代码来源:ParserTest.java

示例8: testUnnormalizedIdentifiers

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testUnnormalizedIdentifiers() {
  // Test that identifiers not normalized to Normal Form C (Unicode NFC)
  // result in a ParseException with a useful error message.
  // According to chapter 6 of ES5, "The [source] text is expected to
  // have been normalized to Unicode Normalized Form C (canonical
  // composition)."
  try {
    js(fromString("C\0327();"));  // Normalizes to \xC7
    fail("Unnormalized identifier parsed without incident");
  } catch (ParseException ex) {
    mq.getMessages().add(ex.getCajaMessage());
  }
  assertMessage(
      MessageType.INVALID_IDENTIFIER,
      MessageLevel.ERROR,
      MessagePart.Factory.valueOf("C\0327"));
}
 
开发者ID:google,项目名称:caja,代码行数:18,代码来源:ParserTest.java

示例9: testMissingSemis

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testMissingSemis() throws ParseException {
  js(fromString("foo();"));
  assertTrue(mq.getMessages().isEmpty());

  js(fromString("foo(\n  42);"));
  assertTrue(mq.getMessages().isEmpty());

  js(fromString("foo\n(42);"));
  assertMessage(true, MessageType.MAYBE_MISSING_SEMI, MessageLevel.WARNING);
  assertTrue(mq.getMessages().isEmpty());

  js(fromString("foo[42];"));
  assertTrue(mq.getMessages().isEmpty());

  js(fromString("foo[\n  42];"));
  assertTrue(mq.getMessages().isEmpty());

  js(fromString("foo\n[42];"));
  assertMessage(true, MessageType.MAYBE_MISSING_SEMI, MessageLevel.WARNING);
  assertTrue(mq.getMessages().isEmpty());
}
 
开发者ID:google,项目名称:caja,代码行数:22,代码来源:ParserTest.java

示例10: testIllegalElementInBuilderStartTag

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testIllegalElementInBuilderStartTag() throws Exception {
  String[] htmlInput = {
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 1.0 Transitional//EN\"",
      "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
      "<html><body>",
      "<li><a href='url'>MY BOOK ON AMAZON<img.jpg\"><blah>hello</blah></a>",
      "</body></html>" };
  TokenQueue<HtmlTokenType> tq = tokenizeTestInput(
      Join.join("\n", htmlInput), false, true);
  DomParser parser = new DomParser(tq, false, mq);

  Document doc = parser.parseDocument().getOwnerDocument();
  assertEquals(1, mq.getMessages().size());
  assertMessage(MessageType.INVALID_TAG_NAME, MessageLevel.WARNING);

  Element elem = (Element) doc.getElementsByTagName("blah").item(0);
  assertEquals("hello", elem.getTextContent());

  String expected =
      "<html><head></head><body>\n" +
      "<li><a href=\"url\">MY BOOK ON AMAZON<blah>hello</blah></a>\n" +
      "</li></body></html>";
  String serialized = Nodes.render(doc);
  assertEquals(expected, serialized);
}
 
开发者ID:google,项目名称:caja,代码行数:26,代码来源:DomParserTest.java

示例11: testProcessTagMalformedTagName

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public final void testProcessTagMalformedTagName() {
  Token<HtmlTokenType> start = Token.instance(
      "<img.jpg\"", HtmlTokenType.TAGBEGIN, FilePosition.UNKNOWN);
  Token<HtmlTokenType> end = Token.instance(
      ">", HtmlTokenType.ATTRVALUE, FilePosition.UNKNOWN);
  List<AttrStub> list = Lists.newArrayList();

  stack.processTag(start, end, list);

  assertEquals(1, mq.getMessages().size());
  assertMessage(MessageType.INVALID_TAG_NAME, MessageLevel.WARNING,
      FilePosition.UNKNOWN,
      MessagePart.Factory.valueOf("img.jpg\""));

  assertNull(stack.builderRootElement());
}
 
开发者ID:google,项目名称:caja,代码行数:17,代码来源:Html5ElementStackTest.java

示例12: assertMessage

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
protected void assertMessage(
    boolean consume, final MessageTypeInt type, final MessageLevel level,
    final MessagePart... expectedParts) {
  assertMessage(
      consume,
      new Function<Message, Integer>() {
        public Integer apply(Message msg) {
          int score = 0;
          if (msg.getMessageType() == type) { ++score; }
          if (msg.getMessageLevel() == level) { ++score; }
          score -= partsMissing(msg, expectedParts);
          return score == 2 ? Integer.MAX_VALUE : score;
        }
      },
      "type " + type + " and level " + level);
}
 
开发者ID:google,项目名称:caja,代码行数:17,代码来源:CajaTestCase.java

示例13: formatErrors

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
private Element formatErrors(Document doc, InputSource is,
    CharSequence orig, MessageQueue mq) {
  MessageContext mc = new MessageContext();
  Map<InputSource, CharSequence> originalSrc = Maps.newHashMap();
  originalSrc.put(is, orig);
  mc.addInputSource(is);
  SnippetProducer sp = new SnippetProducer(originalSrc, mc);

  StringBuilder messageText = new StringBuilder();
  for (Message msg : mq.getMessages()) {
    // Ignore LINT messages
    if (MessageLevel.LINT.compareTo(msg.getMessageLevel()) <= 0) {
      String snippet = sp.getSnippet(msg);
      messageText.append(msg.getMessageLevel().name())
                 .append(" ")
                 .append(html(msg.format(mc)));

      if (!StringUtils.isEmpty(snippet)) {
        messageText.append("\n").append(snippet);
      }
    }
  }
  Element errElement = doc.createElement("pre");
  errElement.appendChild(doc.createTextNode(messageText.toString()));
  return errElement;
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:27,代码来源:CajaContentRewriter.java

示例14: parseImpl

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
private CssTree.StyleSheet parseImpl(String css) throws ParseException {
  InputSource inputSource = new InputSource(FAKE_SOURCE);
  CharProducer producer = CharProducer.Factory.create(new StringReader(css),
      inputSource);
  TokenStream<CssTokenType> lexer = new CssLexer(producer);
  TokenQueue<CssTokenType> queue = new TokenQueue<CssTokenType>(lexer, inputSource,
      new Criterion<Token<CssTokenType>>() {
        public boolean accept(Token<CssTokenType> t) {
          return CssTokenType.SPACE != t.type
              && CssTokenType.COMMENT != t.type;
        }
      });
  if (queue.isEmpty()) {
    // Return empty stylesheet
    return new CssTree.StyleSheet(null, Collections.<CssTree.CssStatement>emptyList());
  }
  MessageQueue mq = new SimpleMessageQueue();
  CssParser parser = new CssParser(queue, mq, MessageLevel.WARNING);
  return parser.parseStyleSheet();
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:21,代码来源:CajaCssParser.java

示例15: getMessageLevels

import com.google.caja.reporting.MessageLevel; //导入依赖的package包/类
public static String[] getMessageLevels() {
  MessageLevel[] values = MessageLevel.values();
  String[] result = new String[values.length];
  for (int i = 0; i < values.length; i++) {
    result[i] = values[i].name();
  }
  return result;
}
 
开发者ID:google,项目名称:caja,代码行数:9,代码来源:GWTCajolingServiceImpl.java


注:本文中的com.google.caja.reporting.MessageLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。