Java 类com.intellij.psi.html.HtmlTag 实例源码

项目:weex-language-support    文件:WeexAnnotator.java   
private void checkStructure(PsiElement document, @NotNull AnnotationHolder annotationHolder) {
    PsiElement[] children = document.getChildren();
    List<String> acceptedTag = Arrays.asList("template","element","script", "style");
    for (PsiElement element : children) {
        if (element instanceof HtmlTag) {
            if (!acceptedTag.contains(((HtmlTag) element).getName().toLowerCase())) {
                annotationHolder.createErrorAnnotation(element, "Invalid tag '"
                        + ((HtmlTag) element).getName() + "', only the [template, element, script, style] tags are allowed here.");
            }
            checkAttributes((XmlTag) element, annotationHolder);
        } else {
            if (!(element instanceof PsiWhiteSpace)
                    && !(element instanceof XmlProlog)
                    && !(element instanceof XmlText)
                    && !(element instanceof XmlComment)) {
                String s = element.getText();
                if (s.length() > 20) {
                    s = s.substring(0, 20);
                }
                annotationHolder.createErrorAnnotation(element, "Invalid content '" + s +
                        "', only the [template, script, style] tags are allowed here.");
            }
        }
    }
}
项目:catberry-idea-plugin    文件:CatberryComponentTagDescriptorsProvider.java   
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
  final Project project = xmlTag.getProject();
  CatberryProjectConfigurationManager manager = CatberryProjectConfigurationManager.getInstance(project);

  if (!(xmlTag instanceof HtmlTag && manager.isCatberryEnabled())) return null;

  final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
  final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
  final boolean special = CatberryConstants.SPECIAL_COMPONENT_NAMES.contains(xmlTag.getName());
  if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor || special)) return null;

  final String name = CatberryComponentUtils.normalizeName(xmlTag.getName());
  final PsiFile file = CatberryComponentUtils.findComponent(project, name);
  return file != null ? new CatberryComponentTagDescriptor(xmlTag.getName(), file) : null;
}
项目:intellij-ce-playground    文件:XmlHighlightVisitor.java   
private void checkTag(XmlTag tag) {
  if (ourDoJaxpTesting) return;

  if (!myHolder.hasErrorResults()) {
    checkTagByDescriptor(tag);
  }

  if (!myHolder.hasErrorResults()) {
    if (!skipValidation(tag)) {
      final XmlElementDescriptor descriptor = tag.getDescriptor();

      if (tag instanceof HtmlTag &&
          ( descriptor instanceof AnyXmlElementDescriptor ||
            descriptor == null
          )
         ) {
        return;
      }

      checkReferences(tag);
    }
  }
}
项目:intellij-ce-playground    文件:PackageDotHtmlMayBePackageInfoInspection.java   
@Nullable
private static String getPackageInfoText(XmlFile xmlFile) {
  final XmlTag rootTag = xmlFile.getRootTag();
  if (rootTag == null) {
    return null;
  }
  final PsiElement[] children = rootTag.getChildren();
  for (PsiElement child : children) {
    if (!(child instanceof HtmlTag)) {
      continue;
    }
    final HtmlTag htmlTag = (HtmlTag)child;
    @NonNls final String name = htmlTag.getName();
    if ("body".equalsIgnoreCase(name)) {
      final XmlTagValue value = htmlTag.getValue();
      return value.getText();
    }
  }
  return null;
}
项目:react-templates-plugin    文件:RTHtmlExtension.java   
public static List<String> loadImportedTags(@NotNull XmlFile file, @NotNull XmlTag context) {
//        PsiElement[] arr = file.getRootTag().getChildren();
//        Collection<HtmlTag> tags = PsiTreeUtil.findChildrenOfType(file, HtmlTag.class);
        PsiElement[] reqTags = PsiTreeUtil.collectElements(file, new PsiElementFilter() {
            @Override
            public boolean isAccepted(PsiElement element) {
                return element instanceof HtmlTag && (((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_REQUIRE) || ((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_IMPORT));
            }
        });

        List<String> importedTags = new ArrayList<String>();
        for (PsiElement elem : reqTags) {
            String as = ((HtmlTag) elem).getAttributeValue("as");
            if (!Strings.isNullOrEmpty(as)) {
                importedTags.add(as);
            }
        }
        return importedTags;
    }
项目:AppCanPlugin    文件:AppendHTMLCommandAction.java   
private void getBodyAndHead() {
    PsiElement[] rootElement=htmlIndexFile.getChildren();
    PsiElement[] rootChildren=rootElement[0].getChildren();
    for (PsiElement psiElement:rootChildren){
        if (psiElement instanceof HtmlTag){
            HtmlTag htmlTag= (HtmlTag) psiElement;
            PsiElement[] htmlChildren=htmlTag.getChildren();
            for (PsiElement htmlChild:htmlChildren){
                //<html>标签里面的内容
                if (htmlChild instanceof HtmlTag){
                    HtmlTag htmlChildTag= (HtmlTag) htmlChild;
                    if (htmlChildTag.getText().equals("body")){
                        bodyHtmlTag=htmlChildTag;
                    }else if (htmlChildTag.getText().equals("head")){
                        headHtmlTag=htmlChildTag;
                    }
                }
            }
        }
    }
}
项目:react-templates-plugin    文件:RTHtmlExtension.java   
public static List<String> loadImportedTags(@NotNull XmlFile file, @NotNull XmlTag context) {
//        PsiElement[] arr = file.getRootTag().getChildren();
//        Collection<HtmlTag> tags = PsiTreeUtil.findChildrenOfType(file, HtmlTag.class);
        PsiElement[] reqTags = PsiTreeUtil.collectElements(file, new PsiElementFilter() {
            @Override
            public boolean isAccepted(PsiElement element) {
                return element instanceof HtmlTag && (((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_REQUIRE) || ((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_IMPORT));
            }
        });

        List<String> importedTags = new ArrayList<String>();
        for (PsiElement elem : reqTags) {
            String as = ((HtmlTag) elem).getAttributeValue("as");
            if (!Strings.isNullOrEmpty(as)) {
                importedTags.add(as);
            }
        }
        return importedTags;
    }
项目:tools-idea    文件:XmlHighlightVisitor.java   
private void checkTag(XmlTag tag) {
  if (ourDoJaxpTesting) return;

  if (!myHolder.hasErrorResults()) {
    checkTagByDescriptor(tag);
  }

  if (!myHolder.hasErrorResults()) {
    if (!skipValidation(tag)) {
      final XmlElementDescriptor descriptor = tag.getDescriptor();

      if (tag instanceof HtmlTag &&
          ( descriptor instanceof AnyXmlElementDescriptor ||
            descriptor == null
          )
         ) {
        return;
      }

      checkReferences(tag);
    }
  }
}
项目:cordovastudio    文件:TagUtil.java   
public static boolean matchesClass(HtmlTag tag, String className) {
    XmlAttribute attr = tag.getAttribute(CLASS_ATTR);

    if (attr != null) {
        String attrVal = attr.getValue();

        if (attrVal != null) {
            String classNames = attrVal.toLowerCase();
            String search = className.toLowerCase();
            int len = className.length();
            int lastIndex = 0;

            while ((lastIndex = classNames.indexOf(search, lastIndex)) != -1) {
                if ((lastIndex == 0 || Character.isWhitespace(classNames.charAt(lastIndex - 1))) &&
                        (lastIndex + len == classNames.length() || Character.isWhitespace(classNames.charAt(lastIndex + len)))) {
                    return true;
                }
                lastIndex += len;
            }
            return false;
        }
    }

    return false;
}
项目:cordovastudio    文件:TagUtil.java   
public static Collection<String> elementClasses(HtmlTag tag) {
    XmlAttribute attr = tag.getAttribute(CLASS_ATTR);

    if (attr != null) {
        String classNames = attr.getValue();

        if (classNames != null) {
            Collection<String> list = new ArrayList<String>();
            for (String cname : classNames.toLowerCase().split(CLASS_DELIM)) {
                cname = cname.trim();
                if (cname.length() > 0)
                    list.add(cname);
            }
            return list;
        }

    }

    return Collections.emptyList();
}
项目:cordovastudio    文件:DOMAnalyzer.java   
/**
 * Finds the explicitly specified base URL in the document according to the HTML specification
 *
 * @return the base URL string, when present in the document or null when not present
 * @see <a href="http://www.w3.org/TR/html4/struct/links.html#edef-BASE">the BASE element definition</a>
 */
public String getDocumentBase() {
    HtmlTag head = getHead();

    if (head != null) {
        HtmlTag base = (HtmlTag) head.findFirstSubTag("base");

        if (base != null) {
            XmlAttribute href = base.getAttribute("href");

            if (href != null) {
                return href.getValue();
            }
        }
    }

    return null;
}
项目:cordovastudio    文件:DOMAnalyzer.java   
/**
 * Finds the explicitly specified character encoding using the <code>&lt;meta&gt;</code> tag according
 * to the HTML specifiaction.
 *
 * @return the encoding name when present in the document or <code>null</code> if not present.
 */
public String getCharacterEncoding() {
    HtmlTag head = getHead();

    if (head != null) {
        for (XmlTag meta : head.findSubTags("meta")) {
            XmlAttribute httpEquiv = meta.getAttribute("http-equiv");
            XmlAttribute charset = meta.getAttribute("charset");

            if (httpEquiv != null) {
                String httpEquivValue = httpEquiv.getValue();
                if (httpEquivValue != null && httpEquivValue.equalsIgnoreCase("content-type")
                        && meta.getAttribute("content") != null) {
                    String ctype = httpEquiv.getValue().toLowerCase();
                    int cpos = ctype.indexOf("charset=");
                    if (cpos != -1)
                        return ctype.substring(cpos + 8);
                }
            } else if (charset != null) {
                return charset.getValue();
            }
        }
    }

    return null;
}
项目:cordovastudio    文件:BlockTableBox.java   
/**
 * Goes through the list of child boxes and organizes them into captions, header,
 * footer, etc.
 */
private void organizeContent()
{
    table = new TableBox((HtmlTag)element, g, ctx);
    table.adoptParent(this);
    table.setStyle(style);

    for (Iterator<Box> it = nested.iterator(); it.hasNext(); )
    {
        Box box = it.next();
        if (box instanceof TableCaptionBox)
        {
            caption = (TableCaptionBox) box;
        }
        else //other elements belong to the table itself
        {
            table.addSubBox(box);
            box.setContainingBlock(table);
            box.setParent(table);
            it.remove();
            endChild--;
        }
    }

    addSubBox(table);
}
项目:cordovastudio    文件:BoxFactory.java   
/**
 * Creates a new box for an element node and sets the containing boxes accordingly.
 *
 * @param tag  The element node
 * @param stat The box tree creation status used for obtaining the containing boxes
 * @return the newly created element box
 */
public ElementBox createElementBox(HtmlTag tag, BoxTreeCreationStatus stat) {
    ElementBox ret = createBox(stat.parent, tag, null);
    ret.setClipBlock(stat.clipbox);
    if (ret.isBlock()) {
        BlockBox block = (BlockBox) ret;
        //Setup my containing box
        if (block.position == BlockBox.POS_ABSOLUTE)
            ret.setContainingBlock(stat.absbox);
        else if (block.position == BlockBox.POS_FIXED)
            ret.setContainingBlock(viewport);
        else
            ret.setContainingBlock(stat.contbox);
    } else
        ret.setContainingBlock(stat.contbox);

    //mark the root visual context
    if (tag.getParentTag() == null)
        ret.getVisualContext().makeRootContext();

    return ret;
}
项目:cordovastudio    文件:BoxFactory.java   
/**
 * Creates a single new box from an element.
 *
 * @param tag     The source DOM element
 * @param display the display: property value that is used when the box style is not known (e.g. anonymous boxes)
 * @return A new box of a subclass of {@link ElementBox} based on the value of the 'display' CSS property
 */
public ElementBox createBox(ElementBox parent, HtmlTag tag, String display) {
    ElementBox root = null;

    //New box style
    NodeData style = decoder.getElementStyleInherited(tag);
    if (style == null)
        style = createAnonymousStyle(display);

    //Special (HTML) tag names
    if (config.getUseHTML() && html.isTagSupported(tag)) {
        root = html.createBox(parent, tag, viewport, style);
    }
    //Not created yet -- create a box according to the display value
    if (root == null) {
        root = createElementInstance(parent, tag, style);
    }
    root.setBase(baseurl);
    root.setViewport(viewport);
    root.setParent(parent);
    root.setOrder(next_order++);
    return root;
}
项目:cordovastudio    文件:TableBox.java   
@Override
protected void loadSizes(boolean update) {
    //load the content width from the attribute (transform to declaration)
    if (!update) {
        //create an important 'width' style for this element
        String width = ((HtmlTag) getElement()).getAttributeValue("width");
        if (width != null && !width.equals("")) {
            TermLengthOrPercent wspec = HTMLNorm.createLengthOrPercent(width);
            if (wspec != null) {
                Declaration dec = CSSFactory.getRuleFactory().createDeclaration();
                dec.setProperty("width");
                dec.unlock();
                dec.add(wspec);
                dec.setImportant(true);
                style.push(dec);
            }
        }
    }
    super.loadSizes(update);
}
项目:emberjs-plugin    文件:EmberJSTagDescriptorsProvider.java   
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
    if (!(xmlTag instanceof HtmlTag && EmberIndexUtil.hasEmberJS(xmlTag.getProject()))) return null;

    final String componentName = ComponentUtil.getAttributeName(xmlTag.getName());
    final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }

    final Project project = xmlTag.getProject();
    final JSNamedElementProxy component = ComponentUtil.getComponentProxy(componentName, project);

    return component != null ? new EmberJSTagDescriptor(componentName, component) : null;
}
项目:cordovastudio    文件:TagUtil.java   
public static boolean matchesClassOld(HtmlTag tag, String className) {
    XmlAttribute attr = tag.getAttribute(CLASS_ATTR);

    if (attr != null) {
        String attrVal = attr.getValue();

        if (attrVal != null) {
            String classNames = attrVal.toLowerCase();
            int len = className.length();
            int start = classNames.indexOf(className.toLowerCase());
            if (start == -1)
                return false;
            else
                return ((start == 0 || Character.isWhitespace(classNames.charAt(start - 1))) &&
                        (start + len == classNames.length() || Character.isWhitespace(classNames.charAt(start + len))));
        }
    }

    return false;
}
项目:cordovastudio    文件:BrowserCanvas.java   
private ElementBox findBodyBoxRec(ElementBox candidate) {
    if(candidate != null && "body".equals(((HtmlTag)candidate.getElement()).getName())) {
        return candidate;
    }

    if(!candidate.getSubBoxList().isEmpty()) {
        for(Box subBox : candidate.getSubBoxList()) {
            /* Skip <head> as it can not contain the <body> tag and skip all boxes that are not ElementBoxes */
            if("head".equals(((HtmlTag)subBox.getElement()).getName()) || !(subBox instanceof ElementBox)) {
                continue;
            }

            ElementBox ret = findBodyBoxRec((ElementBox)subBox);

            if(ret != null) {
                return ret;
            }
        }
    }

    return null;
}
项目:cordovastudio    文件:HTMLBoxFactory.java   
/**
 * Creates the box according to the HTML element.
 *
 * @param parent   The box in the main box tree to be used as a parent box for the new box.
 * @param tag      The element to be processed.
 * @param viewport The viewport to be used for the new box.
 * @param style    The style of the element.
 * @return The newly created box or <code>null</code> when the element is not supported
 * or cannot be created.
 */
public ElementBox createBox(ElementBox parent, HtmlTag tag, Viewport viewport, NodeData style) {
    String name = tag.getName().toLowerCase();
    if (name.equals("object"))
        return createSubtreeObject(parent, tag, viewport, style);
    else if (name.equals("img"))
        return createSubtreeImg(parent, tag, viewport, style);
    else if (name.equals("a") && tag.getAttribute("name") != null
            && (tag.getText() == null || tag.getText().trim().length() == 0)) {
        //make the named anchors sticky
        ElementBox eb = factory.createElementInstance(parent, tag, style);
        eb.setSticky(true);
        return eb;
    } else
        return null;
}
项目:cordovastudio    文件:Viewport.java   
/**
 * Creates a new Viewport with the given initial size. The actual size may be increased during the layout.
 *
 * @param e       The anonymous element representing the viewport.
 * @param g
 * @param ctx
 * @param factory The factory used for creating the child boxes.
 * @param root    The root element of the rendered document.
 * @param width   Preferred (minimal) width.
 * @param height  Preferred (minimal) height.
 */
public Viewport(HtmlTag e, Graphics2D g, VisualContext ctx, BoxFactory factory, HtmlTag root, int width, int height) {
    super(e, g, ctx);
    ctx.setViewport(this);
    this.factory = factory;
    this.root = root;
    style = CSSFactory.createNodeData(); //Viewport starts with an empty style
    nested = new Vector<Box>();
    startChild = 0;
    endChild = 0;
    this.width = width;
    this.height = height;
    isblock = true;
    contblock = true;
    root = null;
    viewInfo = new ViewInfo("viewport", e, 0, 0, width, height);
    viewInfo.setChildren(new ArrayList<>());
    viewInfo.setExtendedInfo(0, 0, 0, 0, 0);
    visibleRect = new Rectangle(0, 0, width, height);
}
项目:cordovastudio    文件:Viewport.java   
private ElementBox recursiveFindElementBoxByName(ElementBox ebox, String name, boolean case_sensitive) {
    if (!(ebox.getElement() instanceof HtmlTag)) {
        return null;
    }

    HtmlTag element = (HtmlTag) ebox.getElement();
    boolean eq;
    if (case_sensitive)
        eq = element.getName().equals(name);
    else
        eq = element.getName().equalsIgnoreCase(name);

    if (eq)
        return ebox;
    else {
        ElementBox ret = null;
        for (int i = 0; i < ebox.getSubBoxNumber() && ret == null; i++) {
            Box child = ebox.getSubBox(i);
            if (child instanceof ElementBox)
                ret = recursiveFindElementBoxByName((ElementBox) child, name, case_sensitive);
        }
        return ret;
    }
}
项目:cordovastudio    文件:CSSFactory.java   
/**
 * Checks allowed media by searching for {@code media} attribute on
 * element and its content
 *
 * @param tag     (STYLE) Element
 * @param media Current media specification used for parsing
 * @return {@code true} if allowed, {@code false} otherwise
 */
private static boolean isAllowedMedia(HtmlTag tag, MediaSpec media) {
    String attr = tag.getAttributeValue("media");
    if (attr != null && attr.length() > 0) {
        attr = attr.trim();
        if (attr.length() > 0) {
            List<MediaQuery> ql = CSSParserFactory.parseMediaQuery(attr);
            if (ql != null) {
                for (MediaQuery q : ql) {
                    if (media.matches(q))
                        return true; //found a matching media query
                }
                return false; //no matching media query
            } else
                return false; //no usable media queries (malformed string?)
        } else
            return media.matchesEmpty(); //empty query string
    } else
        return media.matchesEmpty(); //no media queries
}
项目:catberry-idea-plugin    文件:CatberryComponentReferenceContributor.java   
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
  registrar.registerReferenceProvider(PlatformPatterns.psiElement(HtmlTag.class),
      new PsiReferenceProvider() {
        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
          HtmlTag htmlTag = (HtmlTag) element;
          String name = CatberryComponentUtils.normalizeName(htmlTag.getName());
          return new PsiReference[]{new CatberryComponentReference(htmlTag, name)};
        }
      });
}
项目:catberry-idea-plugin    文件:CatberryComponentTagDescriptorsProvider.java   
@Override
public void addTagNameVariants(final List<LookupElement> elements, @NotNull XmlTag xmlTag, String prefix) {
  CatberryProjectConfigurationManager manager = CatberryProjectConfigurationManager.getInstance(xmlTag.getProject());

  if (!(xmlTag instanceof HtmlTag && manager.isCatberryEnabled())) return;

  final Project project = xmlTag.getProject();
  Map<String, PsiFile> map = CatberryComponentUtils.findComponents(project);
  for(Map.Entry<String, PsiFile> entry : map.entrySet()) {
    String key = entry.getKey();
    if(!CatberryConstants.SPECIAL_COMPONENT_NAMES.contains(entry.getKey()))
      key = CatberryConstants.CATBERRY_COMPONENT_TAG_PREFIX + key;
    elements.add(LookupElementBuilder.create(entry.getValue(), key).withInsertHandler(XmlTagInsertHandler.INSTANCE));
  }
}
项目:intellij-ce-playground    文件:HtmlUnknownAttributeInspectionBase.java   
@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
  final XmlTag tag = attribute.getParent();

  if (tag instanceof HtmlTag) {
    XmlElementDescriptor elementDescriptor = tag.getDescriptor();
    if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
      return;
    }

    XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);

    if (attributeDescriptor == null && !attribute.isNamespaceDeclaration()) {
      final String name = attribute.getName();
      if (!XmlUtil.attributeFromTemplateFramework(name, tag) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
        boolean maySwitchToHtml5 = HtmlUtil.isCustomHtml5Attribute(name) && !HtmlUtil.hasNonHtml5Doctype(tag);
        LocalQuickFix[] quickfixes = new LocalQuickFix[maySwitchToHtml5 ? 3 : 2];
        quickfixes[0] = new AddCustomHtmlElementIntentionAction(ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.attribute", name));
        quickfixes[1] = new RemoveAttributeIntentionAction(name);
        if (maySwitchToHtml5) {
          quickfixes[2] = new SwitchToHtml5WithHighPriorityAction();
        }

        registerProblemOnAttributeName(attribute, XmlErrorMessages.message("attribute.is.not.allowed.here", attribute.getName()), holder,
                                       quickfixes);
      }
    }
  }
}
项目:intellij-ce-playground    文件:HtmlExtraClosingTagInspection.java   
@Override
protected void checkTag(@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
  final XmlToken endTagName = XmlTagUtil.getEndTagNameElement(tag);

  if (endTagName != null && tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag.getName())) {
    holder.registerProblem(endTagName, XmlErrorMessages.message("extra.closing.tag.for.empty.element"),
                           ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RemoveExtraClosingTagIntentionAction());
  }
}
项目:intellij-ce-playground    文件:XmlHighlightVisitor.java   
private static boolean hasAttribute(XmlTag tag, String attrName) {
  final XmlAttribute attribute = tag.getAttribute(attrName);
  if (attribute == null) return false;
  if (attribute.getValueElement() != null) return true;
  if (!(tag instanceof HtmlTag)) return false;
  final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
  return descriptor != null && HtmlUtil.isBooleanAttribute(descriptor, tag);
}
项目:intellij-ce-playground    文件:XmlHighlightVisitor.java   
private void reportOneTagProblem(final XmlTag tag,
                                 final String name,
                                 @NotNull String localizedMessage,
                                 final IntentionAction basicIntention,
                                 final HighlightDisplayKey key,
                                 final XmlEntitiesInspection inspection,
                                 final IntentionAction addAttributeFix) {
  boolean htmlTag = false;

  if (tag instanceof HtmlTag) {
    htmlTag = true;
    if(isAdditionallyDeclared(inspection.getAdditionalEntries(), name)) return;
  }

  final InspectionProfile profile = InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
  if (htmlTag && profile.isToolEnabled(key, tag)) {
    addElementsForTagWithManyQuickFixes(
      tag,
      localizedMessage,
      isInjectedHtmlTagWithoutValidation((HtmlTag)tag) ?
        HighlightInfoType.INFORMATION :
        SeverityRegistrar.getSeverityRegistrar(tag.getProject()).getHighlightInfoTypeBySeverity(profile.getErrorLevel(key, tag).getSeverity()),
      addAttributeFix,
      basicIntention);
  } else if (!htmlTag) {
    addElementsForTag(
      tag,
      localizedMessage,
      HighlightInfoType.ERROR,
      basicIntention
    );
  }
}
项目:intellij-ce-playground    文件:XmlHighlightVisitor.java   
private static HighlightInfoType getTagProblemInfoType(XmlTag tag) {
  if (tag instanceof HtmlTag && XmlUtil.HTML_URI.equals(tag.getNamespace())) {
    if (isInjectedHtmlTagWithoutValidation((HtmlTag)tag)) return HighlightInfoType.INFORMATION;
    return HighlightInfoType.WARNING;
  }
  return HighlightInfoType.WRONG_REF;
}
项目:intellij-ce-playground    文件:XmlHighlightVisitor.java   
public static String getUnquotedValue(XmlAttributeValue value, XmlTag tag) {
  String unquotedValue = value.getValue();

  if (tag instanceof HtmlTag) {
    unquotedValue = unquotedValue.toLowerCase();
  }

  return unquotedValue;
}
项目:intellij-ce-playground    文件:CheckEmptyTagInspection.java   
static boolean isTagWithEmptyEndNotAllowed(final XmlTag tag) {
  String tagName = tag.getName();
  if (tag instanceof HtmlTag) tagName = tagName.toLowerCase();

  Language language = tag.getLanguage();
  return ourTagsWithEmptyEndsNotAllowed.contains(tagName) && language != XMLLanguage.INSTANCE ||
         language == HTMLLanguage.INSTANCE && !HtmlUtil.isSingleHtmlTagL(tagName) && tagName.indexOf(':') == -1;
}
项目:intellij-ce-playground    文件:XmlInvalidIdInspection.java   
@Override
protected void checkValue(XmlAttributeValue value, XmlFile file, XmlRefCountHolder refHolder, XmlTag tag, ProblemsHolder holder) {

  String idRef = XmlHighlightVisitor.getUnquotedValue(value, tag);

  if (tag instanceof HtmlTag) {
    idRef = idRef.toLowerCase();
  }

  if (XmlUtil.isSimpleValue(idRef, value) && refHolder.isIdReferenceValue(value)) {
    boolean hasIdDeclaration = refHolder.hasIdDeclaration(idRef);
    if (!hasIdDeclaration && tag instanceof HtmlTag) {
      hasIdDeclaration = refHolder.hasIdDeclaration(value.getValue());
    }

    if (!hasIdDeclaration) {
      for(XmlIdContributor contributor: Extensions.getExtensions(XmlIdContributor.EP_NAME)) {
        if (contributor.suppressExistingIdValidation(file)) {
          return;
        }
      }

      final FileViewProvider viewProvider = tag.getContainingFile().getViewProvider();
      if (viewProvider instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
        holder.registerProblem(value, XmlErrorMessages.message("invalid.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL,
                               new XmlDeclareIdInCommentAction(idRef));

      }
      else {
        holder.registerProblem(value, XmlErrorMessages.message("invalid.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
      }
    }
  }
}
项目:intellij-ce-playground    文件:HtmlUtil.java   
public static void addHtmlSpecificCompletions(final XmlElementDescriptor descriptor,
                                              final XmlTag element,
                                              final List<XmlElementDescriptor> variants) {
  // add html block completions for tags with optional ends!
  String name = descriptor.getName(element);

  if (name != null && isOptionalEndForHtmlTag(name)) {
    PsiElement parent = element.getParent();

    if (parent != null) {
      // we need grand parent since completion already uses parent's descriptor
      parent = parent.getParent();
    }

    if (parent instanceof HtmlTag) {
      final XmlElementDescriptor parentDescriptor = ((HtmlTag)parent).getDescriptor();

      if (parentDescriptor != descriptor && parentDescriptor != null) {
        for (final XmlElementDescriptor elementsDescriptor : parentDescriptor.getElementsDescriptors((XmlTag)parent)) {
          if (isHtmlBlockTag(elementsDescriptor.getName())) {
            variants.add(elementsDescriptor);
          }
        }
      }
    } else if (parent instanceof HtmlDocumentImpl) {
      final XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
      for (XmlElementDescriptor elementDescriptor : nsDescriptor.getRootElementsDescriptors((XmlDocument)parent)) {
        if (isHtmlBlockTag(elementDescriptor.getName()) && !variants.contains(elementDescriptor)) {
          variants.add(elementDescriptor);
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:HtmlUtil.java   
public static boolean isHtmlTagContainingFile(PsiElement element) {
  if (element == null) {
    return false;
  }
  final PsiFile containingFile = element.getContainingFile();
  if (containingFile != null) {
    final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    if (tag instanceof HtmlTag) {
      return true;
    }
    final XmlDocument document = PsiTreeUtil.getParentOfType(element, XmlDocument.class, false);
    if (document instanceof HtmlDocumentImpl) {
      return true;
    }
    final FileViewProvider provider = containingFile.getViewProvider();
    Language language;
    if (provider instanceof TemplateLanguageFileViewProvider) {
      language = ((TemplateLanguageFileViewProvider)provider).getTemplateDataLanguage();
    }
    else {
      language = provider.getBaseLanguage();
    }

    return language == XHTMLLanguage.INSTANCE;
  }
  return false;
}
项目:intellij-ce-playground    文件:XmlSplitTagAction.java   
private static boolean isInsideUnsplittableElement(final PsiElement grandParent) {
  if (!(grandParent instanceof HtmlTag) && grandParent.getContainingFile().getLanguage() != XHTMLLanguage.INSTANCE) {
    return false;
  }

  final String name = ((XmlTag)grandParent).getName();
  return "html".equals(name) || "body".equals(name) || "title".equals(name);
}
项目:intellij-ce-playground    文件:XmlDocumentationProvider.java   
static String generateHtmlAdditionalDocTemplate(@NotNull PsiElement element) {
  StringBuilder buf = new StringBuilder();
  final PsiFile containingFile = element.getContainingFile();
  if (containingFile != null) {
    final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    boolean append;
    if (tag instanceof HtmlTag) {
      append = true;
    }
    else {
      final FileViewProvider provider = containingFile.getViewProvider();
      Language language;
      if (provider instanceof TemplateLanguageFileViewProvider) {
        language = ((TemplateLanguageFileViewProvider)provider).getTemplateDataLanguage();
      }
      else {
        language = provider.getBaseLanguage();
      }

      append = language == XHTMLLanguage.INSTANCE;
    }

    if (tag != null) {
      EntityDescriptor descriptor = HtmlDescriptorsTable.getTagDescriptor(tag.getName());
      if (descriptor != null && append) {
        buf.append("<br>");
        buf.append(XmlBundle.message("html.quickdoc.additional.template",
                                     descriptor.getHelpRef(),
                                     BASE_SITEPOINT_URL + tag.getName()));
      }
    }
  }

  return buf.toString();
}
项目:react-templates-plugin    文件:RTTagDescriptorsProvider.java   
@Nullable
    @Override
    public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
//        System.out.println("getDescriptor " + xmlTag);
        if (!(xmlTag instanceof HtmlTag && RTProjectComponent.isEnabled(xmlTag.getProject()))) {
            return null;
        }
        final String directiveName = DirectiveUtil.normalizeAttributeName(xmlTag.getName());
        if (directiveName.equals(RT_REQUIRE)) {
            return new RTRequireTagDescriptor(RT_REQUIRE, xmlTag);
        }
        if (directiveName.equals(RT_IMPORT)) {
            return new RTImportTagDescriptor(RT_IMPORT, xmlTag);
        }

        if (xmlTag.getContainingFile() instanceof XmlFile) {
            List<String> tags = RTHtmlExtension.loadImportedTags((XmlFile) xmlTag.getContainingFile(), xmlTag);
            for (String tag : tags) {
                if (Strings.areEqual(tag, directiveName)) {
                    return new RTClassTagDescriptor(directiveName, xmlTag);
                }
            }
        }
        // TODO: support required tags
        //return new AnyXmlElementDescriptor()
        return null;
    }
项目:react-templates-plugin    文件:RTAttributeDescriptorsProvider.java   
@Override
    public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag xmlTag) {
        if (xmlTag instanceof HtmlTag /*&& RTFileUtil.hasRTExt(xmlTag.getContainingFile())*/) {
            final Project project = xmlTag.getProject();
            if (RTActionUtil.isRTEnabled(project)) {
                final Map<String, XmlAttributeDescriptor> result = new LinkedHashMap<String, XmlAttributeDescriptor>();
                for (String attr : RTAttributes.ALL_ATTRIBUTES) {
                    result.put(attr, new RTXmlAttributeDescriptor(attr));
                }
//                result.put("rt-repeat", new RTXmlAttributeDescriptor("rt-repeat")); // x in [javascript]
//                result.put("rt-if", new RTXmlAttributeDescriptor("rt-if")); //[javascript]
//                result.put("rt-scope", new RTXmlAttributeDescriptor("rt-scope")); //a as b;c as d
//                result.put("rt-class", new RTXmlAttributeDescriptor("rt-class")); // [javascript]
//                result.put("rt-props", new RTXmlAttributeDescriptor("rt-props")); // [javascript]
                return result.values().toArray(new XmlAttributeDescriptor[result.size()]);

    //            return new XmlAttributeDescriptor[]{
    //                    new AnyXmlAttributeDescriptor("rt-if"),
    //                    new AnyXmlAttributeDescriptor("rt-repeat"),
    //                    new AnyXmlAttributeDescriptor("rt-scope"),
    //                    new AnyXmlAttributeDescriptor("rt-props"),
    //                    new AnyXmlAttributeDescriptor("rt-class"),
    //                    new AnyXmlAttributeDescriptor("rt-require")
    //            };
            }
        }
        return XmlAttributeDescriptor.EMPTY;
    }
项目:intellij-demandware    文件:ISMLTagDescriptorsProvider.java   
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag tag) {
    if (!(tag instanceof HtmlTag)) {
        return null;
    }

    final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(tag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(tag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }

    return new ISMLTagDescriptor(tag.getName(), tag);
}