Search in sources :

Example 6 with JSPackageStatement

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

the class CreateJSSubclassIntention method isAvailable.

public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
    final PsiFile psiFile = element.getContainingFile();
    if (!(psiFile instanceof JSFile) || InjectedLanguageManager.getInstance(project).getInjectionHost(psiFile) != null || !psiFile.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4)) {
        return false;
    }
    final JSClass jsClass = PsiTreeUtil.getParentOfType(element, JSClass.class);
    if (jsClass == null || !(jsClass.getParent() instanceof JSPackageStatement)) {
        return false;
    }
    if (!jsClass.isInterface()) {
        final JSAttributeList attributeList = jsClass.getAttributeList();
        if (attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.FINAL)) {
            return false;
        }
    }
    final TextRange declarationRange = getClassDeclarationTextRange(jsClass);
    final int offset = editor.getCaretModel().getOffset();
    if (offset < declarationRange.getStartOffset() || offset > declarationRange.getEndOffset()) {
        // not the same as TextRange.contains()
        return false;
    }
    setText(getTitle(jsClass));
    return true;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) JSFile(com.intellij.lang.javascript.psi.JSFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 7 with JSPackageStatement

use of com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement 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

JSPackageStatement (com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement)7 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)6 PsiElement (com.intellij.psi.PsiElement)5 PsiDirectory (com.intellij.psi.PsiDirectory)3 JSFile (com.intellij.lang.javascript.psi.JSFile)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)2 JSPackage (com.intellij.lang.javascript.psi.ecmal4.JSPackage)2 Module (com.intellij.openapi.module.Module)2 PsiDirectoryContainer (com.intellij.psi.PsiDirectoryContainer)2 NotNull (org.jetbrains.annotations.NotNull)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 ASTNode (com.intellij.lang.ASTNode)1 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)1 JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSE4XNamespaceReference (com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference)1 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)1 JSImportStatement (com.intellij.lang.javascript.psi.ecmal4.JSImportStatement)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1 JSReferenceListMember (com.intellij.lang.javascript.psi.ecmal4.JSReferenceListMember)1