com.sun.source.doctree.AttributeTree Java Examples

The following examples show how to use com.sun.source.doctree.AttributeTree. 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 Project: netbeans   Author: apache   File: VeryPretty.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Void visitStartElement(StartElementTree node, Void p) {
    print("<");
    print(node.getName());
    java.util.List<? extends DocTree> attrs = node.getAttributes();
    if (!attrs.isEmpty()) {
        print(" ");
        for (DocTree docTree : attrs) {
            doAccept((DCTree)docTree);
        }
        DocTree last = attrs.get(attrs.size() - 1);
        if (node.isSelfClosing() && last instanceof AttributeTree
                && ((AttributeTree) last).getValueKind() == ValueKind.UNQUOTED)
            print(" ");
    }
    if (node.isSelfClosing())
        print("/");
    print(">");
    return null;
}
 
Example #2
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateHtml4Attrs(AttributeTree tree, Name name, AttrKind k) {
    switch (k) {
        case ALL:
        case HTML4:
            break;

        case INVALID:
            env.messages.error(HTML, tree, "dc.attr.unknown", name);
            break;

        case OBSOLETE:
            env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name);
            break;

        case USE_CSS:
            env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name);
            break;

        case HTML5:
            env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name);
            break;
    }
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #4
Source Project: TencentKona-8   Author: Tencent   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    // allow URIs beginning with javascript:, which would otherwise be rejected by the URI API.
    if (uri.startsWith("javascript:"))
        return;
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #5
Source Project: jdk8u60   Author: chenghanpeng   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    // allow URIs beginning with javascript:, which would otherwise be rejected by the URI API.
    if (uri.startsWith("javascript:"))
        return;
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #9
Source Project: netbeans   Author: apache   File: ImmutableDocTreeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
protected final AttributeTree rewriteChildren(AttributeTree tree) {
    AttributeTree value = tree;
    List<? extends DocTree> vl = translateDoc(tree.getValue());
    if (vl != tree.getValue()) {
        value = make.Attribute((Name) tree.getName(), tree.getValueKind(), vl);
    }
    return value;
}
 
Example #10
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitAttribute(AttributeTree node, Void p) {
    print(node.getName());
    String quote;
    switch (node.getValueKind()) {
        case EMPTY:
            return null;
        case UNQUOTED:
            quote = "";
            break;
        case SINGLE:
            quote = "'";
            break;
        case DOUBLE:
            quote = "\"";
            break;
        default:
            throw new AssertionError();
    }
    print("=");
    print(quote);
    for (DocTree docTree : node.getValue()) {
        doAccept((DCTree)docTree);
    }
    print(quote);
    return null;
}
 
Example #11
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #12
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    // allow URIs beginning with javascript:, which would otherwise be rejected by the URI API.
    if (uri.startsWith("javascript:"))
        return;
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #13
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void validateHtml5Attrs(AttributeTree tree, Name name, AttrKind k) {
    switch (k) {
        case ALL:
        case HTML5:
            break;

        case INVALID:
        case OBSOLETE:
        case USE_CSS:
        case HTML4:
            env.messages.error(HTML, tree, "dc.attr.not.supported.html5", name);
            break;
    }
}
 
Example #14
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #15
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    // allow URIs beginning with javascript:, which would otherwise be rejected by the URI API.
    if (uri.startsWith("javascript:"))
        return;
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #16
Source Project: hottub   Author: dsrg-uoft   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #17
Source Project: hottub   Author: dsrg-uoft   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #18
Source Project: openjdk-8-source   Author: keerath   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #19
Source Project: openjdk-8-source   Author: keerath   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #20
Source Project: openjdk-8   Author: bpupadhyaya   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private String getAttrValue(AttributeTree tree) {
    if (tree.getValue() == null)
        return null;

    StringWriter sw = new StringWriter();
    try {
        new DocPretty(sw).print(tree.getValue());
    } catch (IOException e) {
        // cannot happen
    }
    // ignore potential use of entities for now
    return sw.toString();
}
 
Example #21
Source Project: openjdk-8   Author: bpupadhyaya   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void checkURI(AttributeTree tree, String uri) {
    try {
        URI u = new URI(uri);
    } catch (URISyntaxException e) {
        env.messages.error(HTML, tree, "dc.invalid.uri", uri);
    }
}
 
