use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class DefinitionReference method getVariants.
@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();
}
use of com.intellij.psi.meta.PsiMetaOwner in project intellij-community by JetBrains.
the class TagNameReference method bindToElement.
@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) {
// TODO: need to evaluate new ns prefix
return getTagElement().setName(metaData.getName(getElement()));
}
} 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"));
}
Aggregations