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

项目:mule-intellij-plugins    文件:MuleSchemaProvider.java   
@Nullable
private static String getNamespace(final XmlFile xmlFile, final Project project) {
    //Stupid HTTP module XSD weirdo
    if (xmlFile.getName().contains("mule-httpn.xsd"))
        return "http://www.mulesoft.org/schema/mule/http";
    /////

    final XmlDocument document = xmlFile.getDocument();
    if (document != null) {
        final PsiMetaData metaData = document.getMetaData();
        if (metaData instanceof XmlNSDescriptorImpl) {
            return ((XmlNSDescriptorImpl) metaData).getDefaultNamespace();
        }
    }
    return null;
}
项目:intellij-ce-playground    文件:DefaultLookupItemRenderer.java   
private static String getName(final LookupItem item){
  final String presentableText = item.getPresentableText();
  if (presentableText != null) return presentableText;
  final Object o = item.getObject();
  String name = null;
  if (o instanceof PsiElement) {
    final PsiElement element = (PsiElement)o;
    if (element.isValid()) {
      name = PsiUtilCore.getName(element);
    }
  }
  else if (o instanceof PsiMetaData) {
    name = ((PsiMetaData)o).getName();
  }
  else if (o instanceof PresentableLookupValue ) {
    name = ((PresentableLookupValue)o).getPresentation();
  }
  else {
    name = String.valueOf(o);
  }
  if (name == null){
    name = "";
  }

  return name;
}
项目:intellij-ce-playground    文件:RenameUtil.java   
private static String getStringToReplace(PsiElement element, String newName, boolean nonJava, final RenamePsiElementProcessor theProcessor) {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
    final PsiMetaData metaData = psiMetaOwner.getMetaData();
    if (metaData != null) {
      return metaData.getName();
    }
  }

  if (theProcessor != null) {
    String result = theProcessor.getQualifiedNameAfterRename(element, newName, nonJava);
    if (result != null) {
      return result;
    }
  }

  if (element instanceof PsiNamedElement) {
    return newName;
  }
  else {
    LOG.error("Unknown element type : " + element);
    return null;
  }
}
项目:intellij-ce-playground    文件:XmlFindUsagesProvider.java   
@Override
@NotNull
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
  if (element instanceof XmlTag) {
    final XmlTag xmlTag = (XmlTag)element;
    final PsiMetaData metaData = xmlTag.getMetaData();
    final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName();

    String presentableName = metaData == null ? "<" + name + ">" : name;
    return presentableName+" of file "+xmlTag.getContainingFile().getName();
  }
  if (element instanceof XmlAttributeValue) {
    return ((XmlAttributeValue)element).getValue();
  }
  if (element instanceof PsiNamedElement) {
    return ((PsiNamedElement)element).getName();
  }
  return element.getText();
}
项目:intellij-ce-playground    文件:TagNameReference.java   
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  PsiMetaData metaData = null;

  if (element instanceof PsiMetaOwner){
    final PsiMetaOwner owner = (PsiMetaOwner)element;
    metaData = owner.getMetaData();

    if (metaData instanceof XmlElementDescriptor){
      return getTagElement().setName(metaData.getName(getElement())); // TODO: need to evaluate new ns prefix
    }
  } else if (element instanceof PsiFile) {
    final XmlTag tagElement = getTagElement();
    if (tagElement == null || !myStartTagFlag) return tagElement;
    String newElementName = ((PsiFile)element).getName();
    final int index = newElementName.lastIndexOf('.');

    // TODO: need to evaluate new ns prefix
    newElementName = prependNamespacePrefix(newElementName.substring(0, index), tagElement.getNamespacePrefix());

    return getTagElement().setName(newElementName);
  }

  final XmlTag tag = getTagElement();
  throw new IncorrectOperationException("Cant bind to not a xml element definition!"+element+","+metaData + "," + tag + "," + (tag != null ? tag.getDescriptor() : "unknown descriptor"));
}
项目:tools-idea    文件:DefaultLookupItemRenderer.java   
private static String getName(final LookupItem item){
  final String presentableText = item.getPresentableText();
  if (presentableText != null) return presentableText;
  final Object o = item.getObject();
  String name = null;
  if (o instanceof PsiElement) {
    final PsiElement element = (PsiElement)o;
    if (element.isValid()) {
      name = PsiUtilCore.getName(element);
    }
  }
  else if (o instanceof PsiMetaData) {
    name = ((PsiMetaData)o).getName();
  }
  else if (o instanceof PresentableLookupValue ) {
    name = ((PresentableLookupValue)o).getPresentation();
  }
  else {
    name = String.valueOf(o);
  }
  if (name == null){
    name = "";
  }

  return name;
}
项目:tools-idea    文件:RenameUtil.java   
private static String getStringToReplace(PsiElement element, String newName, boolean nonJava, final RenamePsiElementProcessor theProcessor) {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
    final PsiMetaData metaData = psiMetaOwner.getMetaData();
    if (metaData != null) {
      return metaData.getName();
    }
  }

  if (theProcessor != null) {
    String result = theProcessor.getQualifiedNameAfterRename(element, newName, nonJava);
    if (result != null) {
      return result;
    }
  }

  if (element instanceof PsiNamedElement) {
    return newName;
  }
  else {
    LOG.error("Unknown element type");
    return null;
  }
}
项目:tools-idea    文件:DtdResolveUtil.java   
@Nullable
static XmlNSDescriptor getNsDescriptor(XmlElement element) {
  final XmlElement parentThatProvidesMetaData = PsiTreeUtil
    .getParentOfType(CompletionUtilCoreImpl.getOriginalElement(element), XmlDocument.class, XmlMarkupDecl.class);

  if (parentThatProvidesMetaData instanceof XmlDocument) {
    final XmlDocument document = (XmlDocument)parentThatProvidesMetaData;
    XmlNSDescriptor rootTagNSDescriptor = document.getRootTagNSDescriptor();
    if (rootTagNSDescriptor == null) rootTagNSDescriptor = (XmlNSDescriptor)document.getMetaData();
    return rootTagNSDescriptor;
  } else if (parentThatProvidesMetaData instanceof XmlMarkupDecl) {
    final XmlMarkupDecl markupDecl = (XmlMarkupDecl)parentThatProvidesMetaData;
    final PsiMetaData psiMetaData = markupDecl.getMetaData();

    if (psiMetaData instanceof XmlNSDescriptor) {
      return (XmlNSDescriptor)psiMetaData;
    }
  }

  return null;
}
项目:tools-idea    文件:TagNameReference.java   
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  PsiMetaData metaData = null;

  if (element instanceof PsiMetaOwner){
    final PsiMetaOwner owner = (PsiMetaOwner)element;
    metaData = owner.getMetaData();

    if (metaData instanceof XmlElementDescriptor){
      return getTagElement().setName(metaData.getName(getElement())); // TODO: need to evaluate new ns prefix
    }
  } else if (element instanceof PsiFile) {
    final XmlTag tagElement = getTagElement();
    if (tagElement == null || !myStartTagFlag) return tagElement;
    String newElementName = ((PsiFile)element).getName();
    final int index = newElementName.lastIndexOf('.');

    // TODO: need to evaluate new ns prefix
    newElementName = prependNamespacePrefix(newElementName.substring(0, index), tagElement.getNamespacePrefix());

    return getTagElement().setName(newElementName);
  }

  final XmlTag tag = getTagElement();
  throw new IncorrectOperationException("Cant bind to not a xml element definition!"+element+","+metaData + "," + tag + "," + (tag != null ? tag.getDescriptor() : "unknown descriptor"));
}
项目:tools-idea    文件:XmlFindUsagesProvider.java   
@NotNull
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
  if (element instanceof XmlTag) {
    final XmlTag xmlTag = (XmlTag)element;
    final PsiMetaData metaData = xmlTag.getMetaData();
    final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName();
    return UsageViewBundle.message("usage.target.xml.tag.of.file", metaData == null ? "<" + name + ">" : name, xmlTag.getContainingFile().getName());
  }
  else if (element instanceof XmlAttributeValue) {
    return ((XmlAttributeValue)element).getValue();
  }
  if (element instanceof PsiNamedElement) {
    return ((PsiNamedElement)element).getName();
  } else {
    return element.getText();
  }
}
项目:consulo    文件:DefaultLookupItemRenderer.java   
private static String getName(final LookupItem item){
  final String presentableText = item.getPresentableText();
  if (presentableText != null) return presentableText;
  final Object o = item.getObject();
  String name = null;
  if (o instanceof PsiElement) {
    final PsiElement element = (PsiElement)o;
    if (element.isValid()) {
      name = PsiUtilCore.getName(element);
    }
  }
  else if (o instanceof PsiMetaData) {
    name = ((PsiMetaData)o).getName();
  }
  else if (o instanceof PresentableLookupValue ) {
    name = ((PresentableLookupValue)o).getPresentation();
  }
  else {
    name = String.valueOf(o);
  }
  if (name == null){
    name = "";
  }

  return name;
}
项目:consulo    文件:RenameUtil.java   
private static String getStringToReplace(PsiElement element, String newName, boolean nonJava, final RenamePsiElementProcessor theProcessor) {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
    final PsiMetaData metaData = psiMetaOwner.getMetaData();
    if (metaData != null) {
      return metaData.getName();
    }
  }

  if (theProcessor != null) {
    String result = theProcessor.getQualifiedNameAfterRename(element, newName, nonJava);
    if (result != null) {
      return result;
    }
  }

  if (element instanceof PsiNamedElement) {
    return newName;
  }
  else {
    LOG.error("Unknown element type");
    return null;
  }
}
项目:consulo-xml    文件:XmlFindUsagesProvider.java   
@Override
@NotNull
public String getNodeText(@NotNull PsiElement element, boolean useFullName)
{
    if(element instanceof XmlTag)
    {
        final XmlTag xmlTag = (XmlTag) element;
        final PsiMetaData metaData = xmlTag.getMetaData();
        final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName();

        String presentableName = metaData == null ? "<" + name + ">" : name;
        return presentableName + " of file " + xmlTag.getContainingFile().getName();
    }
    if(element instanceof XmlAttributeValue)
    {
        return ((XmlAttributeValue) element).getValue();
    }
    if(element instanceof PsiNamedElement)
    {
        return ((PsiNamedElement) element).getName();
    }
    return element.getText();
}
项目:mule-intellij-plugins    文件:MuleSchemaProvider.java   
@Override
@NotNull
public Set<String> getAvailableNamespaces(@NotNull XmlFile file, @Nullable String tagName) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    Map<String, XmlFile> schemas = getSchemas(module);
    Set<String> namespaces = new HashSet<>();

    try {
        for (XmlFile xsd : schemas.values()) {
            final XmlDocument document = xsd.getDocument();
            if (document != null) {
                final PsiMetaData metaData = document.getMetaData();
                if (metaData instanceof XmlNSDescriptorImpl) {
                    XmlNSDescriptorImpl descriptor = (XmlNSDescriptorImpl) metaData;
                    String defaultNamespace = descriptor.getDefaultNamespace();

                    //Stupid HTTP module XSD weirdo
                    if (xsd.getName().contains("mule-httpn"))
                        defaultNamespace = "http://www.mulesoft.org/schema/mule/http";
                    /////

                    if (StringUtils.isNotEmpty(defaultNamespace)) {
                        if (StringUtils.isNotEmpty(tagName)) {
                            XmlElementDescriptor elementDescriptor = descriptor.getElementDescriptor(tagName, defaultNamespace);
                            if (elementDescriptor != null) {
                                namespaces.add(defaultNamespace);
                            }
                        } else {
                            namespaces.add(defaultNamespace);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return namespaces;
}
项目:mule-intellij-plugins    文件:MuleSchemaProvider.java   
private static boolean isXSD(final XmlFile xmlFile) {
    final XmlDocument document = xmlFile.getDocument();
    if (document != null) {
        final PsiMetaData metaData = document.getMetaData();
        if (metaData instanceof XmlNSDescriptorImpl) {
            return true;
        }
    }
    return false;
}
项目:intellij-ce-playground    文件:PsiUtil.java   
public static boolean checkName(@NotNull PsiElement element, @NotNull String name, final PsiElement context) {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaData data = ((PsiMetaOwner) element).getMetaData();
    if (data != null) return name.equals(data.getName(context));
  }
  return element instanceof PsiNamedElement && name.equals(((PsiNamedElement)element).getName());
}
项目:intellij-ce-playground    文件:PsiElementPattern.java   
public Self withMetaData(final ElementPattern<? extends PsiMetaData> metaDataPattern) {
  return with(new PatternCondition<T>("withMetaData") {
    @Override
    public boolean accepts(@NotNull final T t, final ProcessingContext context) {
      return t instanceof PsiMetaOwner && metaDataPattern.accepts(((PsiMetaOwner)t).getMetaData(), context);
    }
  });
}
项目:intellij-ce-playground    文件:PsiUtilCore.java   
/**
 * @return name for element using element structure info
 */
@Nullable
public static String getName(PsiElement element) {
  String name = null;
  if (element instanceof PsiMetaOwner) {
    final PsiMetaData data = ((PsiMetaOwner) element).getMetaData();
    if (data != null) {
      name = data.getName(element);
    }
  }
  if (name == null && element instanceof PsiNamedElement) {
    name = ((PsiNamedElement) element).getName();
  }
  return name;
}
项目: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    文件:MetaRegistry.java   
public static void bindDataToElement(final PsiElement element, final PsiMetaData data) {
  CachedValue<PsiMetaData> value =
    CachedValuesManager.getManager(element.getProject()).createCachedValue(new CachedValueProvider<PsiMetaData>() {
      @Override
      public Result<PsiMetaData> compute() {
        data.init(element);
        return new Result<PsiMetaData>(data, data.getDependences());
      }
    });
  element.putUserData(META_DATA_KEY, value);
}
项目:intellij-ce-playground    文件:MetaRegistry.java   
/**
 * @see com.intellij.psi.meta.MetaDataContributor
 * @deprecated
 */
public static <T extends PsiMetaData> void addMetadataBinding(ElementFilter filter,
                                                              Class<T> aMetadataClass,
                                                              Disposable parentDisposable) {
  final MyBinding binding = new MyBinding(filter, aMetadataClass);
  addBinding(binding);
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      ourBindings.remove(binding);
    }
  });
}
项目:intellij-ce-playground    文件:CompletionData.java   
public static LookupElement objectToLookupItem(final @NotNull Object object) {
  if (object instanceof LookupElement) return (LookupElement)object;

  String s = null;
  TailType tailType = TailType.NONE;
  if (object instanceof PsiElement){
    s = PsiUtilCore.getName((PsiElement)object);
  }
  else if (object instanceof PsiMetaData) {
    s = ((PsiMetaData)object).getName();
  }
  else if (object instanceof String) {
    s = (String)object;
  }
  else if (object instanceof Template) {
    s = ((Template) object).getKey();
  }
  else if (object instanceof PresentableLookupValue) {
    s = ((PresentableLookupValue)object).getPresentation();
  }
  if (s == null) {
    throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
  }

  LookupItem item = new LookupItem(object, s);

  if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
    item.setBold();
  }
  item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
  return item;
}
项目:intellij-ce-playground    文件:UsageViewShortNameLocation.java   
@Override
public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
  if (!(location instanceof UsageViewShortNameLocation)) return null;

  if (element instanceof PsiMetaOwner) {
    PsiMetaData metaData = ((PsiMetaOwner)element).getMetaData();
    if (metaData!=null) return DescriptiveNameUtil.getMetaDataName(metaData);
  }

  if (element instanceof PsiNamedElement) {
    return ((PsiNamedElement)element).getName();
  }
  return "";
}
项目: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    文件:DefaultNonCodeSearchElementDescriptionProvider.java   
@Override
public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
  if (!(location instanceof NonCodeSearchDescriptionLocation)) return null;
  final NonCodeSearchDescriptionLocation ncdLocation = (NonCodeSearchDescriptionLocation)location;

  if (element instanceof PsiDirectory) {
    if (ncdLocation.isNonJava()) {
      final String qName = PsiDirectoryFactory.getInstance(element.getProject()).getQualifiedName((PsiDirectory)element, false);
      if (qName.length() > 0) return qName;
      return null;
    }
    return ((PsiDirectory) element).getName();
  }

  if (element instanceof PsiMetaOwner) {
    final PsiMetaOwner psiMetaOwner = (PsiMetaOwner)element;
    final PsiMetaData metaData = psiMetaOwner.getMetaData();
    if (metaData != null) {
      return metaData.getName();
    }
  }
  if (element instanceof PsiNamedElement) {
    return ((PsiNamedElement)element).getName();
  }
  else {
   // LOG.error("Unknown element type: " + element);
    return null;
  }
}
项目:intellij-ce-playground    文件:DomNameSuggestionProvider.java   
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, final PsiElement nameSuggestionContext, final Set<String> result) {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaData psiMetaData = ((PsiMetaOwner)element).getMetaData();
    if (psiMetaData instanceof DomMetaData) {
      final DomMetaData domMetaData = (DomMetaData)psiMetaData;
      final GenericDomValue value = domMetaData.getNameElement(domMetaData.getElement());
      ContainerUtil.addIfNotNull(getNameFromNameValue(value, true), result);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:XmlHighlightVisitor.java   
@Override public void visitXmlDocument(final XmlDocument document) {
  if (document.getLanguage() == DTDLanguage.INSTANCE) {
    final PsiMetaData psiMetaData = document.getMetaData();
    if (psiMetaData instanceof Validator) {
      //noinspection unchecked
      ((Validator<XmlDocument>)psiMetaData).validate(document, this);
    }
  }
}
项目:intellij-ce-playground    文件:XmlNSDescriptorImpl.java   
public static XmlNSDescriptorImpl getRedefinedElementDescriptor(final XmlTag parentTag) {
  XmlFile file = getRedefinedElementDescriptorFile(parentTag);
  if (file != null) {
    final XmlDocument document = file.getDocument();
    final PsiMetaData metaData = document != null ? document.getMetaData():null;
    if (metaData instanceof XmlNSDescriptorImpl) return (XmlNSDescriptorImpl)metaData;
  }
  return null;
}
项目:intellij-ce-playground    文件:XmlFindUsagesProvider.java   
@Override
@NotNull
public String getType(@NotNull PsiElement element) {
  if (element instanceof XmlTag) {
    final PsiMetaData metaData = ((XmlTag)element).getMetaData();
    if (metaData != null && metaData.getDeclaration() instanceof XmlTag) {
      return ((XmlTag)metaData.getDeclaration()).getName();
    }
    return LangBundle.message("xml.terms.xml.tag");
  }
  if (element instanceof XmlElementDecl) {
    return LangBundle.message("xml.terms.tag");
  }
  else if (element instanceof XmlAttributeDecl) {
    return LangBundle.message("xml.terms.attribute");
  }
  else if (element instanceof XmlAttributeValue) {
    return LangBundle.message("xml.terms.attribute.value");
  }
  else if (element instanceof XmlEntityDecl) {
    return LangBundle.message("xml.terms.entity");
  }
  else if (element instanceof XmlAttribute) {
    return LangBundle.message("xml.terms.attribute");
  } else if (element instanceof XmlComment) {
    return LangBundle.message("xml.terms.variable");
  }
  throw new IllegalArgumentException("Cannot get type for " + element);
}
项目:intellij-ce-playground    文件:CreateNSDeclarationIntentionFix.java   
@Override
public boolean isAcceptableMetaData(final PsiMetaData metaData, final String url) {
  if (metaData instanceof XmlNSDescriptorImpl) {
    final XmlNSDescriptorImpl nsDescriptor = (XmlNSDescriptorImpl)metaData;

    final XmlElementDescriptor descriptor = nsDescriptor.getElementDescriptor(searchFor(), url);
    return descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor);
  }
  return false;
}
项目:intellij-ce-playground    文件:Xsd2InstanceUtils.java   
public static XmlElementDescriptor getDescriptor(XmlTag tag, String elementName) {
  final PsiMetaData metaData = tag.getMetaData();

  if (metaData instanceof XmlNSDescriptorImpl) {
    final XmlNSDescriptorImpl nsDescriptor = (XmlNSDescriptorImpl) metaData;
    return nsDescriptor.getElementDescriptor(elementName, nsDescriptor.getDefaultNamespace());
  }

  return null;
}
项目:intellij-ce-playground    文件:Xsd2InstanceUtils.java   
public static List<String> addVariantsFromRootTag(XmlTag rootTag) {
  PsiMetaData metaData = rootTag.getMetaData();
  if (metaData instanceof XmlNSDescriptorImpl) {
    XmlNSDescriptorImpl nsDescriptor = (XmlNSDescriptorImpl) metaData;

    List<String> elementDescriptors = new ArrayList<String>();
    XmlElementDescriptor[] rootElementsDescriptors = nsDescriptor.getRootElementsDescriptors(PsiTreeUtil.getParentOfType(rootTag, XmlDocument.class));
    for(XmlElementDescriptor e:rootElementsDescriptors) {
      elementDescriptors.add(e.getName());
    }

    return elementDescriptors;
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:XmlTagPattern.java   
public Self withDescriptor(@NotNull final ElementPattern<? extends PsiMetaData> metaDataPattern) {
  return with(new PatternCondition<XmlTag>("withDescriptor") {
    @Override
    public boolean accepts(@NotNull final XmlTag xmlTag, final ProcessingContext context) {
      return metaDataPattern.accepts(xmlTag.getDescriptor());
    }
  });
}
项目:tools-idea    文件:PsiUtil.java   
public static boolean checkName(@NotNull PsiElement element, @NotNull String name, final PsiElement context) {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaData data = ((PsiMetaOwner) element).getMetaData();
    if (data != null) return name.equals(data.getName(context));
  }
  return element instanceof PsiNamedElement && name.equals(((PsiNamedElement)element).getName());
}
项目:tools-idea    文件:PsiElementPattern.java   
public Self withMetaData(final ElementPattern<? extends PsiMetaData> metaDataPattern) {
  return with(new PatternCondition<T>("withMetaData") {
    @Override
    public boolean accepts(@NotNull final T t, final ProcessingContext context) {
      return t instanceof PsiMetaOwner && metaDataPattern.accepts(((PsiMetaOwner)t).getMetaData(), context);
    }
  });
}
项目:tools-idea    文件:PsiUtilCore.java   
/**
 * @return name for element using element structure info
 */
@Nullable
public static String getName(PsiElement element) {
  String name = null;
  if (element instanceof PsiMetaOwner) {
    final PsiMetaData data = ((PsiMetaOwner) element).getMetaData();
    if (data != null) {
      name = data.getName(element);
    }
  }
  if (name == null && element instanceof PsiNamedElement) {
    name = ((PsiNamedElement) element).getName();
  }
  return name;
}
项目:tools-idea    文件:MetaRegistry.java   
public static void bindDataToElement(final PsiElement element, final PsiMetaData data) {
  CachedValue<PsiMetaData> value =
    CachedValuesManager.getManager(element.getProject()).createCachedValue(new CachedValueProvider<PsiMetaData>() {
      @Override
      public Result<PsiMetaData> compute() {
        data.init(element);
        return new Result<PsiMetaData>(data, data.getDependences());
      }
    });
  element.putUserData(META_DATA_KEY, value);
}
项目:tools-idea    文件:MetaRegistry.java   
/**
 * @see com.intellij.psi.meta.MetaDataContributor
 * @deprecated
 */
public static <T extends PsiMetaData> void addMetadataBinding(ElementFilter filter,
                                                              Class<T> aMetadataClass,
                                                              Disposable parentDisposable) {
  final MyBinding binding = new MyBinding(filter, aMetadataClass);
  addBinding(binding);
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      ourBindings.remove(binding);
    }
  });
}
项目:tools-idea    文件:CompletionData.java   
public static LookupElement objectToLookupItem(Object object) {
  if (object instanceof LookupElement) return (LookupElement)object;

  String s = null;
  TailType tailType = TailType.NONE;
  if (object instanceof PsiElement){
    s = PsiUtilCore.getName((PsiElement)object);
  }
  else if (object instanceof PsiMetaData) {
    s = ((PsiMetaData)object).getName();
  }
  else if (object instanceof String) {
    s = (String)object;
  }
  else if (object instanceof Template) {
    s = ((Template) object).getKey();
  }
  else if (object instanceof PresentableLookupValue) {
    s = ((PresentableLookupValue)object).getPresentation();
  }
  if (s == null) {
    throw new AssertionError("Null string for object: " + object + " of class " + (object != null ? object.getClass() : null));
  }

  LookupItem item = new LookupItem(object, s);

  if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
    item.setBold();
  }
  if (object instanceof LookupValueWithTail) {
    item.setAttribute(LookupItem.TAIL_TEXT_ATTR, " " + ((LookupValueWithTail)object).getTailText());
  }
  item.setAttribute(CompletionUtil.TAIL_TYPE_ATTR, tailType);
  return item;
}
项目:tools-idea    文件:UsageViewShortNameLocation.java   
@Override
public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
  if (!(location instanceof UsageViewShortNameLocation)) return null;

  if (element instanceof PsiMetaOwner) {
    PsiMetaData metaData = ((PsiMetaOwner)element).getMetaData();
    if (metaData!=null) return DescriptiveNameUtil.getMetaDataName(metaData);
  }

  if (element instanceof PsiNamedElement) {
    return ((PsiNamedElement)element).getName();
  }
  return "";
}