Example #22
Source Project: netbeans   Author: apache   File: ImmutableDocTreeTranslator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitAttribute(AttributeTree tree, Object p) {
    return rewriteChildren(tree);
}
 
Example #23
Source Project: netbeans   Author: apache   File: TreeFactory.java    License: Apache License 2.0 4 votes vote down vote up
public AttributeTree Attribute(CharSequence name, AttributeTree.ValueKind vkind, List<? extends DocTree> value) {
    return docMake.at(NOPOS).newAttributeTree((Name) names.fromString(name.toString()), vkind, value);
}
 
Example #24
Source Project: netbeans   Author: apache   File: DoctreeTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testCreateAll() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile,
            "package hierbas.del.litoral;\n"
            + "\n"
            + "public class Test {\n"
            + "\n"
            + "    /**\n"
            + "     */\n"
            + "    private void test() {\n"
            + "    }\n"
            + "}\n");
    String golden =
            "package hierbas.del.litoral;\n"
            + "\n"
            + "public class Test {\n"
            + "\n"
            + "    /**\n"
            + "     * <!-- comment -->{@docRoot}</a>&a;{@inheritDoc}{@link H#H(H, H) H}{@literal H}<a a/>{@a H}{@value H#H(H, H)}\n"
            + "     * @author H\n"
            + "     * @deprecated H\n"
            + "     * @param a H\n"
            + "     * @param <A> H\n"
            + "     * @return H\n"
            + "     * @see H#H(H, H)\n"
            + "     * @serialData H\n"
            + "     * @serialField a H#H(H, H) H\n"
            + "     * @serial H\n"
            + "     * @since H\n"
            + "     * @throws H#H(H, H) H\n"
            + "     * @H H\n"
            + "     * @version H\n"
            + "     */\n"
            + "    private void test() {\n"
            + "    }\n"
            + "}\n";

    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {
        @Override
        public void run(final WorkingCopy wc) throws IOException {
            wc.toPhase(JavaSource.Phase.RESOLVED);
            final TreeMaker make = wc.getTreeMaker();
            final DocTrees trees = wc.getDocTrees();
            new ErrorAwareTreePathScanner<Void, Void>() {
                @Override
                public Void visitMethod(final MethodTree mt, Void p) {
                    DocCommentTree docTree = trees.getDocCommentTree(getCurrentPath());
                    List<DocTree> firstSentence = new LinkedList<DocTree>();
                    List<DocTree> tags = new LinkedList<DocTree>();
                    
                    List<TextTree> text = Collections.singletonList(make.Text("H"));
                    IdentifierTree ident = make.DocIdentifier("a");
                    ReferenceTree reference = make.Reference((ExpressionTree)make.Type("H"), "H", Collections.<ExpressionTree>nCopies(2, (ExpressionTree)make.Type("H")));
                    AttributeTree attribute = make.Attribute("a", AttributeTree.ValueKind.EMPTY, null);

                    firstSentence.add(make.Comment("<!-- comment -->"));
                    firstSentence.add(make.DocRoot());
                    firstSentence.add(make.EndElement("a"));
                    firstSentence.add(make.Entity("a"));
                    firstSentence.add(make.InheritDoc());
                    firstSentence.add(make.Link(reference, text));
                    firstSentence.add(make.DocLiteral(text.get(0)));
                    firstSentence.add(make.StartElement("a", Collections.singletonList(attribute), true));
                    firstSentence.add(make.UnknownInlineTag("a", text));
                    firstSentence.add(make.Value(reference));

                    tags.add(make.Author(text));
                    tags.add(make.Deprecated(text));
                    tags.add(make.Param(false, ident, text));
                    tags.add(make.Param(true, make.DocIdentifier("A"), text));
                    tags.add(make.DocReturn(text));
                    tags.add(make.See(Collections.singletonList(reference)));
                    tags.add(make.SerialData(text));
                    tags.add(make.SerialField(ident, reference, text));
                    tags.add(make.Serial(text));
                    tags.add(make.Since(text));
                    tags.add(make.Throws(reference, text));
                    tags.add(make.UnknownBlockTag("H", text));
                    tags.add(make.Version(text));
                    
                    DocCommentTree newDoc = make.DocComment(firstSentence, Collections.EMPTY_LIST, tags);
                    wc.rewrite(mt, docTree, newDoc);
                    return super.visitMethod(mt, p);
                }
            }.scan(wc.getCompilationUnit(), null);
        }
    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    //System.err.println(res);
    assertEquals(golden, res);
}
 
