Java 类com.intellij.psi.meta.PsiPresentableMetaData 实例源码

项目:intellij-ce-playground    文件:UsageViewTypeLocation.java   
@Override
public String getElementDescription(@NotNull final PsiElement psiElement, @NotNull final ElementDescriptionLocation location) {
  if (!(location instanceof UsageViewTypeLocation)) return null;

  if (psiElement instanceof PsiMetaOwner) {
    final PsiMetaData metaData = ((PsiMetaOwner)psiElement).getMetaData();
    if (metaData instanceof PsiPresentableMetaData) {
      return ((PsiPresentableMetaData)metaData).getTypeName();
    }
  }

  if (psiElement instanceof PsiFile) {
    return LangBundle.message("terms.file");
  }
  if (psiElement instanceof PsiDirectory) {
    return LangBundle.message("terms.directory");
  }

  final Language lang = psiElement.getLanguage();
  FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
  final String type = provider.getType(psiElement);
  if (StringUtil.isNotEmpty(type)) {
    return type;
  }

  return TypePresentationService.getService().getTypePresentableName(psiElement.getClass());
}
项目:intellij-ce-playground    文件:ComputableIcon.java   
public static ComputableIcon create(final PsiPresentableMetaData data) {
  return new ComputableIcon(new Computable<Icon>() {
    @Override
    public Icon compute() {
      return data.getIcon();
    }
  });
}
项目:intellij-ce-playground    文件:HighlightUsagesDescriptionLocation.java   
@Override
public ElementDescriptionProvider getDefaultProvider() {
  return new ElementDescriptionProvider() {
    @Override
    public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) {
      if (element instanceof PsiPresentableMetaData) {
        return ((PsiPresentableMetaData)element).getTypeName();
      }
      return null;
    }
  };
}
项目:intellij-ce-playground    文件:PsiElement2UsageTargetAdapter.java   
private void update(PsiElement element) {
  if (element != null && element.isValid()) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
    myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
    myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
    if (myIconOpen == null || myIconClosed == null) {
      if (element instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData instanceof PsiPresentableMetaData) {
          final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData)metaData;
          if (myIconOpen == null) myIconOpen = ComputableIcon.create(psiPresentableMetaData);
          if (myIconClosed == null) myIconClosed = ComputableIcon.create(psiPresentableMetaData);
        }
      }
      else if (element instanceof PsiFile) {
        final PsiFile psiFile = (PsiFile)element;
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null) {
          myIconOpen = ComputableIcon.create(virtualFile);
          myIconClosed = ComputableIcon.create(virtualFile);
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:DefinitionReference.java   
@Override
@NotNull
public Object[] getVariants() {
  final RngGrammar scope = getScope();
  if (scope == null) {
    return ResolveResult.EMPTY_ARRAY;
  }

  final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
  if (map == null || map.size() == 0) return ArrayUtil.EMPTY_OBJECT_ARRAY;

  return ContainerUtil.mapNotNull(map.values(), new Function<Set<Define>, Object>() {
    @Override
    public Object fun(Set<Define> defines) {
      final Define define = defines.iterator().next();
      if (defines.size() == 0) {
        return null;
      } else {
        final PsiElement element = define.getPsiElement();
        if (element != null) {
          final PsiPresentableMetaData data = (PsiPresentableMetaData)((PsiMetaOwner)element).getMetaData();
          if (data != null) {
            return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
          } else {
            return define.getName();
          }
        } else {
          return define.getName();
        }
      }
    }
  }).toArray();
}
项目:tools-idea    文件:ComputableIcon.java   
public static ComputableIcon create(final PsiPresentableMetaData data) {
  return new ComputableIcon(new Computable<Icon>() {
    @Override
    public Icon compute() {
      return data.getIcon();
    }
  });
}
项目:tools-idea    文件:HighlightUsagesDescriptionLocation.java   
@Override
public ElementDescriptionProvider getDefaultProvider() {
  return new ElementDescriptionProvider() {
    @Override
    public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) {
      if (element instanceof PsiPresentableMetaData) {
        return ((PsiPresentableMetaData)element).getTypeName();
      }
      return null;
    }
  };
}
项目:tools-idea    文件:UsageViewTypeLocation.java   
@Override
public String getElementDescription(@NotNull final PsiElement psiElement, @NotNull final ElementDescriptionLocation location) {
  if (!(location instanceof UsageViewTypeLocation)) return null;

  if (psiElement instanceof PsiMetaOwner) {
    final PsiMetaData metaData = ((PsiMetaOwner)psiElement).getMetaData();
    if (metaData instanceof PsiPresentableMetaData) {
      return ((PsiPresentableMetaData)metaData).getTypeName();
    }
  }

  if (psiElement instanceof PsiFile) {
    return LangBundle.message("terms.file");
  }
  if (psiElement instanceof PsiDirectory) {
    return LangBundle.message("terms.directory");
  }

  final Language lang = psiElement.getLanguage();
  FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
  final String type = provider.getType(psiElement);
  if (StringUtil.isNotEmpty(type)) {
    return type;
  }

  return TypePresentationService.getService().getTypePresentableName(psiElement.getClass());
}
项目:tools-idea    文件:PsiElement2UsageTargetAdapter.java   
public void update() {
  final PsiElement element = getElement();
  if (element != null && element.isValid()) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    myIconOpen = presentation != null ? ComputableIcon.create(presentation, true) : null;
    myIconClosed = presentation != null ? ComputableIcon.create(presentation, false) : null;
    myPresentableText = presentation != null ? presentation.getPresentableText() : UsageViewUtil.createNodeText(element);
    if (myIconOpen == null || myIconClosed == null) {
      if (element instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData instanceof PsiPresentableMetaData) {
          final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData)metaData;
          if (myIconOpen == null) myIconOpen = ComputableIcon.create(psiPresentableMetaData);
          if (myIconClosed == null) myIconClosed = ComputableIcon.create(psiPresentableMetaData);
        }
      }
      else if (element instanceof PsiFile) {
        final PsiFile psiFile = (PsiFile)element;
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null) {
          myIconOpen = ComputableIcon.create(virtualFile);
          myIconClosed = ComputableIcon.create(virtualFile);
        }
      }
    }
  }
}
项目:tools-idea    文件:DefinitionReference.java   
@NotNull
public Object[] getVariants() {
  final RngGrammar scope = getScope();
  if (scope == null) {
    return ResolveResult.EMPTY_ARRAY;
  }

  final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
  if (map == null || map.size() == 0) return ArrayUtil.EMPTY_OBJECT_ARRAY;

  return ContainerUtil.mapNotNull(map.values(), new Function<Set<Define>, Object>() {
    public Object fun(Set<Define> defines) {
      final Define define = defines.iterator().next();
      if (defines.size() == 0) {
        return null;
      } else {
        final PsiElement element = define.getPsiElement();
        if (element != null) {
          final PsiPresentableMetaData data = (PsiPresentableMetaData)((PsiMetaOwner)element).getMetaData();
          if (data != null) {
            return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
          } else {
            return define.getName();
          }
        } else {
          return define.getName();
        }
      }
    }
  }).toArray();
}
项目:consulo    文件:ComputableIcon.java   
public static ComputableIcon create(final PsiPresentableMetaData data) {
  return new ComputableIcon(new Computable<Icon>() {
    @Override
    public Icon compute() {
      return data.getIcon();
    }
  });
}
项目:consulo    文件:HighlightUsagesDescriptionLocation.java   
@Override
public ElementDescriptionProvider getDefaultProvider() {
  return new ElementDescriptionProvider() {
    @Override
    public String getElementDescription(@Nonnull PsiElement element, @Nonnull ElementDescriptionLocation location) {
      if (element instanceof PsiPresentableMetaData) {
        return ((PsiPresentableMetaData)element).getTypeName();
      }
      return null;
    }
  };
}
项目:consulo    文件:UsageViewTypeLocation.java   
@Override
public String getElementDescription(@Nonnull final PsiElement psiElement, @Nonnull final ElementDescriptionLocation location) {
  if (!(location instanceof UsageViewTypeLocation)) return null;

  if (psiElement instanceof PsiMetaOwner) {
    final PsiMetaData metaData = ((PsiMetaOwner)psiElement).getMetaData();
    if (metaData instanceof PsiPresentableMetaData) {
      return ((PsiPresentableMetaData)metaData).getTypeName();
    }
  }

  if (psiElement instanceof PsiFile) {
    return LangBundle.message("terms.file");
  }
  if (psiElement instanceof PsiDirectory) {
    return LangBundle.message("terms.directory");
  }

  final Language lang = psiElement.getLanguage();
  FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
  final String type = provider.getType(psiElement);
  if (StringUtil.isNotEmpty(type)) {
    return type;
  }

  return TypePresentationService.getInstance().getTypePresentableName(psiElement.getClass());
}
项目:consulo    文件:PsiElement2UsageTargetAdapter.java   
private void update(PsiElement element) {
  if (element != null && element.isValid()) {
    final ItemPresentation presentation = ((NavigationItem)element).getPresentation();
    myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
    myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
    myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
    if (myIconOpen == null || myIconClosed == null) {
      if (element instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData instanceof PsiPresentableMetaData) {
          final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData)metaData;
          if (myIconOpen == null) myIconOpen = ComputableIcon.create(psiPresentableMetaData);
          if (myIconClosed == null) myIconClosed = ComputableIcon.create(psiPresentableMetaData);
        }
      }
      else if (element instanceof PsiFile) {
        final PsiFile psiFile = (PsiFile)element;
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null) {
          myIconOpen = ComputableIcon.create(virtualFile);
          myIconClosed = ComputableIcon.create(virtualFile);
        }
      }
    }
  }
}
项目:consulo-xml    文件:DefinitionReference.java   
@Override
@NotNull
public Object[] getVariants() {
  final RngGrammar scope = getScope();
  if (scope == null) {
    return ResolveResult.EMPTY_ARRAY;
  }

  final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
  if (map == null || map.size() == 0) return ArrayUtil.EMPTY_OBJECT_ARRAY;

  return ContainerUtil.mapNotNull(map.values(), defines -> {
    final Define define = defines.iterator().next();
    if (defines.size() == 0) {
      return null;
    } else {
      final PsiElement element = define.getPsiElement();
      if (element != null) {
        final PsiPresentableMetaData data = (PsiPresentableMetaData)((PsiMetaOwner)element).getMetaData();
        if (data != null) {
          return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
        } else {
          return define.getName();
        }
      } else {
        return define.getName();
      }
    }
  }).toArray();
}
项目:consulo-apache-velocity    文件:VtlResolveTest.java   
public void testVariableAssignedFromGetter() throws Throwable {
    PsiClass clazz = Util.addJavaClassTo(myFixture);
    VtlVariable var = assertInstanceOf(resolveReferenceAtCaret(), VtlVariable.class);
    PsiType varType = var.getPsiType();
    assertInstanceOf(varType, PsiClassType.class);
    PsiClass varClass = com.intellij.psi.util.PsiUtil.resolveClassInType(varType);
    assertEquals(clazz, varClass);
    PsiPresentableMetaData metadata = assertInstanceOf(var, PsiPresentableMetaData.class);
    assertEquals(VelocityBundle.message("type.name.variable"), metadata.getTypeName());
}
项目:consulo-apache-velocity    文件:VtlResolveTest.java   
public void testOverrideMacroParam() throws Throwable {
    Util.addEmptyJavaClassTo(myFixture);
    VtlVariable var = assertInstanceOf(resolveReferenceAtCaret(), VtlVariable.class);
    assertNotNull(var.getPsiType());
    assertEquals(26, var.getNavigationElement().getTextOffset());
    PsiPresentableMetaData metadata = assertInstanceOf(var, PsiPresentableMetaData.class);
    assertEquals(VelocityBundle.message("type.name.variable"), metadata.getTypeName());
}
项目:intellij-ce-playground    文件:XmlAttributeReferenceCompletionProvider.java   
private static void addVariants(final CompletionResultSet result,
                                final XmlAttribute[] attributes,
                                final XmlAttributeDescriptor[] descriptors,
                                XmlAttribute attribute,
                                @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
  final XmlTag tag = attribute.getParent();
  final PsiFile file = tag.getContainingFile();
  final XmlExtension extension = XmlExtension.getExtension(file);
  final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0
                        ? attribute.getNamespacePrefix() + ":"
                        : null;

  CompletionData
    completionData = CompletionUtil.getCompletionDataByElement(attribute, attribute.getContainingFile().getOriginalFile());
  boolean caseSensitive = !(completionData instanceof HtmlCompletionData) || ((HtmlCompletionData)completionData).isCaseSensitive();

  for (XmlAttributeDescriptor descriptor : descriptors) {
    if (isValidVariant(attribute, descriptor, attributes, extension)) {
      String name = descriptor.getName(tag);

      InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

      if (tag instanceof HtmlTag &&
          HtmlUtil.isShortNotationOfBooleanAttributePreferred() &&
          HtmlUtil.isBooleanAttribute(descriptor, tag)) {
        insertHandler = null;
      }

      if (replacementInsertHandler != null) {
        insertHandler = replacementInsertHandler;
      }
      else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
        final String namespace = ((NamespaceAwareXmlAttributeDescriptor)descriptor).getNamespace(tag);

        if (file instanceof XmlFile &&
            namespace != null &&
            namespace.length() > 0 &&
            !name.contains(":") &&
            tag.getPrefixByNamespace(namespace) == null) {
          insertHandler = new XmlAttributeInsertHandler(namespace);
        }
      }
      if (prefix == null || name.startsWith(prefix)) {
        if (prefix != null && name.length() > prefix.length()) {
          name = descriptor.getName(tag).substring(prefix.length());
        }
        LookupElementBuilder element = LookupElementBuilder.create(name);
        if (descriptor instanceof PsiPresentableMetaData) {
          element = element.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
        }
        final int separator = name.indexOf(':');
        if (separator > 0) {
          element = element.withLookupString(name.substring(separator + 1));
        }
        element = element
          .withCaseSensitivity(caseSensitive)
          .withInsertHandler(insertHandler);
        result.addElement(
          descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) :
          HtmlUtil.isOwnHtmlAttribute(descriptor) ? PrioritizedLookupElement.withPriority(element, 50) : element);
      }
    }
  }
}
项目:intellij-ce-playground    文件:DefaultXmlTagNameProvider.java   
@Override
public void addTagNameVariants(List<LookupElement> elements, @NotNull XmlTag tag, String prefix) {
  final List<String> namespaces;
  if (prefix.isEmpty()) {
    namespaces = new ArrayList<String>(Arrays.asList(tag.knownNamespaces()));
    namespaces.add(XmlUtil.EMPTY_URI); // empty namespace
  }
  else {
    namespaces = new ArrayList<String>(Collections.singletonList(tag.getNamespace()));
  }
  PsiFile psiFile = tag.getContainingFile();
  XmlExtension xmlExtension = XmlExtension.getExtension(psiFile);
  List<String> nsInfo = new ArrayList<String>();
  List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(tag, namespaces, nsInfo);

  if (variants.isEmpty() && psiFile instanceof XmlFile && ((XmlFile)psiFile).getRootTag() == tag) {
    getRootTagsVariants(tag, elements);
    return;
  }

  final Set<String> visited = new HashSet<String>();
  for (int i = 0; i < variants.size(); i++) {
    XmlElementDescriptor descriptor = variants.get(i);
    String qname = descriptor.getName(tag);
    if (!visited.add(qname)) continue;
    if (!prefix.isEmpty() && qname.startsWith(prefix + ":")) {
      qname = qname.substring(prefix.length() + 1);
    }

    PsiElement declaration = descriptor.getDeclaration();
    if (declaration != null && !declaration.isValid()) {
      LOG.error(descriptor + " contains invalid declaration: " + declaration);
    }
    LookupElementBuilder lookupElement = declaration == null ? LookupElementBuilder.create(qname) : LookupElementBuilder.create(declaration, qname);
    final int separator = qname.indexOf(':');
    if (separator > 0) {
      lookupElement = lookupElement.withLookupString(qname.substring(separator + 1));
    }
    String ns = nsInfo.get(i);
    if (StringUtil.isNotEmpty(ns)) {
      lookupElement = lookupElement.withTypeText(ns, true);
    }
    if (descriptor instanceof PsiPresentableMetaData) {
      lookupElement = lookupElement.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
    }
    if (xmlExtension.useXmlTagInsertHandler()) {
      lookupElement = lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE);
    }

    elements.add(PrioritizedLookupElement.withPriority(lookupElement, separator > 0 ? 0 : 1));
  }
}
项目:tools-idea    文件:XmlAttributeReferenceCompletionProvider.java   
private static void addVariants(final CompletionResultSet result,
                                final XmlAttribute[] attributes,
                                final XmlAttributeDescriptor[] descriptors,
                                XmlAttribute attribute,
                                @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
  final XmlTag tag = attribute.getParent();
  final PsiFile file = tag.getContainingFile();
  final XmlExtension extension = XmlExtension.getExtension(file);
  final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0
                        ? attribute.getNamespacePrefix() + ":"
                        : null;

  CompletionData
    completionData = CompletionUtil.getCompletionDataByElement(attribute, attribute.getContainingFile().getOriginalFile());
  boolean caseSensitive = !(completionData instanceof HtmlCompletionData) || ((HtmlCompletionData)completionData).isCaseSensitive();

  for (XmlAttributeDescriptor descriptor : descriptors) {
    if (isValidVariant(attribute, descriptor, attributes, extension)) {
      String name = descriptor.getName(tag);

      InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

      if (replacementInsertHandler != null) {
        insertHandler = replacementInsertHandler;
      }
      else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
        final String namespace = ((NamespaceAwareXmlAttributeDescriptor)descriptor).getNamespace(tag);

        if (file instanceof XmlFile &&
            namespace != null &&
            namespace.length() > 0 &&
            !name.contains(":") &&
            tag.getPrefixByNamespace(namespace) == null) {
          insertHandler = new XmlAttributeInsertHandler(namespace);
        }
      }
      if (prefix == null || name.startsWith(prefix)) {
        if (prefix != null && name.length() > prefix.length()) {
          name = descriptor.getName(tag).substring(prefix.length());
        }
        LookupElementBuilder element = LookupElementBuilder.create(name);
        if (descriptor instanceof PsiPresentableMetaData) {
          element = element.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
        }
        final int separator = name.indexOf(':');
        if (separator > 0) {
          element = element.withLookupString(name.substring(separator + 1));
        }
        element = element
          .withCaseSensitivity(caseSensitive)
          .withInsertHandler(insertHandler);
        result.addElement(
          descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : element);
      }
    }
  }
}
项目:consulo-xml    文件:XmlAttributeReferenceCompletionProvider.java   
private static void addVariants(final CompletionResultSet result,
        final XmlAttribute[] attributes,
        final XmlAttributeDescriptor[] descriptors,
        XmlAttribute attribute,
        @Nullable InsertHandler<LookupElement> replacementInsertHandler)
{
    final XmlTag tag = attribute.getParent();
    final PsiFile file = tag.getContainingFile();
    final XmlExtension extension = XmlExtension.getExtension(file);
    final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0 ? attribute.getNamespacePrefix() + ":" : null;

    for(XmlAttributeDescriptor descriptor : descriptors)
    {
        if(isValidVariant(attribute, descriptor, attributes, extension))
        {
            String name = descriptor.getName(tag);

            InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

            if(tag instanceof HtmlTag && HtmlUtil.isShortNotationOfBooleanAttributePreferred() && HtmlUtil.isBooleanAttribute(descriptor, tag))
            {
                insertHandler = null;
            }

            if(replacementInsertHandler != null)
            {
                insertHandler = replacementInsertHandler;
            }
            else if(descriptor instanceof NamespaceAwareXmlAttributeDescriptor)
            {
                final String namespace = ((NamespaceAwareXmlAttributeDescriptor) descriptor).getNamespace(tag);

                if(file instanceof XmlFile && namespace != null && namespace.length() > 0 && !name.contains(":") && tag.getPrefixByNamespace(namespace) == null)
                {
                    insertHandler = new XmlAttributeInsertHandler(namespace);
                }
            }
            if(prefix == null || name.startsWith(prefix))
            {
                if(prefix != null && name.length() > prefix.length())
                {
                    name = descriptor.getName(tag).substring(prefix.length());
                }
                LookupElementBuilder element = LookupElementBuilder.create(name);
                if(descriptor instanceof PsiPresentableMetaData)
                {
                    element = element.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
                }
                final int separator = name.indexOf(':');
                if(separator > 0)
                {
                    element = element.withLookupString(name.substring(separator + 1));
                }
                element = element.withCaseSensitivity(!(descriptor instanceof HtmlAttributeDescriptorImpl)).withInsertHandler(insertHandler);
                result.addElement(descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : HtmlUtil.isOwnHtmlAttribute(descriptor) ?
                        PrioritizedLookupElement.withPriority(element, 50) : element);
            }
        }
    }
}
项目:consulo-xml    文件:DefaultXmlTagNameProvider.java   
@Override
public void addTagNameVariants(List<LookupElement> elements, @NotNull XmlTag tag, String prefix)
{
    final List<String> namespaces;
    if(prefix.isEmpty())
    {
        namespaces = new ArrayList<>(Arrays.asList(tag.knownNamespaces()));
        namespaces.add(XmlUtil.EMPTY_URI); // empty namespace
    }
    else
    {
        namespaces = new ArrayList<>(Collections.singletonList(tag.getNamespace()));
    }
    PsiFile psiFile = tag.getContainingFile();
    XmlExtension xmlExtension = XmlExtension.getExtension(psiFile);
    List<String> nsInfo = new ArrayList<>();
    List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(tag, namespaces, nsInfo);

    if(variants.isEmpty() && psiFile instanceof XmlFile && ((XmlFile) psiFile).getRootTag() == tag)
    {
        getRootTagsVariants(tag, elements);
        return;
    }

    final Set<String> visited = new HashSet<>();
    for(int i = 0; i < variants.size(); i++)
    {
        XmlElementDescriptor descriptor = variants.get(i);
        String qname = descriptor.getName(tag);
        if(!visited.add(qname))
        {
            continue;
        }
        if(!prefix.isEmpty() && qname.startsWith(prefix + ":"))
        {
            qname = qname.substring(prefix.length() + 1);
        }

        PsiElement declaration = descriptor.getDeclaration();
        if(declaration != null && !declaration.isValid())
        {
            LOG.error(descriptor + " contains invalid declaration: " + declaration);
        }
        LookupElementBuilder lookupElement = declaration == null ? LookupElementBuilder.create(qname) : LookupElementBuilder.create(declaration, qname);
        final int separator = qname.indexOf(':');
        if(separator > 0)
        {
            lookupElement = lookupElement.withLookupString(qname.substring(separator + 1));
        }
        String ns = nsInfo.get(i);
        if(StringUtil.isNotEmpty(ns))
        {
            lookupElement = lookupElement.withTypeText(ns, true);
        }
        if(descriptor instanceof PsiPresentableMetaData)
        {
            lookupElement = lookupElement.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
        }
        if(xmlExtension.useXmlTagInsertHandler())
        {
            lookupElement = lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE);
        }
        lookupElement = lookupElement.withCaseSensitivity(!(descriptor instanceof HtmlElementDescriptorImpl));
        elements.add(PrioritizedLookupElement.withPriority(lookupElement, separator > 0 ? 0 : 1));
    }
}