use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class HardwiredNamespacePrefix method createVisitor.
protected Visitor createVisitor(final InspectionManager manager, final boolean isOnTheFly) {
return new Visitor(manager, isOnTheFly) {
protected void checkExpression(XPathExpression expression) {
if (!(expression instanceof XPathBinaryExpression)) {
return;
}
final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
if (expr.getOperator() == XPathTokenTypes.EQ) {
final XPathExpression lop = expr.getLOperand();
final XPathExpression rop = expr.getROperand();
if (isNameComparison(lop, rop)) {
assert rop != null;
final ProblemDescriptor p = manager.createProblemDescriptor(rop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
addProblem(p);
} else if (isNameComparison(rop, lop)) {
assert lop != null;
final ProblemDescriptor p = manager.createProblemDescriptor(lop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
addProblem(p);
} else if (isNameFunctionCall(lop)) {
// TODO
} else if (isNameFunctionCall(rop)) {
// TODO
}
}
}
};
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class AbstractFix method createQuickFix.
@Nullable
public LocalQuickFix createQuickFix(boolean isOnTheFly) {
final boolean requiresEditor = requiresEditor();
if (requiresEditor && !isOnTheFly)
return null;
return new LocalQuickFix() {
@NotNull
public String getName() {
return AbstractFix.this.getText();
}
@NotNull
public String getFamilyName() {
return AbstractFix.this.getFamilyName();
}
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
Editor editor;
if (requiresEditor) {
final DataContext dataContext = DataManager.getInstance().getDataContext();
editor = CommonDataKeys.EDITOR.getData(dataContext);
if (editor == null) {
if ((editor = FileEditorManager.getInstance(project).getSelectedTextEditor()) == null) {
return;
}
}
} else {
editor = null;
}
final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
if (!isAvailable(project, editor, psiFile)) {
return;
}
invoke(project, editor, psiFile);
}
};
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class BuildoutUnresolvedPartInspection method checkFile.
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
List<ProblemDescriptor> problems = Lists.newArrayList();
if (file.getFileType().equals(BuildoutCfgFileType.INSTANCE)) {
Visitor visitor = new Visitor();
file.accept(visitor);
for (BuildoutPartReference ref : visitor.getUnresolvedParts()) {
ProblemDescriptor d = manager.createProblemDescriptor(ref.getElement(), ref.getRangeInElement(), PyBundle.message("buildout.unresolved.part.inspection.msg"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
problems.add(d);
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class PyRemoveParameterQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement parameter = descriptor.getPsiElement();
assert parameter instanceof PyParameter;
final PyFunction function = PsiTreeUtil.getParentOfType(parameter, PyFunction.class);
if (function != null) {
final PyResolveContext resolveContext = PyResolveContext.noImplicits();
StreamEx.of(PyRefactoringUtil.findUsages(function, false)).map(UsageInfo::getElement).nonNull().map(PsiElement::getParent).select(PyCallExpression.class).flatMap(callExpression -> callExpression.multiMapArguments(resolveContext).stream()).flatMap(mapping -> mapping.getMappedParameters().entrySet().stream()).filter(entry -> entry.getValue() == parameter).forEach(entry -> entry.getKey().delete());
final PyStringLiteralExpression docStringExpression = function.getDocStringExpression();
final String parameterName = ((PyParameter) parameter).getName();
if (docStringExpression != null && parameterName != null) {
PyDocstringGenerator.forDocStringOwner(function).withoutParam(parameterName).buildAndInsert();
}
}
parameter.delete();
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class InspectionDescriptionNotFoundInspection method checkClass.
@Override
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
final Project project = psiClass.getProject();
final PsiIdentifier nameIdentifier = psiClass.getNameIdentifier();
final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(psiClass))
return null;
final PsiClass base = JavaPsiFacade.getInstance(project).findClass(INSPECTION_PROFILE_ENTRY, psiClass.getResolveScope());
if (base == null || !psiClass.isInheritor(base, true) || isPathMethodsAreOverridden(psiClass))
return null;
final InspectionDescriptionInfo info = InspectionDescriptionInfo.create(module, psiClass);
if (!info.isValid() || info.hasDescriptionFile())
return null;
final PsiElement problemElement = getProblemElement(psiClass, info.getShortNameMethod());
final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(problemElement == null ? nameIdentifier : problemElement, "Inspection does not have a description", isOnTheFly, new LocalQuickFix[] { new CreateHtmlDescriptionFix(info.getFilename(), module, DescriptionType.INSPECTION) }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
Aggregations