Search in sources :

Example 6 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-plugins by JetBrains.

the class FlexRefactoringListenerProvider method getListener.

@Override
@Nullable
public RefactoringElementListener getListener(final PsiElement element) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (element instanceof PsiDirectoryContainer || element instanceof JSPackage || element instanceof JSPackageStatement) {
        final String packageName = getPackageName(element);
        return StringUtil.isEmpty(packageName) ? null : new PackageRefactoringListener(element.getProject(), module, packageName);
    }
    if (module == null || ModuleType.get(module) != FlexModuleType.getInstance())
        return null;
    final JSClass jsClass = getJSClass(element);
    if (jsClass != null) {
        return new JSClassRefactoringListener(module, jsClass.getQualifiedName());
    }
    final VirtualFile file = element instanceof PsiFile ? element.getContainingFile().getVirtualFile() : null;
    if (file != null) {
        if ("css".equalsIgnoreCase(file.getExtension())) {
            return new CssFileRefactoringListener(module, file.getPath());
        } else if ("xml".equalsIgnoreCase(file.getExtension())) {
            return new XmlFileRefactoringListener(module, file.getPath());
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-plugins by JetBrains.

the class FlexUnitRunConfiguration method getRefactoringElementListener.

@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
    final FlexUnitRunnerParameters params = getRunnerParameters();
    final Module module = ModuleManager.getInstance(getProject()).findModuleByName(params.getModuleName());
    if (!(element instanceof PsiDirectoryContainer) && !(element instanceof JSPackage) && !(element instanceof JSPackageStatement) && (module == null || !module.equals(ModuleUtilCore.findModuleForPsiElement(element)))) {
        return null;
    }
    switch(params.getScope()) {
        case Method:
            if (element instanceof JSFunction) {
                final PsiElement parent = element.getParent();
                if (parent instanceof JSClass && Comparing.strEqual(((JSClass) parent).getQualifiedName(), params.getClassName()) && Comparing.strEqual(((JSFunction) element).getName(), params.getMethodName())) {
                    return new FlexRunConfigRefactoringListener.JSFunctionRefactoringListener(this);
                }
            }
        // no break here!
        case Class:
            if (element instanceof PsiDirectory && FlashRunConfiguration.containsClass(module, ((PsiDirectory) element), params.getClassName())) {
                return new FlexRunConfigRefactoringListener.PsiDirectoryRefactoringListener(this);
            }
            final JSClass jsClass = FlexRefactoringListenerProvider.getJSClass(element);
            if (jsClass != null && Comparing.strEqual(jsClass.getQualifiedName(), params.getClassName())) {
                return new FlexRunConfigRefactoringListener.JSClassRefactoringListener(this);
            }
        // no break here!
        case Package:
            final String currentPackage = params.getScope() == FlexUnitRunnerParameters.Scope.Package ? params.getPackageName() : StringUtil.getPackageName(params.getClassName());
            if ((element instanceof PsiDirectoryContainer || element instanceof JSPackage || element instanceof JSPackageStatement) && Comparing.strEqual(FlexRefactoringListenerProvider.getPackageName(element), currentPackage)) {
                return new FlexRunConfigRefactoringListener.PackageRefactoringListener(this);
            }
    }
    return null;
}
Also used : JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) JSPackage(com.intellij.lang.javascript.psi.ecmal4.JSPackage) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiDirectoryContainer (com.intellij.psi.PsiDirectoryContainer)7 PsiDirectory (com.intellij.psi.PsiDirectory)5 PsiElement (com.intellij.psi.PsiElement)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Module (com.intellij.openapi.module.Module)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 JSPackage (com.intellij.lang.javascript.psi.ecmal4.JSPackage)2 JSPackageStatement (com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement)2 PsiFile (com.intellij.psi.PsiFile)2 Nullable (org.jetbrains.annotations.Nullable)2 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)1 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)1 FactoryMap (com.intellij.util.containers.FactoryMap)1 HashMap (com.intellij.util.containers.HashMap)1 Map (java.util.Map)1