use of com.intellij.psi.xml.XmlElement 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.psi.xml.XmlElement in project intellij-plugins by JetBrains.
the class ExtendableClassConverterImpl method fromString.
public PsiClass fromString(@Nullable @NonNls final String s, final ConvertContext context) {
if (s == null) {
return null;
}
// resolve JAVA-class directly
final PsiClass psiClass = DomJavaUtil.findClass(s, context.getInvocationElement());
if (psiClass != null) {
return psiClass;
}
// first match in additional providers
final XmlElement element = context.getReferenceXmlElement();
assert element != null;
final ExtendClass extendClass = getExtendsAnnotation(context.getInvocationElement());
for (final ExtendableClassConverterContributor contributor : Extensions.getExtensions(EP_NAME)) {
if (contributor.isSuitable(context)) {
final PsiReference[] add = contributor.getReferences(context, element, extendClass);
if (add.length == 1) {
final PsiElement resolveElement = add[0].resolve();
if (resolveElement != null) {
return (PsiClass) resolveElement;
}
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlElement in project intellij-plugins by JetBrains.
the class FieldNameConverterImpl method findBeanPropertyClass.
@Override
protected PsiClass findBeanPropertyClass(@NotNull final DomElement domElement) {
final XmlElement xmlElement = domElement.getXmlElement();
assert xmlElement != null;
final PsiFile psiFile = xmlElement.getContainingFile().getOriginalFile();
final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
if (containingDirectory == null) {
return null;
}
final PsiPackage containingPackage = JavaDirectoryService.getInstance().getPackage(containingDirectory);
if (containingPackage == null) {
return null;
}
// ClassName-[method-]validation.xml
final String validationFileName = psiFile.getName();
final String actionClassName = StringUtil.split(validationFileName, "-").get(0);
final String qualifiedActionClassName = StringUtil.getQualifiedName(containingPackage.getQualifiedName(), actionClassName);
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(psiFile.getProject());
return psiFacade.findClass(qualifiedActionClassName, new PackageScope(containingPackage, false, false));
}
use of com.intellij.psi.xml.XmlElement in project intellij-plugins by JetBrains.
the class StrutsDataModel method addNode.
private void addNode(final BasicStrutsNode node) {
if (!node.getIdentifyingElement().isValid()) {
return;
}
myNodes.add(node);
if (isGroupElements()) {
final XmlElement element = node.getIdentifyingElement().getXmlElement();
assert element != null;
final PsiFile file = element.getContainingFile();
if (file != null && !myGroups.containsKey(file)) {
final String name = file.getName();
final BasicNodesGroup group = new BasicNodesGroup(name) {
@Nullable
public GroupNodeRealizer getGroupNodeRealizer() {
final GroupNodeRealizer groupNodeRealizer = super.getGroupNodeRealizer();
assert groupNodeRealizer != null;
final NodeLabel nodeLabel = groupNodeRealizer.getLabel();
nodeLabel.setText(" " + getGroupName());
nodeLabel.setModel(NodeLabel.INTERNAL);
nodeLabel.setPosition(NodeLabel.TOP_RIGHT);
return groupNodeRealizer;
}
};
// collapse all other files
group.setClosed(file != myFile);
myGroups.put(file, group);
}
}
}
Aggregations