Search in sources :

Example 26 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method getQuickFixesForUnknownSimpleSelector.

@NotNull
@Override
public LocalQuickFix[] getQuickFixesForUnknownSimpleSelector(@NotNull String selectorName, @NotNull PsiElement context, boolean isOnTheFly) {
    if (!isOnTheFly) {
        return LocalQuickFix.EMPTY_ARRAY;
    }
    final VirtualFile vFile = checkForQuickFixAndGetVFile(context);
    if (vFile == null) {
        return LocalQuickFix.EMPTY_ARRAY;
    }
    final CssDialect dialect = CssDialectMappings.getInstance(context.getProject()).getMapping(vFile);
    if (dialect == CssDialect.CLASSIC) {
        if (isPossibleSelector(selectorName, context)) {
            return new LocalQuickFix[] { new SwitchToCssDialectQuickFix(FlexCSSDialect.getInstance()) };
        }
    } else {
        final CssElementDescriptorProviderImpl classicCssDescriptorProvider = CssElementDescriptorProvider.EP_NAME.findExtension(CssElementDescriptorProviderImpl.class);
        if (classicCssDescriptorProvider != null && classicCssDescriptorProvider.isPossibleSelector(selectorName, context)) {
            return new LocalQuickFix[] { new SwitchToCssDialectQuickFix(CssDialect.CLASSIC) };
        }
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CssDialect(com.intellij.lang.css.CssDialect) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CssElementDescriptorProviderImpl(com.intellij.psi.css.impl.util.scheme.CssElementDescriptorProviderImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-plugins by JetBrains.

the class FlexUnitClassInProductSourceInspection method visitPotentialTestClass.

protected void visitPotentialTestClass(JSClass aClass, @NotNull ProblemsHolder holder, FlexUnitSupport support) {
    final VirtualFile file = aClass.getContainingFile().getVirtualFile();
    if (file == null) {
        return;
    }
    if (!ProjectRootManager.getInstance(aClass.getProject()).getFileIndex().isInTestSourceContent(file)) {
        final PsiElement nameIdentifier = aClass.getNameIdentifier();
        if (nameIdentifier != null) {
            final LocalQuickFix[] fixes = holder.isOnTheFly() ? new LocalQuickFix[] { new MoveClassFix() } : LocalQuickFix.EMPTY_ARRAY;
            holder.registerProblem(nameIdentifier, FlexBundle.message("flexunit.inspection.testclassinproductsource.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fixes);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiElement(com.intellij.psi.PsiElement)

Example 28 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-plugins by JetBrains.

the class ActionScriptAnnotatingVisitor method getPreferredQuickFixForUnresolvedRef.

@Nullable
@Override
protected LocalQuickFix getPreferredQuickFixForUnresolvedRef(final PsiElement nameIdentifier) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(nameIdentifier);
    if (module == null || ModuleType.get(module) != FlexModuleType.getInstance())
        return null;
    final String conditionalCompilerDefinitionName = getPotentialConditionalCompilerDefinitionName(nameIdentifier);
    if (conditionalCompilerDefinitionName != null) {
        return new DeclareConditionalCompilerDefinitionFix(module, conditionalCompilerDefinitionName);
    }
    final JSCallExpression callExpression = PsiTreeUtil.getParentOfType(nameIdentifier, JSCallExpression.class);
    if (callExpression == null)
        return null;
    if (JSResolveUtil.isEventListenerCall(callExpression)) {
        final JSExpression[] params = callExpression.getArguments();
        if (params.length >= 2 && PsiTreeUtil.isAncestor(params[1], nameIdentifier, true)) {
            return new CreateJSEventMethod(nameIdentifier.getText(), () -> {
                PsiElement responsibleElement = null;
                if (params[0] instanceof JSReferenceExpression) {
                    responsibleElement = ((JSReferenceExpression) params[0]).getQualifier();
                }
                return responsibleElement == null ? FlexCommonTypeNames.FLASH_EVENT_FQN : responsibleElement.getText();
            });
        }
    } else if (needsFlexMobileViewAsFirstArgument(callExpression)) {
        final JSExpression[] params = callExpression.getArguments();
        if (params.length >= 1 && PsiTreeUtil.isAncestor(params[0], nameIdentifier, true)) {
            final String contextPackage = JSResolveUtil.getPackageNameFromPlace(callExpression);
            final String fqn = StringUtil.getQualifiedName(contextPackage, nameIdentifier.getText());
            final CreateFlexMobileViewIntentionAndFix fix = new CreateFlexMobileViewIntentionAndFix(fqn, nameIdentifier, true);
            fix.setCreatedClassFqnConsumer(fqn1 -> {
                final String packageName = StringUtil.getPackageName(fqn1);
                if (StringUtil.isNotEmpty(packageName) && !packageName.equals(contextPackage)) {
                    ImportUtils.doImport(nameIdentifier, fqn1, true);
                }
            });
            return fix;
        }
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSPackageStatementImpl(com.intellij.lang.javascript.psi.ecmal4.impl.JSPackageStatementImpl) NUMBER_CLASS_NAME(com.intellij.lang.javascript.psi.JSCommonTypeNames.NUMBER_CLASS_NAME) THashSet(gnu.trove.THashSet) com.intellij.lang.javascript.flex(com.intellij.lang.javascript.flex) AnnotationHolder(com.intellij.lang.annotation.AnnotationHolder) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) JSFormatUtil(com.intellij.lang.javascript.ui.JSFormatUtil) RenameFileFix(com.intellij.codeInsight.daemon.impl.quickfix.RenameFileFix) JSReadWriteAccessDetector(com.intellij.lang.javascript.findUsages.JSReadWriteAccessDetector) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) com.intellij.lang.javascript.validation(com.intellij.lang.javascript.validation) com.intellij.lang.javascript(com.intellij.lang.javascript) JSSymbolUtil(com.intellij.lang.javascript.index.JSSymbolUtil) com.intellij.lang.javascript.psi.resolve(com.intellij.lang.javascript.psi.resolve) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) IncorrectOperationException(com.intellij.util.IncorrectOperationException) JSMethodDescriptor(com.intellij.lang.javascript.refactoring.changeSignature.JSMethodDescriptor) JSE4XNamespaceReference(com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) ReadWriteAccessDetector(com.intellij.codeInsight.highlighting.ReadWriteAccessDetector) TokenSet(com.intellij.psi.tree.TokenSet) Nullable(org.jetbrains.annotations.Nullable) BOOLEAN_CLASS_NAME(com.intellij.lang.javascript.psi.JSCommonTypeNames.BOOLEAN_CLASS_NAME) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) ProblemHighlightType(com.intellij.codeInspection.ProblemHighlightType) Annotation(com.intellij.lang.annotation.Annotation) com.intellij.psi(com.intellij.psi) JSE4XFilterQueryArgumentList(com.intellij.lang.javascript.psi.e4x.JSE4XFilterQueryArgumentList) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) JSAttributeListImpl(com.intellij.lang.javascript.psi.ecmal4.impl.JSAttributeListImpl) JSFixFactory(com.intellij.lang.javascript.highlighting.JSFixFactory) JSReferenceExpressionImpl(com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) FlexCommonTypeNames(com.intellij.javascript.flex.mxml.FlexCommonTypeNames) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) XmlTagChild(com.intellij.psi.xml.XmlTagChild) com.intellij.lang.javascript.psi.types(com.intellij.lang.javascript.psi.types) RenameElementFix(com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix) ActionScriptConstructorChecker(com.intellij.lang.javascript.inspections.actionscript.fixes.ActionScriptConstructorChecker) JSTypeEvaluateManager(com.intellij.lang.javascript.index.JSTypeEvaluateManager) JSSemanticHighlightingUtil(com.intellij.lang.javascript.highlighting.JSSemanticHighlightingUtil) Project(com.intellij.openapi.project.Project) JSPackageWrapper(com.intellij.lang.javascript.psi.ecmal4.impl.JSPackageWrapper) ModuleType(com.intellij.openapi.module.ModuleType) PropertyKey(org.jetbrains.annotations.PropertyKey) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) com.intellij.lang.javascript.psi.ecmal4(com.intellij.lang.javascript.psi.ecmal4) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.lang.javascript.psi(com.intellij.lang.javascript.psi) JSStringType(com.intellij.lang.javascript.psi.types.primitives.JSStringType) JSVoidType(com.intellij.lang.javascript.psi.types.primitives.JSVoidType) Editor(com.intellij.openapi.editor.Editor) XmlText(com.intellij.psi.xml.XmlText) ASTNode(com.intellij.lang.ASTNode) com.intellij.lang.javascript.validation.fixes(com.intellij.lang.javascript.validation.fixes) Pair(com.intellij.openapi.util.Pair) JSAttributeImpl(com.intellij.lang.javascript.psi.ecmal4.impl.JSAttributeImpl) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-plugins by JetBrains.

the class JSImplicitlyInternalDeclarationInspection method process.

private static void process(final JSNamedElement node, final ProblemsHolder holder) {
    if (!DialectDetector.isActionScript(node))
        return;
    JSFunction fun = PsiTreeUtil.getParentOfType(node, JSFunction.class);
    if (fun != null)
        return;
    ASTNode nameIdentifier = node.findNameIdentifier();
    if (nameIdentifier == null)
        return;
    JSClass clazz = JSResolveUtil.getClassOfContext(node);
    if (clazz == null) {
        PsiElement parent = JSResolveUtil.findParent(node);
        if (!(parent instanceof JSPackageStatement))
            return;
    }
    JSAttributeList attributeList = ((JSAttributeListOwner) node).getAttributeList();
    JSAttributeList.AccessType accessType = attributeList != null ? attributeList.getAccessType() : null;
    if (accessType == JSAttributeList.AccessType.PACKAGE_LOCAL && attributeList.findAccessTypeElement() == null && attributeList.getNamespaceElement() == null && !JSResolveUtil.isConstructorFunction(node)) {
        holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("js.implicitly.internal.declaration.problem"), new LocalQuickFix() {

            @NotNull
            @Override
            public String getFamilyName() {
                return FlexBundle.message("js.implicitly.internal.declaration.problem.add.internal.fix");
            }

            @Override
            public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
                PsiElement anchor = descriptor.getPsiElement();
                JSChangeVisibilityUtil.setVisibility((JSAttributeListOwner) anchor.getParent(), JSAttributeList.AccessType.PACKAGE_LOCAL);
            }
        });
    }
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) ASTNode(com.intellij.lang.ASTNode) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 30 with LocalQuickFix

