use of com.intellij.psi.meta.PsiMetaData in project intellij-plugins by JetBrains.
the class MxmlReferenceContributor method createReferenceProviderForTagOrAttributeExpectingJSClass.
private static PsiReferenceProvider createReferenceProviderForTagOrAttributeExpectingJSClass(final Function<PsiReference, LocalQuickFix[]> quickFixProvider) {
return new PsiReferenceProvider() {
@NotNull
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
final PsiMetaData descriptor;
final String name;
if (element instanceof XmlTag) {
descriptor = ((XmlTag) element).getDescriptor();
name = ((XmlTag) element).getLocalName();
} else if (element instanceof XmlAttributeValue) {
final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class);
descriptor = xmlAttribute == null ? null : xmlAttribute.getDescriptor();
name = xmlAttribute == null ? "" : xmlAttribute.getName();
} else {
assert false : element;
return PsiReference.EMPTY_ARRAY;
}
if (!(descriptor instanceof AnnotationBackedDescriptor))
return PsiReference.EMPTY_ARRAY;
final String type = ((AnnotationBackedDescriptor) descriptor).getType();
if (!FlexReferenceContributor.isClassReferenceType(type))
return PsiReference.EMPTY_ARRAY;
final Pair<String, TextRange> trimmedValueAndRange = getTrimmedValueAndRange((XmlElement) element);
if (trimmedValueAndRange.second.getStartOffset() == 0)
return PsiReference.EMPTY_ARRAY;
if (trimmedValueAndRange.first.indexOf('{') != -1 || trimmedValueAndRange.first.indexOf('@') != -1)
return PsiReference.EMPTY_ARRAY;
final JSReferenceSet jsReferenceSet = new JSReferenceSet(element, trimmedValueAndRange.first, trimmedValueAndRange.second.getStartOffset(), false, true) {
@Override
protected JSTextReference createTextReference(String s, int offset, boolean methodRef) {
return new MyJSTextReference(this, s, offset, methodRef, quickFixProvider);
}
};
if (SKIN_CLASS_ATTR_NAME.equals(name)) {
jsReferenceSet.setBaseClassFqns(Collections.singletonList(UI_COMPONENT_FQN));
}
return jsReferenceSet.getReferences();
}
};
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-plugins by JetBrains.
the class PropertyProcessor method writeClassFactory.
private void writeClassFactory(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
if (valueProvider instanceof XmlTagValueProvider) {
XmlTag tag = ((XmlTagValueProvider) valueProvider).getTag();
XmlTag[] subTags = tag.getSubTags();
if (subTags.length > 0) {
processFxComponent(subTags[0], true);
return;
}
}
String className = valueProvider.getTrimmed();
if (writeFxComponentReferenceIfProcessed(className) || writeReferenceIfReferenced(className)) {
return;
}
final JSClass jsClass = valueProvider.getJsClass();
if (jsClass == null) {
throw new InvalidPropertyException(valueProvider.getElement(), "unresolved.class", valueProvider.getTrimmed());
}
final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
final PsiElement parent = jsClass.getNavigationElement().getParent();
if (parent instanceof XmlTag && MxmlUtil.isComponentLanguageTag((XmlTag) parent)) {
// if referenced by inner class name, but inner fx component is not yet processed
if (parent.getContainingFile().equals(valueProvider.getElement().getContainingFile())) {
processFxComponent((XmlTag) parent, false);
return;
} else {
effectiveClassInfo = new Trinity<>(-1, "mx.core.UIComponent", null);
}
} else {
effectiveClassInfo = MxmlUtil.computeEffectiveClass(valueProvider.getElement(), jsClass, mxmlWriter.projectComponentReferenceCounter, false);
}
if (effectiveClassInfo.first == -1) {
if (effectiveClassInfo.second != null) {
if (effectiveClassInfo.second.equals("mx.core.UIComponent")) {
PsiMetaData psiMetaData = valueProvider.getPsiMetaData();
if (psiMetaData != null && psiMetaData.getName().equals("itemRenderer") && MxmlUtil.isPropertyOfSparkDataGroup((AnnotationBackedDescriptor) psiMetaData)) {
className = MxmlUtil.UNKNOWN_ITEM_RENDERER_CLASS_NAME;
} else {
className = MxmlUtil.UNKNOWN_COMPONENT_CLASS_NAME;
}
} else {
className = effectiveClassInfo.second;
}
}
writeNonProjectUnreferencedClassFactory(className);
} else {
writer.documentFactoryReference(effectiveClassInfo.first);
}
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class DescriptiveNameUtil method getDescriptiveName.
@NotNull
public static String getDescriptiveName(@NotNull PsiElement psiElement) {
LOG.assertTrue(psiElement.isValid());
if (psiElement instanceof PsiMetaOwner) {
final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) psiElement;
final PsiMetaData metaData = psiMetaOwner.getMetaData();
if (metaData != null)
return getMetaDataName(metaData);
}
if (psiElement instanceof PsiFile) {
return ((PsiFile) psiElement).getName();
}
final Language lang = psiElement.getLanguage();
final FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
assert provider != null : lang;
return provider.getDescriptiveName(psiElement);
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class CompletionData method objectToLookupItem.
public static LookupElement objectToLookupItem(@NotNull final 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;
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class AbstractQualifiedReference method bindToElement.
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
CheckUtil.checkWritable(this);
if (isReferenceTo(element))
return this;
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
final String methodName = method.getName();
if (isDirectlyVisible(method))
return replaceReference(methodName);
final AbstractQualifiedReference result = replaceReference(method.getContainingClass().getQualifiedName() + "." + methodName);
final AbstractQualifiedReference qualifier = result.getQualifier();
assert qualifier != null;
qualifier.shortenReferences();
return result;
}
if (element instanceof PsiClass) {
return replaceReference(((PsiClass) element).getQualifiedName()).shortenReferences();
}
if (element instanceof PsiPackage) {
return replaceReference(((PsiPackage) element).getQualifiedName());
}
if (element instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
if (metaData != null) {
final String name = metaData.getName(this);
if (name != null) {
return replaceReference(name);
}
}
}
return this;
}
Aggregations