use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class ActionScriptImportHandler method _resolveTypeName.
// TODO _str should be JSReferenceExpression for caching!
@Nullable
private JSImportedElementResolveResult _resolveTypeName(@Nullable final String _name, @NotNull PsiElement context) {
String name = _name;
if (name == null)
return null;
JSResolveUtil.GenericSignature genericSignature = JSResolveUtil.extractGenericSignature(name);
if (genericSignature != null) {
name = genericSignature.elementType;
}
final Ref<JSImportedElementResolveResult> resultRef = new Ref<>();
final String name1 = name;
JSResolveUtil.walkOverStructure(context, context1 -> {
JSImportedElementResolveResult resolved = null;
if (context1 instanceof XmlBackedJSClassImpl) {
XmlTag rootTag = ((XmlBackedJSClassImpl) context1).getParent();
if (rootTag != null && name1.equals(rootTag.getLocalName())) {
final XmlElementDescriptor descriptor = rootTag.getDescriptor();
PsiElement element = descriptor != null ? descriptor.getDeclaration() : null;
if (element instanceof XmlFile) {
element = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
}
final String s = element instanceof JSClass ? ((JSClass) element).getQualifiedName() : rootTag.getLocalName();
resolved = new JSImportedElementResolveResult(s);
} else {
resolved = resolveTypeNameUsingImports(name1, context1);
}
} else if (context1 instanceof JSQualifiedNamedElement) {
if (context1 instanceof JSClass && name1.equals(context1.getName())) {
resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) context1).getQualifiedName());
} else {
resolved = resolveTypeNameUsingImports(name1, context1);
if (resolved == null && context1.getParent() instanceof JSFile) {
final String qName = ((JSQualifiedNamedElement) context1).getQualifiedName();
final String packageName = qName == null ? "" : context1 instanceof JSPackageStatement ? qName + "." : qName.substring(0, qName.lastIndexOf('.') + 1);
if (packageName.length() != 0) {
final PsiElement byQName = JSClassResolver.findClassFromNamespace(packageName + name1, context1);
if (byQName instanceof JSQualifiedNamedElement) {
resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) byQName).getQualifiedName());
}
}
}
}
} else {
resolved = resolveTypeNameUsingImports(name1, context1);
PsiElement contextOfContext;
if (resolved == null && context1 instanceof JSFile && (contextOfContext = context1.getContext()) != null) {
XmlBackedJSClassImpl clazz = contextOfContext instanceof XmlElement ? (XmlBackedJSClassImpl) XmlBackedJSClassImpl.getContainingComponent((XmlElement) contextOfContext) : null;
if (clazz != null) {
SinkResolveProcessor r = new SinkResolveProcessor(name1, new ResolveResultSink(null, name1));
r.setForceImportsForPlace(true);
boolean b = clazz.doImportFromScripts(r, clazz);
if (!b) {
PsiElement resultFromProcessor = r.getResult();
JSQualifiedNamedElement clazzFromComponent = resultFromProcessor instanceof JSQualifiedNamedElement ? (JSQualifiedNamedElement) resultFromProcessor : null;
if (clazzFromComponent != null) {
resolved = new JSImportedElementResolveResult(clazzFromComponent.getQualifiedName(), clazz, null);
}
}
}
}
}
if (resolved != null) {
resultRef.set(resolved);
return false;
}
if (context1 instanceof JSPackageStatement)
return false;
return true;
});
JSImportedElementResolveResult result = resultRef.get();
if (genericSignature != null && result != null) {
// TODO: more than one type parameter
StringBuilder genericSignatureBuffer = new StringBuilder();
genericSignatureBuffer.append(".<");
genericSignatureBuffer.append(resolveTypeName(genericSignature.genericType, context).getQualifiedName());
genericSignatureBuffer.append(">");
result = result.appendSignature(genericSignatureBuffer.toString());
}
return result;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FxDefinitionBackedDescriptor method getClassBackedDescriptor.
@Nullable
private ClassBackedElementDescriptor getClassBackedDescriptor() {
final XmlTag tag = PsiTreeUtil.getParentOfType(getDeclaration(), XmlTag.class);
final XmlTag[] subTags = tag == null ? XmlTag.EMPTY : tag.getSubTags();
if (subTags.length == 1) {
final XmlElementDescriptor descriptor = subTags[0].getDescriptor();
return descriptor instanceof ClassBackedElementDescriptor ? (ClassBackedElementDescriptor) descriptor : null;
}
return null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class MxmlTagNameReference method fixSubTagsPrefixes.
private static void fixSubTagsPrefixes(final XmlTag tag, final String oldPrefix, final String newPrefix) {
final XmlElementDescriptor descriptor = tag.getDescriptor();
if (!(descriptor instanceof ClassBackedElementDescriptor)) {
return;
}
for (final XmlTag subTag : tag.getSubTags()) {
if (Comparing.strEqual(subTag.getNamespacePrefix(), oldPrefix) && subTag.getDescriptor() == null) {
final String oldSubTagName = subTag.getName();
subTag.setName(StringUtil.isEmpty(newPrefix) ? subTag.getLocalName() : (newPrefix + ":" + subTag.getLocalName()));
final XmlElementDescriptor subTagDescriptor = descriptor.getElementDescriptor(subTag, tag);
if (!(subTagDescriptor instanceof AnnotationBackedDescriptor)) {
subTag.setName(oldSubTagName);
}
}
}
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class XmlTagValueProvider method getSubstituted.
@Override
public CharSequence getSubstituted() {
CharSequence v = getDisplay(tag.getValue().getChildren());
if (v == EMPTY) {
return EMPTY;
}
XmlElementDescriptor descriptor = tag.getDescriptor();
// may be ClassBackedElementDescriptor for fx:String: <TextArea><text><fx:String>sfsdsd</fx:String></text></TextArea>
if (descriptor instanceof AnnotationBackedDescriptor && ((AnnotationBackedDescriptor) descriptor).isCollapseWhiteSpace()) {
return CharMatcher.WHITESPACE.trimAndCollapseFrom(v, ' ');
} else {
return v;
}
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class MxmlWriter method write.
@Nullable
public Pair<ProjectComponentReferenceCounter, List<RangeMarker>> write(XmlFile psiFile) throws IOException {
document = MxmlUtil.getDocumentAndWaitIfNotCommitted(psiFile);
final AccessToken token = ReadAction.start();
try {
VirtualFile virtualFile = psiFile.getVirtualFile();
LOG.assertTrue(virtualFile != null);
problemsHolder.setCurrentFile(virtualFile);
XmlTag tag = psiFile.getRootTag();
XmlElementDescriptor untypedDescriptor = tag == null ? null : tag.getDescriptor();
final ClassBackedElementDescriptor descriptor;
if (untypedDescriptor instanceof ClassBackedElementDescriptor) {
descriptor = (ClassBackedElementDescriptor) untypedDescriptor;
} else {
return null;
}
final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
try {
PsiElement declaration = descriptor.getDeclaration();
if (declaration == null) {
return null;
}
effectiveClassInfo = MxmlUtil.computeEffectiveClass(tag, declaration, projectComponentReferenceCounter, true);
} catch (InvalidPropertyException e) {
problemsHolder.add(e);
return null;
}
if (effectiveClassInfo.first == -1) {
out.write(Amf3Types.OBJECT);
writer.mxmlObjectHeader(effectiveClassInfo.second == null ? descriptor.getQualifiedName() : effectiveClassInfo.second);
} else {
writer.documentReference(effectiveClassInfo.first);
out.allocateClearShort();
}
processElements(tag, null, false, -1, out.size() - 2, true, effectiveClassInfo.third);
writer.endObject();
if (stateWriter != null) {
stateWriter.write();
hasStates = false;
} else {
out.write(0);
}
injectedASWriter.write();
writer.writeMessageHeader(projectComponentReferenceCounter);
return Pair.create(projectComponentReferenceCounter, rangeMarkers);
} finally {
token.finish();
problemsHolder.setCurrentFile(null);
writer.resetAfterMessage();
}
}
Aggregations