Package com.google.caja.lexer

Examples of com.google.caja.lexer.FilePosition


        }
        // Sort positionless parts after ones with a position.
        long aSPos = Integer.MAX_VALUE + 1L, aEPos = Integer.MAX_VALUE + 1L;
        long bSPos = Integer.MAX_VALUE + 1L, bEPos = Integer.MAX_VALUE + 1L;
        if (a0 instanceof FilePosition) {
          FilePosition pos = (FilePosition) a0;
          aSPos = pos.startCharInFile();
          aEPos = pos.endCharInFile();
        } else if (a0 instanceof InputSource) {
          // sort file level messages before messages within file
          aSPos = aEPos = -1;
        }
        if (b0 instanceof FilePosition) {
          FilePosition pos = (FilePosition) b0;
          bSPos = pos.startCharInFile();
          bEPos = pos.endCharInFile();
        } else if (b0 instanceof InputSource) {
          // sort file level messages before messages within file
          bSPos = bEPos = -1;
        }
        int delta = Long.signum(aSPos - bSPos);
View Full Code Here


      }

      // Create a string literal to replace all the terms [start:end-1].
      // Make sure it has the same synthetic attributes and file position.
      String text = sb.toString();
      FilePosition pos = FilePosition.span(
          t.getFilePosition(), e.getNthTerm(end - 1).getFilePosition());
      CssTree.StringLiteral quotedWords = new CssTree.StringLiteral(pos, text);
      CssTree.Term quotedTerm = new CssTree.Term(pos, null, quotedWords);
      quotedTerm.getAttributes().putAll(t.getAttributes());
      quotedTerm.getAttributes().set(CssValidator.CSS_PROPERTY_PART_TYPE,
View Full Code Here

                         .endsWith("::color"))) {
            Name colorName = Name.css(
                ((CssTree.IdentLiteral) term.getExprAtom()).getValue());
            if (!stdColorMatcher.matcher(colorName.getCanonicalForm() + " ")
                .matches()) {
              FilePosition pos = term.getExprAtom().getFilePosition();
              CssTree.HashLiteral replacement = colorHash(pos, colorName);
              MessageLevel lvl = MessageLevel.LINT;
              if (replacement == null) {
                lvl = MessageLevel.ERROR;
                replacement = CssTree.HashLiteral.hex(pos, 0, 3);
View Full Code Here

        CssTree.SimpleSelector baseSelector = (CssTree.SimpleSelector)
            sel.children().get(0);

        // Use the start position of the base selector as the position of
        // the synthetic parts.
        FilePosition pos = FilePosition.endOf(
            baseSelector.getFilePosition());

        CssTree restrictClass = new CssTree.SuffixedSelectorPart(pos);

        if (!selectorMatchesClass(baseSelector, "vdoc-container___")) {
View Full Code Here

    if (!scriptsPerNode.containsKey(n)) { return null; }
    Node safe;
    switch (n.getNodeType()) {
      case Node.ELEMENT_NODE:
        Element el = (Element) n;
        FilePosition pos = Nodes.getFilePositionFor(el);
        safe = doc.createElementNS(el.getNamespaceURI(), el.getTagName());
        bones.add(new NodeBone(src, n, safe));

        for (Node child : Nodes.childrenOf(el)) {
          Node safeChild = makeSkeleton(child, src, bones);
View Full Code Here

    }
  }

  /** Emit an inlined script. */
  private void fleshOutScriptBlock(ScriptBone bone) {
    FilePosition unk = FilePosition.UNKNOWN;

    FilePosition pos = bone.body.getFilePosition();
    String sourcePath = mc.abbreviate(pos.source());
    if (bone.source.fromCache) {
      CajoledModule scriptFromCache = (CajoledModule) bone.body;
      finishBlock();
      this.js.add(new SafeJsChunk(bone.source, scriptFromCache));
    } else {
      Block scriptToWrapAndProcess = (Block) bone.body;
      emitStatement(quasiStmt(
          ""
          + "try {"
          + "  @scriptBody;"
          + "} catch (ex___) {"
          + "  ___./*@synthetic*/ getNewModuleHandler()"
          // getNewModuleHandler is appropriate since there can't be multiple
          // module handlers in play while loadModule is being called, and all
          // these exception handlers are only reachable while control is in
          // loadModule.
          + "      ./*@synthetic*/ handleUncaughtException("
          + "          ex___, onerror, @sourceFile, @line);"
          + "}",
          // TODO(ihab.awad): Will add UncajoledModule wrapper when we no longer
          // "consolidate" all scripts in an HTML file into one Caja module.
          "scriptBody", scriptToWrapAndProcess,
          "sourceFile", StringLiteral.valueOf(unk, sourcePath),
          "line", StringLiteral.valueOf(unk, String.valueOf(pos.startLineNo()))
          ),
          false,
          bone.source);
    }
  }
View Full Code Here

   *     script block.
   */
  private void fleshOutElement(NodeBone bone, boolean splitDom) {
    Element el = (Element) bone.node;
    Element safe = (Element) bone.safeNode;
    FilePosition pos = Nodes.getFilePositionFor(el);
    ElKey elKey = ElKey.forElement(el);

    // If the element is supposed to have a FRAME_TARGET attribute, set that
    // to a safe value (the actual final value of all FRAME_TARGET attributes
    // will be assigned dynamically).
View Full Code Here

    safe.setAttributeNodeNS(safeAttr);
  }

  private void emitDynamicAttr(
      Attr a, Expression dynamicValue, JobEnvelope source) {
    FilePosition pos = Nodes.getFilePositionFor(a);
    String name = a.getName();
    // Emit a statement to attach the dynamic attribute.
    if (dynamicValue instanceof FunctionConstructor) {
      emitStatement(
          quasiStmt(
View Full Code Here

        if (!expectOpen) {
          // expectOpen can only be false if lastContainer has been set below.
          assert lastContainer != null;
          // last must be an ihtml:ph without a corresponding ihtml:eph.
          markBroken(last);
          FilePosition endPos = FilePosition.endOf(
              Nodes.getFilePositionFor(lastContainer.getLastChild()));
          mq.addMessage(
              IhtmlMessageType.UNCLOSED_PLACEHOLDER,
              FilePosition.span(Nodes.getFilePositionFor(last), endPos));
          markBroken(last);
          expectOpen = true;
          last = null;
        }
        lastContainer = msg;
      }

      if (expectOpen != IHTML.isPh(el)) {
        if (expectOpen) {
          mq.addMessage(
              IhtmlMessageType.ORPHANED_PLACEHOLDER_END,
              Nodes.getFilePositionFor(el));
          markBroken(el);
        } else {
          mq.addMessage(
              IhtmlMessageType.UNCLOSED_PLACEHOLDER,
              FilePosition.span(
                  Nodes.getFilePositionFor(last),
                  FilePosition.startOf(Nodes.getFilePositionFor(el))));
          markBroken(last);
          last = el;
        }
      } else {
        last = el;
        expectOpen = !expectOpen;
      }
    }

    // Check that the last item is not an unclosed ihtml:ph.
    if (!expectOpen) {
      // expectOpen can only be false if lastContainer has been set above.
      assert lastContainer != null;
      FilePosition endPos = FilePosition.endOf(
          Nodes.getFilePositionFor(lastContainer.getLastChild()));
      mq.addMessage(
          IhtmlMessageType.UNCLOSED_PLACEHOLDER,
          FilePosition.span(Nodes.getFilePositionFor(last), endPos));
      markBroken(last);
View Full Code Here

      ElKey.forHtmlElement("script"), "src");

  private static <U> ExpressionStmt mapFromEnum(
      Iterable<U> entries, String key,
      Function<U, String> keyMaker, Function<U, Integer> valueMaker) {
    FilePosition unk = FilePosition.UNKNOWN;
    List<StringLiteral> keys = Lists.newArrayList();
    List<IntegerLiteral> values = Lists.newArrayList();
    for (U e : entries) {
      // Since enum values are public, we don't want Closure compiler
      // to rewrite them, so we need quoted keys.
View Full Code Here

TOP

Related Classes of com.google.caja.lexer.FilePosition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.