Search in sources :

Example 71 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlashRunConfiguration method containsClass.

public static boolean containsClass(final Module module, final PsiDirectory directory, final String className) {
    final String packageName = DirectoryIndex.getInstance(module.getProject()).getPackageName(directory.getVirtualFile());
    if (!StringUtil.getPackageName(className).equals(packageName))
        return false;
    final PsiElement psiElement = ActionScriptClassResolver.findClassByQNameStatic(className, GlobalSearchScope.moduleScope(module));
    return psiElement instanceof JSClass && directory.equals(psiElement.getContainingFile().getParent());
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 72 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class ModuleInfoUtil method collectApplicationLocalStyle.

@Nullable
private static List<LocalStyleHolder> collectApplicationLocalStyle(final Module module, String flexSdkVersion, final ProblemsHolder problemsHolder, StringWriter stringWriter, ProjectComponentReferenceCounter projectComponentReferenceCounter, final AssetCounter assetCounter) {
    GlobalSearchScope moduleWithDependenciesAndLibrariesScope = module.getModuleWithDependenciesAndLibrariesScope(false);
    final List<JSClass> holders = new ArrayList<>(2);
    if (flexSdkVersion.charAt(0) > '3') {
        JSClass clazz = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.SPARK_APPLICATION, moduleWithDependenciesAndLibrariesScope));
        // it is not legal case, but user can use patched/modified Flex SDK
        if (clazz != null) {
            holders.add(clazz);
        }
    }
    JSClass mxApplicationClass = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.MX_APPLICATION, moduleWithDependenciesAndLibrariesScope));
    // if null, mx.swc is not added to module dependencies
    if (mxApplicationClass != null) {
        holders.add(mxApplicationClass);
    }
    if (holders.isEmpty()) {
        return null;
    }
    final StyleTagWriter styleTagWriter = new StyleTagWriter(new LocalCssWriter(stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
    final List<LocalStyleHolder> result = new ArrayList<>();
    final Processor<JSClass> processor = jsClass -> {
        PsiFile psiFile = jsClass.getNavigationElement().getContainingFile();
        if (!(psiFile instanceof XmlFile)) {
            return true;
        }
        XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
        if (rootTag == null) {
            return true;
        }
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        problemsHolder.setCurrentFile(virtualFile);
        try {
            for (final XmlTag subTag : rootTag.getSubTags()) {
                if (subTag.getNamespace().equals(JavaScriptSupportLoader.MXML_URI3) && subTag.getLocalName().equals(FlexPredefinedTagNames.STYLE)) {
                    try {
                        LocalStyleHolder localStyleHolder = styleTagWriter.write(subTag, module, virtualFile);
                        if (localStyleHolder != null) {
                            result.add(localStyleHolder);
                        }
                    } catch (InvalidPropertyException e) {
                        problemsHolder.add(e);
                    }
                }
            }
        } finally {
            problemsHolder.setCurrentFile(null);
        }
        return true;
    };
    final GlobalSearchScope moduleScope = module.getModuleScope(false);
    for (JSClass holder : holders) {
        JSClassSearch.searchClassInheritors(holder, true, moduleScope).forEach(processor);
    }
    return result;
}
Also used : StringWriter(com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) Application(com.intellij.openapi.application.Application) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) FlexPredefinedTagNames(com.intellij.javascript.flex.FlexPredefinedTagNames) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FlexCommonTypeNames(com.intellij.javascript.flex.mxml.FlexCommonTypeNames) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) JSClassSearch(com.intellij.lang.javascript.search.JSClassSearch) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) AccessToken(com.intellij.openapi.application.AccessToken) MxmlUtil(com.intellij.flex.uiDesigner.mxml.MxmlUtil) Semaphore(com.intellij.util.concurrency.Semaphore) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) Project(com.intellij.openapi.project.Project) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Module(com.intellij.openapi.module.Module) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StylesheetFile(com.intellij.psi.css.StylesheetFile) XmlTag(com.intellij.psi.xml.XmlTag) DumbService(com.intellij.openapi.project.DumbService) XmlAttribute(com.intellij.psi.xml.XmlAttribute) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Library(com.intellij.flex.uiDesigner.libraries.Library) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Collections(java.util.Collections) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 73 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class ResolveExternalInlineStyleSourceAction method find.

public Navigatable find() {
    JSClass classElement = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(parentFqn, scope));
    assert classElement != null;
    XmlTag rootTag = ((XmlFile) classElement.getNavigationElement().getContainingFile()).getRootTag();
    assert rootTag != null && rootTag.getDescriptor() != null && rootTag.getDescriptor() instanceof ClassBackedElementDescriptor;
    return find(rootTag, true);
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlTag(com.intellij.psi.xml.XmlTag)

Example 74 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class SocketInputHandlerImpl method goToClass.

private void goToClass() throws IOException {
    final Module module = readModule();
    final String className = reader.readUTF();
    ApplicationManager.getApplication().invokeLater(() -> {
        JSClass classElement = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(className, module.getModuleWithDependenciesAndLibrariesScope(false)));
        classElement.navigate(true);
        ProjectUtil.focusProjectWindow(classElement.getProject(), true);
    });
}
Also used : Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 75 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7