use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class FlexResolveHelper method importClass.
public boolean importClass(final PsiScopeProcessor processor, final PsiNamedElement file) {
// there is no need to process package stuff at function level
if (file instanceof JSFunction)
return true;
if (file instanceof XmlBackedJSClassImpl) {
if (!processInlineComponentsInScope((XmlBackedJSClassImpl) file, inlineComponent -> processor.execute(inlineComponent, ResolveState.initial()))) {
return false;
}
}
final String packageQualifierText = JSResolveUtil.findPackageStatementQualifier(file);
final Project project = file.getProject();
GlobalSearchScope scope = JSResolveUtil.getResolveScope(file);
final MxmlAndFxgFilesProcessor filesProcessor = new MxmlAndFxgFilesProcessor() {
final PsiManager manager = PsiManager.getInstance(project);
public void addDependency(final PsiDirectory directory) {
}
public boolean processFile(final VirtualFile file, final VirtualFile root) {
final PsiFile xmlFile = manager.findFile(file);
if (!(xmlFile instanceof XmlFile))
return true;
return processor.execute(XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) xmlFile), ResolveState.initial());
}
};
PsiFile containingFile = file.getContainingFile();
boolean completion = containingFile.getOriginalFile() != containingFile;
if (completion) {
return processAllMxmlAndFxgFiles(scope, project, filesProcessor, null);
} else {
if (packageQualifierText != null && packageQualifierText.length() > 0) {
if (!processMxmlAndFxgFilesInPackage(scope, project, packageQualifierText, filesProcessor))
return false;
}
return processMxmlAndFxgFilesInPackage(scope, project, "", filesProcessor);
}
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class ActionScriptSmartCompletionContributor method getEventsMap.
public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
if (clazzToProcess == null)
return Collections.emptyMap();
final Map<String, String> eventsMap = new THashMap<>();
class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {
public EventsDataCollector() {
super(null);
setToProcessHierarchy(true);
setToProcessMembers(false);
setTypeContext(true);
setLocalResolve(true);
}
@Override
public boolean process(@NotNull final JSAttribute jsAttribute) {
if ("Event".equals(jsAttribute.getName())) {
final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
if (eventAttr != null && typeAttr != null) {
final String simpleValue = eventAttr.getSimpleValue();
if (simpleValue != null) {
eventsMap.put(simpleValue, typeAttr.getSimpleValue());
}
}
}
return true;
}
@Override
public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
return true;
}
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof JSClass) {
ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
}
return true;
}
}
final EventsDataCollector eventsDataCollector = new EventsDataCollector();
if (clazzToProcess instanceof XmlBackedJSClassImpl) {
XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
final XmlDocument xmlDocument = file.getDocument();
final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {
@Override
protected void process(JSFile file) {
for (PsiElement element : file.getChildren()) {
if (element instanceof JSAttributeList) {
ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
}
}
}
};
for (XmlTag tag : tags) {
JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
}
}
}
clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
return eventsMap;
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class FlexTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
List<AbstractTreeNode> result = new ArrayList<>();
if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
JSQualifiedNamedElement parentElement = getElement(parent);
if (parentElement != null) {
JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
if (structureViewChild instanceof JSStructureViewElement) {
PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
} else {
result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
}
}
}
}
} else {
for (final AbstractTreeNode child : children) {
Object o = child.getValue();
if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
continue;
}
result.add(child);
}
}
return result;
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class FlashUmlDataModel method createEdge.
@Override
@Nullable
public DiagramEdge<Object> createEdge(@NotNull final DiagramNode<Object> from, @NotNull final DiagramNode<Object> to) {
final JSClass fromClass = (JSClass) from.getIdentifyingElement();
final JSClass toClass = (JSClass) to.getIdentifyingElement();
if (fromClass.isEquivalentTo(toClass)) {
return null;
}
if (toClass.isInterface()) {
if (JSPsiImplUtils.containsEquivalent(fromClass.isInterface() ? fromClass.getSuperClasses() : fromClass.getImplementedInterfaces(), toClass)) {
return null;
}
Callable<DiagramEdge<Object>> callable = () -> {
String targetQName = toClass.getQualifiedName();
JSRefactoringUtil.addToSupersList(fromClass, targetQName, true);
if (targetQName.contains(".") && !(fromClass instanceof XmlBackedJSClassImpl)) {
List<FormatFixer> formatters = new ArrayList<>();
formatters.add(ImportUtils.insertImportStatements(fromClass, Collections.singletonList(targetQName)));
formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
FormatFixer.fixAll(formatters);
}
return addEdgeAndRefresh(from, to, fromClass.isInterface() ? FlashUmlRelationship.GENERALIZATION : FlashUmlRelationship.INTERFACE_GENERALIZATION);
};
String commandName = FlexBundle.message(fromClass.isInterface() ? "create.extends.relationship.command.name" : "create.implements.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
} else {
if (fromClass.isInterface()) {
return null;
} else if (fromClass instanceof XmlBackedJSClassImpl) {
JSClass[] superClasses = fromClass.getSuperClasses();
if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
return null;
}
if (superClasses.length > 0) {
// if base component is not resolved, replace it silently
final JSClass currentParent = superClasses[0];
if (Messages.showYesNoDialog(FlexBundle.message("replace.base.component.prompt", currentParent.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
return null;
}
}
Callable<DiagramEdge<Object>> callable = () -> {
NewFlexComponentAction.setParentComponent((MxmlJSClass) fromClass, toClass.getQualifiedName());
return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
};
String commandName = FlexBundle.message("create.extends.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
} else {
final JSClass[] superClasses = fromClass.getSuperClasses();
if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
return null;
}
if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
// if base class is not resolved, replace it silently
final JSClass currentParent = superClasses[0];
if (Messages.showYesNoDialog(FlexBundle.message("replace.base.class.prompt", currentParent.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
return null;
}
}
Callable<DiagramEdge<Object>> callable = () -> {
List<FormatFixer> formatters = new ArrayList<>();
boolean optimize = false;
if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
JSRefactoringUtil.removeFromReferenceList(fromClass.getExtendsList(), superClasses[0], formatters);
optimize = needsImport(fromClass, superClasses[0]);
}
JSRefactoringUtil.addToSupersList(fromClass, toClass.getQualifiedName(), false);
if (needsImport(fromClass, toClass)) {
formatters.add(ImportUtils.insertImportStatements(fromClass, Collections.singletonList(toClass.getQualifiedName())));
optimize = true;
}
if (optimize) {
formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
}
FormatFixer.fixAll(formatters);
return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
};
String commandName = FlexBundle.message("create.extends.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
}
}
}
use of com.intellij.lang.javascript.flex.XmlBackedJSClassImpl in project intellij-plugins by JetBrains.
the class MyImplicitUsageProvider method isImplicitUsage.
@Override
public boolean isImplicitUsage(PsiElement element) {
if (!(element instanceof JSFunction)) {
return false;
}
final JSFunction method = (JSFunction) element;
final String methodName = method.getName();
if (methodName == null || !Character.isUpperCase(methodName.charAt(0)) || !(method.getParent() instanceof JSClass) || method.getParent() instanceof XmlBackedJSClassImpl) {
return false;
}
final JSClass clazz = (JSClass) method.getParent();
if (!ActionScriptClassResolver.isParentClass(clazz, "com.intellij.flex.uiDesigner.TestCase")) {
return false;
}
final JSAttributeList attributeList = method.getAttributeList();
if (attributeList == null || attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC) {
return false;
}
final VirtualFile projectBaseDir = element.getProject().getBaseDir();
if (projectBaseDir == null) {
return false;
}
File testSourcePath = new File(projectBaseDir.getPath(), RELATIVE_TEST_DATA_PATH);
if (!testSourcePath.exists()) {
testSourcePath = new File(projectBaseDir.getPath(), "flex/tools/flex-ui-designer/" + RELATIVE_TEST_DATA_PATH);
assert testSourcePath.exists();
}
final JSAttributeList classAttributeList = clazz.getAttributeList();
if (classAttributeList != null) {
final JSAttribute testAnnotation = classAttributeList.findAttributeByName("Test");
if (testAnnotation == null) {
return false;
}
return new File(testSourcePath, testAnnotation.getValueByName("dir").getSimpleValue() + File.separatorChar + methodName + ".mxml").exists();
}
return false;
}
Aggregations