Example #25
Source Project: netbeans   Author: apache   File: RefactoringVisitor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @since 1.47
 */
@Override
public DocTree visitAttribute(AttributeTree node, Element p) {
    return docScanner.visitAttribute(node, p, null);
}
 
Example #26
Source Project: netbeans   Author: apache   File: RefactoringVisitor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitAttribute(AttributeTree node, Element p) {
    return instance.visitAttribute(node, p);
}
 
Example #27
Source Project: netbeans   Author: apache   File: RefactoringVisitor.java    License: Apache License 2.0 4 votes vote down vote up
public DocTree visitAttribute(AttributeTree node, Element p, Void ignore) {
    return super.visitAttribute(node, p);
}
 
Example #28
Source Project: netbeans   Author: apache   File: Analyzer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Void visitAttribute(AttributeTree node, List<ErrorDescription> errors) {
    return super.visitAttribute(node, errors);
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JavaScriptScanner.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitAttribute(AttributeTree tree, Consumer<DocTreePath> f) {
    String name = tree.getName().toString().toLowerCase(Locale.ENGLISH);
    switch (name) {
        // See https://www.w3.org/TR/html-markup/global-attributes.html#common.attrs.event-handler
        case "onabort":  case "onblur":  case "oncanplay":  case "oncanplaythrough":
        case "onchange":  case "onclick":  case "oncontextmenu":  case "ondblclick":
        case "ondrag":  case "ondragend":  case "ondragenter":  case "ondragleave":
        case "ondragover":  case "ondragstart":  case "ondrop":  case "ondurationchange":
        case "onemptied":  case "onended":  case "onerror":  case "onfocus":  case "oninput":
        case "oninvalid":  case "onkeydown":  case "onkeypress":  case "onkeyup":
        case "onload":  case "onloadeddata":  case "onloadedmetadata":  case "onloadstart":
        case "onmousedown":  case "onmousemove":  case "onmouseout":  case "onmouseover":
        case "onmouseup":  case "onmousewheel":  case "onpause":  case "onplay":
        case "onplaying":  case "onprogress":  case "onratechange":  case "onreadystatechange":
        case "onreset":  case "onscroll":  case "onseeked":  case "onseeking":
        case "onselect":  case "onshow":  case "onstalled":  case "onsubmit":  case "onsuspend":
        case "ontimeupdate":  case "onvolumechange":  case "onwaiting":

        // See https://www.w3.org/TR/html4/sgml/dtd.html
        // Most of the attributes that take a %Script are also defined as event handlers
        // in HTML 5. The one exception is onunload.
        // case "onchange":  case "onclick":   case "ondblclick":  case "onfocus":
        // case "onkeydown":  case "onkeypress":  case "onkeyup":  case "onload":
        // case "onmousedown":  case "onmousemove":  case "onmouseout":  case "onmouseover":
        // case "onmouseup":  case "onreset":  case "onselect":  case "onsubmit":
        case "onunload":
            f.accept(getCurrentPath());
            break;

        // See https://www.w3.org/TR/html4/sgml/dtd.html
        //     https://www.w3.org/TR/html5/
        // These are all the attributes that take a %URI or a valid URL potentially surrounded
        // by spaces
        case "action":  case "cite":  case "classid":  case "codebase":  case "data":
        case "datasrc":  case "for":  case "href":  case "longdesc":  case "profile":
        case "src":  case "usemap":
            List<? extends DocTree> value = tree.getValue();
            if (value != null && !value.isEmpty() && value.get(0).getKind() == Kind.TEXT) {
                String v = value.get(0).toString().trim().toLowerCase(Locale.ENGLISH);
                if (v.startsWith("javascript:")) {
                    f.accept(getCurrentPath());
                }
            }
            break;
    }
    return super.visitAttribute(tree, f);
}
 
Example #30
Source Project: lua-for-android   Author: qtiuto   File: DocTreeFactory.java    License: BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create a new {@code AttributeTree} object, to represent an HTML attribute in an HTML tag.
 * @param name  the name of the attribute
 * @param vkind the kind of attribute value
 * @param value the value, if any, of the attribute
 * @return an {@code AttributeTree} object
 */
AttributeTree newAttributeTree(Name name, ValueKind vkind, List<? extends DocTree> value);