@Override public void visit(Element node) { for(ElementVisitor visitor : visitors) { visitor.visit(node); } }
/** * Returns the source node with the specified ID. * * @param root root of the source tree to search. * @param id ID of the desired source node. * @return source node with the specified ID or {@code null} * if such a node doesn't exist. */ private static org.netbeans.modules.html.editor.lib.api.elements.Node findElementByID(org.netbeans.modules.html.editor.lib.api.elements.Node root, String id) { org.netbeans.modules.html.editor.lib.api.elements.Node result = null; if (root instanceof OpenTag) { OpenTag tag = (OpenTag)root; Attribute attr = tag.getAttribute("id"); // NOI18N CharSequence seq = (attr == null) ? null : attr.unquotedValue(); String nodeId = (seq == null) ? null : seq.toString(); if (id.equals(nodeId)) { result = root; } else { for (org.netbeans.modules.html.editor.lib.api.elements.Element element : root.children(ElementType.OPEN_TAG)) { result = findElementByID((org.netbeans.modules.html.editor.lib.api.elements.Node)element, id); if (result != null) { break; } } } } return result; }
public static boolean isAngularAttribute(Attribute attribute) { return DirectiveConvention.getConvention(attribute.unqualifiedName()) != null; }
String sourceTagName = tag.name().toString(); if (!domNode.getNodeName().equalsIgnoreCase(sourceTagName)) { return false; Attribute sourceAttr = tag.getAttribute("id"); // NOI18N CharSequence seq = (sourceAttr == null) ? null : sourceAttr.unquotedValue(); String sourceID = (seq == null) ? null : seq.toString(); if ((domID == null) != (sourceID == null)) { attributes.put(attribute.getName().toUpperCase(), attribute.getValue()); for (Attribute attribute : tag.attributes()) { String name = attribute.name().toString().toUpperCase(); String domValue = attributes.get(name); CharSequence sourceSeq = attribute.unquotedValue(); String sourceValue = (sourceSeq == null) ? "" : sourceSeq.toString(); // NOI18N if (domValue == null || !domValue.equals(sourceValue)) {
@Override public void visit(Element node) { switch (node.type()) { case OPEN_TAG: OpenTag ot = (OpenTag) node; String name = ot.name().toString(); Tag tagModel = conf.getTag(name); Collection<Attribute> tagAttrs = ot.attributes(); Collection<String> unknownAttributeNames = new ArrayList<>(); for (Attribute a : tagAttrs) { String attrName = a.name().toString(); if (tagModel.getAttribute(attrName) == null) { OffsetRange range = new OffsetRange(snapshot.getEmbeddedOffset(ot.from()), snapshot.getEmbeddedOffset(ot.to())); hints.add(new UnknownAttributes(unknownAttributeNames, tagModel.getName(), context, range, lineHint));
@Override public void visit(Element node) { switch (node.type()) { case OPEN_TAG: OpenTag ot = (OpenTag) node; String name = ot.name().toString(); Tag tagModel = conf.getTag(name); //check just the custom elements if (tagModel != null) { Collection<org.netbeans.modules.html.custom.conf.Attribute> toAdd = new ArrayList<>(); for(org.netbeans.modules.html.custom.conf.Attribute modelAttribute : tagModel.getAttributes()) { if(modelAttribute.isRequired()) { if(ot.getAttribute(modelAttribute.getName()) == null) { //missing required attribute toAdd.add(modelAttribute); } } } if(!toAdd.isEmpty()) { hints.add(new MissingRequiredAttributes(toAdd, ot, context, HtmlEditorUtils.getDocumentOffsetRange(node, snapshot), false)); } } } } }
@Override public void computeSuggestions(HintsProvider.HintsManager manager, RuleContext context, List<Hint> hints, int caretOffset) { HtmlParserResult result = (HtmlParserResult) context.parserResult; Node root = result.root(SyntaxAnalyzerResult.FILTERED_CODE_NAMESPACE); Snapshot snapshot = result.getSnapshot(); int embeddedCaretOffset = snapshot.getEmbeddedOffset(caretOffset); Element found = ElementUtils.findByPhysicalRange(root, embeddedCaretOffset, false); if (found != null) { switch (found.type()) { case OPEN_TAG: case CLOSE_TAG: Named named = (Named) found; String elementName = named.name().toString(); Configuration conf = Configuration.get(snapshot.getSource().getFileObject()); if (conf.getTagsNames().contains(elementName)) { //custom element hints.add(new CustomElementHint(elementName, context, new OffsetRange(snapshot.getOriginalOffset(found.from()), snapshot.getOriginalOffset(found.to())))); } //TODO add check + fix for missing required attributes } } }
/** * Returns some source node with the specified tag name. * * @param root root of the source tree to search. * @param tagName tag name of the desired source node. * @return source node with the specified tag name or {@code null} * if such node doesn't exist. */ private static org.netbeans.modules.html.editor.lib.api.elements.Node findElementByTagName(org.netbeans.modules.html.editor.lib.api.elements.Node root, String tagName) { org.netbeans.modules.html.editor.lib.api.elements.Node result = null; if (root instanceof OpenTag) { OpenTag tag = ((OpenTag)root); String name = tag.name().toString(); if (tagName.equalsIgnoreCase(name)) { result = root; } else { for (org.netbeans.modules.html.editor.lib.api.elements.Element element : root.children(ElementType.OPEN_TAG)) { result = findElementByTagName((org.netbeans.modules.html.editor.lib.api.elements.Node)element, tagName); if (result != null) { break; } } } } return result; }
while (elementsIterator.hasNext()) { Element element = elementsIterator.next(); switch (element.type()) { case OPEN_TAG: OpenTag ot = (OpenTag) element; for (Iterator<Attribute> it = ot.attributes(new AttributeFilter() { @Override public boolean accepts(Attribute attribute) {
private List<OpenTag> findValue(Collection<OpenTag> nodes, String tagName, List<OpenTag> foundNodes) { if (nodes == null) { return foundNodes; } for (OpenTag ot : nodes) { if(LexerUtils.equals(tagName, ot.name(), true, false)) { foundNodes.add(ot); } else { foundNodes = findValue(ot.children(OpenTag.class), tagName, foundNodes); } } return foundNodes; }
@Override public void run() { try { int insertOffset = openTag.from() + "<".length() + openTag.name().length(); int documentInsertOffset = snapshot.getOriginalOffset(insertOffset); document.insertString(documentInsertOffset, insertText.toString(), null); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } }
@Override public Map<OffsetRange, Set<ColoringAttributes>> getHighlights(HtmlParserResult result, SchedulerEvent event) { final Map<OffsetRange, Set<ColoringAttributes>> highlights = new HashMap<>(); AngularModel model = AngularModel.getModel(result); for(Attribute ngAttr : model.getNgAttributes()) { OffsetRange dor = Utils.getValidDocumentOffsetRange(ngAttr.from(), ngAttr.from() + ngAttr.name().length(), result.getSnapshot()); if(dor != null) { highlights.put(dor, ColoringAttributes.CONSTRUCTOR_SET); } } return highlights; }
@Override public String getDescription() { return Bundle.addAttributeToSource(Utils.attributes2String(attrs), openTag.name().toString()); }
@Override public boolean isCustomAttribute(Attribute attribute, HtmlSource source) { return getConfiguration(source).getAttributesNames().contains(attribute.name().toString()); }
org.netbeans.modules.web.webkit.debugging.api.dom.Node domChild = parentChain.get(0); int domIndex = elementIndexInParent(domChild); List<org.netbeans.modules.html.editor.lib.api.elements.Element> children = new ArrayList<org.netbeans.modules.html.editor.lib.api.elements.Element>(sourceParent.children(ElementType.OPEN_TAG));
@Override public boolean isCustomTag(Named element, HtmlSource source) { return getConfiguration(source).getTagsNames().contains(element.name().toString()); }
@Override public void run(ResultIterator resultIterator) throws Exception { ResultIterator htmlResultIterator = WebUtils.getResultIterator(resultIterator, "text/html"); // NOI18N final int offsetToShow; if (htmlResultIterator == null) { offsetToShow = 0; } else { HtmlParsingResult result = (HtmlParsingResult)htmlResultIterator.getParserResult(); Node nodeToShow = Utilities.findNode(result, node); Snapshot snapshot = htmlResultIterator.getSnapshot(); int snapshotOffset = nodeToShow.from(); offsetToShow = snapshot.getOriginalOffset(snapshotOffset); } EventQueue.invokeLater(new Runnable() { @Override public void run() { CSSUtils.openAtOffset(fob, offsetToShow); } }); }
@Override public void computeErrors(HintsProvider.HintsManager manager, final RuleContext context, final List<Hint> hints, List<Error> unhandled) { HtmlParserResult result = (HtmlParserResult) context.parserResult; Node root = result.root(SyntaxAnalyzerResult.FILTERED_CODE_NAMESPACE); final Snapshot snapshot = result.getSnapshot(); final Configuration conf = Configuration.get(snapshot.getSource().getFileObject()); ElementUtils.visitChildren(root, CheckerElementVisitor.getChecker(context, conf, snapshot, hints)); }
@Override public void run(ResultIterator resultIterator) throws Exception { templateData = new LinkedHashSet<>(); Result result = resultIterator.getParserResult(0); if (result.getSnapshot().getMimeType().equals("text/html")) { HtmlParserResult htmlResult = (HtmlParserResult)result; String ns = null; if (htmlResult.getNamespaces().containsKey(DefaultLibraryInfo.FACELETS.getNamespace())) { ns = DefaultLibraryInfo.FACELETS.getNamespace(); } else if (htmlResult.getNamespaces().containsKey(DefaultLibraryInfo.FACELETS.getLegacyNamespace())) { ns = DefaultLibraryInfo.FACELETS.getLegacyNamespace(); } if (ns != null) { String faceletsPrefix = htmlResult.getNamespaces().get(ns); List<OpenTag> foundNodes = findValue(htmlResult.root(ns).children(OpenTag.class), faceletsPrefix + ":insert", new ArrayList<OpenTag>()); // NOI18N for (OpenTag node : foundNodes) { Attribute attr = node.getAttribute(VALUE_NAME); if (attr !=null) { String value = attr.unquotedValue().toString(); if (value != null && !"".equals(value)) { //NOI18N templateData.add(value); } } } } } } });
@Override public boolean accepts(Attribute attribute) { DirectiveConvention convention = DirectiveConvention.getConvention(attribute.unqualifiedName()); if(convention != null) { //count the occurrences Integer i = directiveConventionOccurrenceCount.get(convention); if(i == null) { directiveConventionOccurrenceCount.put(convention, 1); } else { directiveConventionOccurrenceCount.put(convention, i + 1); } return true; } return false; } }).iterator(); it.hasNext();) {