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

项目: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    文件: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    文件: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    文件: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"));
}
项目: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    文件:XmlDocumentImpl.java   
@Nullable
private XmlNSDescriptor getNSDescriptorFromMetaData(@Nullable PsiMetaOwner metaOwner, boolean nonEmpty)
{
    if(metaOwner == null)
    {
        return null;
    }
    XmlNSDescriptor descriptor = (XmlNSDescriptor) metaOwner.getMetaData();
    if(descriptor == null)
    {
        return null;
    }
    if(nonEmpty && descriptor.getRootElementsDescriptors(this).length == 0)
    {
        return null;
    }
    return descriptor;
}
项目:consulo-java    文件:JavaFindUsagesProvider.java   
@Override
public boolean canFindUsagesFor(@NotNull PsiElement element)
{
    if(element instanceof PsiDirectory)
    {
        PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
        return psiPackage != null && psiPackage.getQualifiedName().length() != 0;
    }

    return element instanceof PsiClass ||
            element instanceof PsiVariable ||
            element instanceof PsiMethod ||
            element instanceof PsiPackage ||
            element instanceof PsiLabeledStatement ||
            ThrowSearchUtil.isSearchable(element) ||
            element instanceof PsiMetaOwner && ((PsiMetaOwner) element).getMetaData() != null;
}
项目: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    文件:JavaFindUsagesProvider.java   
@Override
public boolean canFindUsagesFor(@NotNull PsiElement element) {
  if (element instanceof PsiDirectory) {
    PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element);
    return psiPackage != null && psiPackage.getQualifiedName().length() != 0;
  }

  return element instanceof PsiClass ||
         element instanceof PsiVariable ||
         element instanceof PsiMethod ||
         element instanceof PsiPackage ||
         element instanceof PsiLabeledStatement ||
         ThrowSearchUtil.isSearchable(element) ||
         element instanceof PsiMetaOwner && ((PsiMetaOwner)element).getMetaData() != null;
}
项目: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    文件: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    文件:XmlTagImpl.java   
@Nullable
private PsiMetaOwner retrieveOwner(final XmlFile file, @NotNull final String namespace) {
  if (file == null) {
    return namespace.equals(XmlUtil.getTargetSchemaNsFromTag(this)) ? this : null;
  }
  return file.getDocument();
}
项目:intellij-ce-playground    文件:XmlDocumentImpl.java   
@Nullable
private XmlNSDescriptor getNSDescriptorFromMetaData(@Nullable PsiMetaOwner metaOwner, boolean nonEmpty) {
  if (metaOwner == null) return null;
  XmlNSDescriptor descriptor = (XmlNSDescriptor)metaOwner.getMetaData();
  if (descriptor == null) return null;
  if (nonEmpty && descriptor.getRootElementsDescriptors(this).length == 0) {
    return null;
  }
  return descriptor;
}
项目:intellij-ce-playground    文件:XmlAttributeReference.java   
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaOwner owner = (PsiMetaOwner)element;
    if (owner.getMetaData() instanceof XmlElementDescriptor) {
      myAttribute.setName(owner.getMetaData().getName());
    }
  }
  throw new IncorrectOperationException("Cant bind to not a xml element definition!");
}
项目: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();
}
项目:intellij-ce-playground    文件:ValueResourceElementWrapper.java   
public ValueResourceElementWrapper(@NotNull XmlAttributeValue wrappeeElement) {
  if (!(wrappeeElement instanceof NavigationItem)) {
    throw new IllegalArgumentException();
  }
  if (!(wrappeeElement instanceof PsiMetaOwner)) {
    throw new IllegalArgumentException();
  }
  myWrappee = wrappeeElement;
  final PsiFile file = getContainingFile();
  myFileName = file != null ? file.getName() : null;
  final PsiDirectory dir = file != null ? file.getContainingDirectory() : null;
  myDirName = dir != null ? dir.getName() : null;
}
项目: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    文件:JavaFindUsagesProvider.java   
@Override
public boolean canFindUsagesFor(@NotNull PsiElement element) {
  if (element instanceof PsiDirectory) {
    PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element);
    return psiPackage != null && psiPackage.getQualifiedName().length() != 0;
  }

  return element instanceof PsiClass ||
         element instanceof PsiVariable ||
         element instanceof PsiMethod ||
         element instanceof PsiPackage ||
         element instanceof PsiLabeledStatement ||
         ThrowSearchUtil.isSearchable(element) ||
         element instanceof PsiMetaOwner && ((PsiMetaOwner)element).getMetaData() != null;
}
项目: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    文件: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 "";
}
项目: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    文件: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;
  }
}
项目:tools-idea    文件:DomNameSuggestionProvider.java   
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;
}
项目:tools-idea    文件:XmlTagImpl.java   
@Nullable
private PsiMetaOwner retrieveOwner(final XmlFile file, final String namespace) {
  if (file == null) {
    return namespace.equals(XmlUtil.getTargetSchemaNsFromTag(this)) ? this : null;
  }
  return file.getDocument();
}
项目:tools-idea    文件:XmlDocumentImpl.java   
@Nullable
private XmlNSDescriptor getNSDescriptorFromMetaData(@Nullable PsiMetaOwner metaOwner, boolean nonEmpty) {
  if (metaOwner == null) return null;
  XmlNSDescriptor descriptor = (XmlNSDescriptor)metaOwner.getMetaData();
  if (descriptor == null) return null;
  if (nonEmpty && descriptor.getRootElementsDescriptors(this).length == 0) {
    return null;
  }
  return descriptor;
}
项目:tools-idea    文件:XmlAttributeReference.java   
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  if (element instanceof PsiMetaOwner) {
    final PsiMetaOwner owner = (PsiMetaOwner)element;
    if (owner.getMetaData() instanceof XmlElementDescriptor) {
      myAttribute.setName(owner.getMetaData().getName());
    }
  }
  throw new IncorrectOperationException("Cant bind to not a xml element definition!");
}
项目: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    文件:PsiElementPattern.java   
public Self withMetaData(final ElementPattern<? extends PsiMetaData> metaDataPattern) {
  return with(new PatternCondition<T>("withMetaData") {
    @Override
    public boolean accepts(@Nonnull final T t, final ProcessingContext context) {
      return t instanceof PsiMetaOwner && metaDataPattern.accepts(((PsiMetaOwner)t).getMetaData(), context);
    }
  });
}
项目:consulo    文件: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;
}
项目:consulo    文件:UsageViewShortNameLocation.java   
@Override
public String getElementDescription(@Nonnull final PsiElement element, @Nonnull 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 "";
}
项目: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    文件:DefaultNonCodeSearchElementDescriptionProvider.java   
@Override
public String getElementDescription(@Nonnull final PsiElement element, @Nonnull final ElementDescriptionLocation location) {
  if (!(location instanceof NonCodeSearchDescriptionLocation)) return null;
  final NonCodeSearchDescriptionLocation ncdLocation = (NonCodeSearchDescriptionLocation)location;

  if (element instanceof PsiDirectory) {
    if (ncdLocation.isNonJava()) {
      final String qName = PsiPackageHelper.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;
  }
}