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;
}
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);
}
}
}
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;
}
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);
}
});
}
}
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");
}
}
Aggregations