use of com.intellij.codeInspection.LocalQuickFix in project intellij-plugins by JetBrains.

the class ActionScriptFunctionSignatureChecker method checkConstructorCall.

@Override
public void checkConstructorCall(@NotNull JSCallExpression node, @NotNull JSClass target) {
    if (node instanceof JSNewExpression || node.getMethodExpression() instanceof JSSuperExpression) {
        final JSArgumentList argumentList = node.getArgumentList();
        final JSExpression[] expressions = argumentList != null ? argumentList.getArguments() : JSExpression.EMPTY_ARRAY;
        if (expressions.length > 0) {
            final ActionScriptCreateConstructorFix fix = ActionScriptCreateConstructorFix.createIfApplicable(node);
            registerProblem(node, JSBundle.message("javascript.invalid.number.of.parameters", "0"), fix != null ? new LocalQuickFix[] { fix } : LocalQuickFix.EMPTY_ARRAY);
        }
    } else {
        reportProblemIfNotExpectedCountOfParameters(node, 1, "one");
    }
}
Also used : ActionScriptCreateConstructorFix(com.intellij.lang.javascript.validation.fixes.ActionScriptCreateConstructorFix) JSSuperExpression(com.intellij.lang.javascript.psi.ecmal4.JSSuperExpression) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)59 NotNull (org.jetbrains.annotations.NotNull)20 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)11 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)10 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)10 ASTNode (com.intellij.lang.ASTNode)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 XmlTag (com.intellij.psi.xml.XmlTag)6 PsiFile (com.intellij.psi.PsiFile)5 PsiReference (com.intellij.psi.PsiReference)5 ArrayList (java.util.ArrayList)5 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)4 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)3 QuickFixWrapper (com.intellij.codeInspection.ex.QuickFixWrapper)3 Pair (com.intellij.openapi.util.Pair)3 TextRange (com.intellij.openapi.util.TextRange)3 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3