use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class TypeCustomizerInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitFile(@NotNull GroovyFileBase file) {
CompilerConfiguration configuration = CompilerConfiguration.getInstance(file.getProject());
if (configuration != null && !configuration.isResourceFile(file.getVirtualFile()) && fileSeemsToBeTypeCustomizer(file)) {
final LocalQuickFix[] fixes = { new AddToResourceFix(file) };
final String message = GroovyInspectionBundle.message("type.customizer.is.not.marked.as.a.resource.file");
registerError(file, message, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class GroovyStaticTypeCheckVisitor method registerError.
@Override
protected void registerError(@NotNull final PsiElement location, @NotNull final String description, @Nullable final LocalQuickFix[] fixes, final ProblemHighlightType highlightType) {
if (highlightType != ProblemHighlightType.GENERIC_ERROR)
return;
final List<IntentionAction> intentions = ContainerUtil.newArrayList();
if (fixes != null) {
for (final LocalQuickFix fix : fixes) {
intentions.add(new IntentionAction() {
@NotNull
@Override
public String getText() {
return fix.getName();
}
@NotNull
@Override
public String getFamilyName() {
return fix.getFamilyName();
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return true;
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final InspectionManager manager = InspectionManager.getInstance(project);
final ProblemDescriptor descriptor = manager.createProblemDescriptor(location, description, fixes, highlightType, fixes.length == 1, false);
fix.applyFix(project, descriptor);
}
@Override
public boolean startInWriteAction() {
return true;
}
});
}
}
registerError(location, description, intentions.toArray(new IntentionAction[intentions.size()]), highlightType);
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class TemplateInvocationInspection method checkTemplateInvocation.
private static void checkTemplateInvocation(XsltTemplateInvocation call, ProblemsHolder holder, boolean onTheFly) {
final XsltWithParam[] arguments = call.getArguments();
final Map<String, XsltWithParam> argNames = new HashMap<>();
for (XsltWithParam arg : arguments) {
final XmlAttribute attr = arg.getNameAttribute();
if (attr != null) {
final String name = attr.getValue();
if (argNames.containsKey(name)) {
final PsiElement token = arg.getNameIdentifier();
assert token != null;
holder.registerProblem(token, "Duplicate Argument '" + name + "'");
}
argNames.put(name, arg);
}
}
if (call instanceof XsltCallTemplate) {
final XsltCallTemplate ct = ((XsltCallTemplate) call);
final PsiElement nameToken = ct.getNameIdentifier();
final XsltTemplate template = ct.getTemplate();
if (template != null) {
if (nameToken != null) {
final XsltParameter[] parameters = template.getParameters();
for (XsltParameter parameter : parameters) {
if (!argNames.containsKey(parameter.getName()) && !parameter.hasDefault()) {
final LocalQuickFix fix = new AddWithParamFix(parameter, call.getTag()).createQuickFix(onTheFly);
holder.registerProblem(nameToken, "Missing template parameter: " + parameter.getName(), AbstractFix.createFixes(fix));
}
}
}
for (String s : argNames.keySet()) {
final XmlAttribute argAttribute = argNames.get(s).getNameAttribute();
assert argAttribute != null;
final XmlAttributeValue valueElement = argAttribute.getValueElement();
final PsiElement valueToken = XsltSupport.getAttValueToken(argAttribute);
if (valueToken != null && s.trim().length() > 0) {
if (template.getParameter(s) == null) {
final LocalQuickFix fix1 = new AddParameterFix(s, template).createQuickFix(onTheFly);
final LocalQuickFix fix2 = new RemoveParamFix(argNames.get(s).getTag(), s).createQuickFix(onTheFly);
holder.registerProblem(valueToken, "Undeclared template parameter: " + s, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, AbstractFix.createFixes(fix1, fix2));
}
} else if (valueElement != null) {
holder.registerProblem(valueElement, "Parameter name expected");
}
}
}
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class VariableShadowingInspection method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (!(holder.getFile() instanceof XmlFile))
return PsiElementVisitor.EMPTY_VISITOR;
return new XmlElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
final XmlAttribute nameAttr = tag.getAttribute("name", null);
if (nameAttr == null || PsiTreeUtil.hasErrorElements(nameAttr))
return;
if (XsltSupport.isVariableOrParam(tag)) {
final XmlTag shadowedVariable = DeclarationChecker.getInstance((XmlFile) tag.getContainingFile()).getShadowedVariable(tag);
if (shadowedVariable != null) {
final String innerKind = XsltSupport.isParam(tag) ? "Parameter" : "Variable";
final String outerKind = XsltSupport.isParam(shadowedVariable) ? "parameter" : "variable";
final LocalQuickFix fix1 = new RenameVariableFix(tag, "local").createQuickFix(isOnTheFly);
final LocalQuickFix fix2 = new RenameVariableFix(shadowedVariable, "outer").createQuickFix(isOnTheFly);
final XmlAttribute name = tag.getAttribute("name");
assert name != null;
final PsiElement token = XsltSupport.getAttValueToken(name);
assert token != null;
holder.registerProblem(token, innerKind + " '" + name.getValue() + "' shadows " + outerKind, AbstractFix.createFixes(fix1, fix2));
}
}
}
};
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class BaseInspectionVisitor method registerMethodCallError.
protected void registerMethodCallError(GrMethodCall method, Object... args) {
if (method == null) {
return;
}
final LocalQuickFix[] fixes = createFixes(method);
final String description = StringUtil.notNullize(inspection.buildErrorString(args));
final GrExpression invoked = method.getInvokedExpression();
final PsiElement nameElement = ((GrReferenceExpression) invoked).getReferenceNameElement();
assert nameElement != null;
registerError(nameElement, description, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
Aggregations