use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class FlexXmlBackedSymbolContributor method getItemsByName.
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
Collection<NavigationItem> result = new THashSet<>();
result.addAll(FlexXmlBackedMembersIndex.getItemsByName(name, project));
for (NavigationItem item : JavaScriptClassContributor.getItemsByNameStatic(name, project, includeNonProjectItems)) {
if (item instanceof XmlBackedJSClassImpl) {
result.add(item);
}
}
return result.toArray(new NavigationItem[result.size()]);
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class FlashUmlDependencyProvider method computeUsedClasses.
public Collection<Pair<JSClass, FlashUmlRelationship>> computeUsedClasses() {
final Collection<Pair<JSClass, FlashUmlRelationship>> result = new ArrayList<>();
final JSElementVisitor visitor = new JSElementVisitor() {
JSVariable myVariable;
JSNewExpression myNewExpression;
boolean myInField;
boolean myInParameter;
@Override
public void visitJSReferenceExpression(final JSReferenceExpression node) {
if (PsiTreeUtil.getParentOfType(node, JSImportStatement.class) != null) {
return;
}
if (myVariable == null && myNewExpression == null && !myInParameter && isReturnTypeReference(node)) {
return;
}
PsiElement resolved = node.resolve();
if (myNewExpression != null && resolved instanceof JSFunction) {
if (((JSFunction) resolved).isConstructor()) {
resolved = JSResolveUtil.findParent(resolved);
}
}
if (resolved instanceof JSClass) {
FlashUmlRelationship relType;
if (node.getParent() instanceof JSReferenceExpression) {
relType = Factory.dependency(myInField ? myVariable.getName() : null, myVariable != null ? myVariable : node);
} else if (myNewExpression != null) {
if (node.getParent() instanceof JSGenericSignature) {
relType = Factory.dependency(myInField ? myVariable.getName() : null, myVariable != null ? myVariable : node);
} else {
relType = Factory.create(myNewExpression);
}
} else if (myInField && node.getParent() instanceof JSGenericSignature) {
assert myVariable != null;
String qName = ((JSClass) resolved).getQualifiedName();
if (FlashUmlVfsResolver.isVectorType(qName)) {
relType = Factory.dependency(myVariable.getName(), myVariable);
} else {
relType = Factory.oneToMany(myVariable.getName(), myVariable);
}
} else if (myInField) {
assert myVariable != null;
String qName = ((JSClass) resolved).getQualifiedName();
if (FlashUmlVfsResolver.isVectorType(qName)) {
relType = Factory.dependency(myVariable.getName(), myVariable);
} else {
relType = Factory.oneToOne(myVariable.getName(), myVariable);
}
} else {
relType = Factory.dependency(null, myVariable != null ? myVariable : node);
}
result.add(Pair.create((JSClass) resolved, relType));
}
super.visitJSReferenceExpression(node);
}
@Override
public void visitJSVariable(final JSVariable node) {
if (node instanceof JSParameter) {
myInParameter = true;
} else {
myVariable = node;
}
myInField = JSResolveUtil.findParent(node) instanceof JSClass;
try {
super.visitJSVariable(node);
} finally {
myVariable = null;
myInField = false;
myInParameter = false;
}
}
@Override
public void visitJSNewExpression(final JSNewExpression node) {
myNewExpression = node;
try {
super.visitJSNewExpression(node);
} finally {
myNewExpression = null;
}
}
@Override
public void visitElement(final PsiElement element) {
super.visitElement(element);
element.acceptChildren(this);
}
};
if (myClazz instanceof XmlBackedJSClassImpl) {
// TODO process attributes
((XmlBackedJSClassImpl) myClazz).processInjectedFiles(jsFile -> {
jsFile.accept(visitor);
return true;
});
myClazz.getParent().acceptChildren(new // don't visit parent tag
XmlElementVisitor() {
// also to prevent extra references resolve
private String myInClassAttributeName;
@Override
public void visitXmlTag(final XmlTag tag) {
XmlElementDescriptor descriptor = tag.getDescriptor();
if (descriptor != null) {
PsiElement declaration = descriptor.getDeclaration();
if (declaration instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) declaration)) {
declaration = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) declaration);
}
if (declaration instanceof JSClass) {
XmlAttribute id = tag.getAttribute("id");
FlashUmlRelationship type = id != null && StringUtil.isNotEmpty(id.getValue()) ? Factory.oneToOne(id.getValue(), id) : Factory.dependency(null, tag);
result.add(Pair.create((JSClass) declaration, type));
}
}
super.visitXmlTag(tag);
}
@Override
public void visitXmlAttribute(final XmlAttribute attribute) {
XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (descriptor instanceof AnnotationBackedDescriptor) {
if (FlexReferenceContributor.isClassReferenceType(((AnnotationBackedDescriptor) descriptor).getType())) {
myInClassAttributeName = StringUtil.notNullize(attribute.getName());
try {
super.visitXmlAttribute(attribute);
} finally {
myInClassAttributeName = null;
}
}
}
}
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
if (myInClassAttributeName != null) {
processReferenceSet(value.getReferences(), result, Factory.dependency(myInClassAttributeName, value.getParent()));
}
}
@Override
public void visitXmlText(final XmlText text) {
List<Pair<PsiElement, TextRange>> injectedFiles = InjectedLanguageManager.getInstance(text.getProject()).getInjectedPsiFiles(text);
if (injectedFiles != null) {
for (Pair<PsiElement, TextRange> pair : injectedFiles) {
if (CSS.is(pair.first.getLanguage())) {
pair.first.accept(new CssElementVisitor() {
// to prevent extra references resolve
private boolean myInClassReference;
@Override
public void visitElement(final PsiElement element) {
super.visitElement(element);
element.acceptChildren(this);
}
@Override
public void visitCssFunction(final CssFunction _function) {
if (FlexReferenceContributor.CLASS_REFERENCE.equals(_function.getName())) {
myInClassReference = true;
try {
super.visitCssFunction(_function);
} finally {
myInClassReference = false;
}
}
}
@Override
public void visitCssString(final CssString _string) {
if (myInClassReference) {
CssDeclaration declaration = PsiTreeUtil.getParentOfType(_string, CssDeclaration.class);
if (declaration != null) {
processReferenceSet(_string.getReferences(), result, Factory.dependency(declaration.getPropertyName(), declaration));
}
}
}
});
}
}
}
super.visitXmlText(text);
}
@Override
public void visitElement(final PsiElement element) {
super.visitElement(element);
element.acceptChildren(this);
}
});
}
myClazz.processDeclarations(new BaseScopeProcessor() {
@Override
public boolean execute(@NotNull final PsiElement element, @NotNull final ResolveState state) {
element.accept(visitor);
return true;
}
}, ResolveState.initial(), myClazz, myClazz);
return result;
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class FlashUmlDataModel method removeEdge.
@Override
public void removeEdge(DiagramEdge<Object> edge) {
final Object source = edge.getSource().getIdentifyingElement();
final Object target = edge.getTarget().getIdentifyingElement();
final DiagramRelationshipInfo relationship = edge.getRelationship();
if (!(source instanceof JSClass) || !(target instanceof JSClass) || relationship == DiagramRelationshipInfo.NO_RELATIONSHIP) {
return;
}
final JSClass fromClass = (JSClass) source;
final JSClass toClass = (JSClass) target;
if (JSProjectUtil.isInLibrary(fromClass)) {
return;
}
if (fromClass instanceof XmlBackedJSClassImpl && !toClass.isInterface()) {
Messages.showErrorDialog(fromClass.getProject(), FlexBundle.message("base.component.needed.message"), FlexBundle.message("remove.edge.title"));
return;
}
if (Messages.showYesNoDialog(fromClass.getProject(), FlexBundle.message("remove.inheritance.link.prompt", fromClass.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("remove.edge.title"), Messages.getQuestionIcon()) != Messages.YES) {
return;
}
final Runnable runnable = () -> {
JSReferenceList refList = !fromClass.isInterface() && toClass.isInterface() ? fromClass.getImplementsList() : fromClass.getExtendsList();
List<FormatFixer> formatters = new ArrayList<>();
JSRefactoringUtil.removeFromReferenceList(refList, toClass, formatters);
if (!(fromClass instanceof XmlBackedJSClassImpl) && needsImport(fromClass, toClass)) {
formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
}
FormatFixer.fixAll(formatters);
};
DiagramAction.performCommand(getBuilder(), runnable, FlexBundle.message("remove.relationship.command.name"), null, fromClass.getContainingFile());
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class AnnotationBackedDescriptorImpl method getDeclaration.
@Override
@Nullable
public PsiElement getDeclaration() {
final PsiElement[] result = new PsiElement[1];
final PsiElement parentDescriptorDeclaration = parentDescriptor.getDeclaration();
PsiElement element = parentDescriptorDeclaration;
if (predefined)
return element;
if (myOriginatingElementType == OriginatingElementType.IdAttribute) {
return findDeclarationByIdAttributeValue(parentDescriptorDeclaration, new THashSet<>());
}
while (element instanceof XmlFile) {
XmlTag rootTag = ((XmlFile) element).getDocument().getRootTag();
element = JSResolveUtil.getClassFromTagNameInMxml(rootTag.getFirstChild());
if (element instanceof XmlBackedJSClassImpl) {
element = element.getParent().getContainingFile();
}
}
final JSNamedElement jsClass = (JSNamedElement) element;
final ClassBackedElementDescriptor.AttributedItemsProcessor itemsProcessor = new ClassBackedElementDescriptor.AttributedItemsProcessor() {
@Override
public boolean process(final JSNamedElement jsNamedElement, final boolean isPackageLocalVisibility) {
if (myOriginatingElementType != OriginatingElementType.Metadata && name.equals(jsNamedElement.getName())) {
result[0] = jsNamedElement;
return false;
}
return true;
}
@Override
public boolean process(final JSAttributeNameValuePair pair, final String annotationName, final boolean included) {
if (myOriginatingElementType == OriginatingElementType.Metadata && name.equals(pair.getSimpleValue()) && included) {
result[0] = pair;
return false;
}
return true;
}
};
boolean b = jsClass == null || ClassBackedElementDescriptor.processAttributes(jsClass, itemsProcessor);
if (b && jsClass instanceof JSClass) {
final JSClass clazz = (JSClass) jsClass;
final JSClass[] classes = clazz.getSuperClasses();
if (classes.length > 0 && clazz.getName().equals(classes[0].getName()) && clazz != classes[0]) {
b = ClassBackedElementDescriptor.processAttributes(classes[0], itemsProcessor);
}
}
if (b && parentDescriptorDeclaration instanceof XmlFile) {
final JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {
@Override
protected void process(final JSFile file) {
ClassBackedElementDescriptor.processAttributes(file, itemsProcessor);
}
};
element = parentDescriptorDeclaration;
while (element instanceof XmlFile) {
XmlTag rootTag = ((XmlFile) element).getDocument().getRootTag();
FlexUtils.processMxmlTags(rootTag, true, injectedFilesVisitor);
if (result[0] != null)
break;
element = JSResolveUtil.getClassFromTagNameInMxml(rootTag.getFirstChild());
if (element instanceof XmlBackedJSClassImpl) {
element = element.getParent().getContainingFile();
}
}
}
return result[0];
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class ClassBackedElementDescriptor method ensureDescriptorsMapsInitialized.
private void ensureDescriptorsMapsInitialized(PsiElement element, @Nullable Set<JSClass> visited) {
Map<String, AnnotationBackedDescriptor> map;
Map<String, Map<String, AnnotationBackedDescriptor>> packageToInternalDescriptors;
synchronized (CodeContext.class) {
map = myDescriptors;
packageToInternalDescriptors = myPackageToInternalDescriptors;
if (map != null && packageToInternalDescriptors != null)
return;
map = new THashMap<>();
packageToInternalDescriptors = new THashMap<>();
Set<PsiElement> processedElements = null;
if (element instanceof XmlBackedJSClassImpl) {
// TODO: make this code and following loop better
element = element.getParent().getContainingFile();
}
if (element instanceof XmlFile && MxmlJSClass.isFxgFile((PsiFile) element)) {
element = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
}
while (element instanceof XmlFile) {
final XmlDocument document = ((XmlFile) element).getDocument();
final XmlTag rootTag = document != null ? document.getRootTag() : null;
final XmlElementDescriptor descriptor = rootTag != null ? rootTag.getDescriptor() : null;
if (processedElements == null)
processedElements = new THashSet<>();
processedElements.add(element);
element = descriptor != null ? descriptor.getDeclaration() : null;
if (processedElements.contains(element))
break;
collectMxmlAttributes(map, packageToInternalDescriptors, rootTag);
}
if (element instanceof JSNamedElement) {
JSNamedElement jsClass = (JSNamedElement) element;
if (visited == null || !visited.contains(jsClass)) {
if (!MxmlJSClass.XML_TAG_NAME.equals(jsClass.getName()) && !MxmlJSClass.XMLLIST_TAG_NAME.equals(jsClass.getName())) {
JSReferenceList extendsList = jsClass instanceof JSClass ? ((JSClass) jsClass).getExtendsList() : null;
if (extendsList != null) {
final JSClass clazz = (JSClass) jsClass;
if (visited == null) {
visited = new THashSet<>();
}
visited.add(clazz);
for (JSClass superClazz : clazz.getSuperClasses()) {
appendSuperClassDescriptors(map, packageToInternalDescriptors, superClazz, visited);
}
} else if (!OBJECT_CLASS_NAME.equals(jsClass.getName()) && CodeContext.isStdNamespace(context.namespace)) {
appendSuperClassDescriptors(map, packageToInternalDescriptors, ActionScriptClassResolver.findClassByQNameStatic(OBJECT_CLASS_NAME, jsClass), visited);
}
}
collectMyAttributes(jsClass, map, packageToInternalDescriptors);
}
}
myDescriptors = map;
myPackageToInternalDescriptors = packageToInternalDescriptors;
}
}
Aggregations