use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class ProblemDescriptionNode method calculatePresentableName.
@NotNull
@Override
protected String calculatePresentableName() {
CommonProblemDescriptor descriptor = getDescriptor();
if (descriptor == null)
return "";
PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : null;
return XmlStringUtil.stripHtml(ProblemDescriptorUtil.renderDescriptionMessage(descriptor, element, TRIM_AT_TREE_END));
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class SuppressableInspectionTreeNode method getSuppressContent.
@NotNull
public final Pair<PsiElement, CommonProblemDescriptor> getSuppressContent() {
RefEntity refElement = getElement();
CommonProblemDescriptor descriptor = getDescriptor();
PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
return Pair.create(element, descriptor);
}
use of com.intellij.codeInspection.ProblemDescriptor 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.ProblemDescriptor in project intellij-community by JetBrains.
the class GroovyRangeTypeCheckInspection method buildFix.
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
final GrRangeExpression range = (GrRangeExpression) location;
final PsiType type = range.getType();
final List<GroovyFix> fixes = new ArrayList<>(3);
if (type instanceof GrRangeType) {
PsiType iterationType = ((GrRangeType) type).getIterationType();
if (!(iterationType instanceof PsiClassType))
return null;
final PsiClass psiClass = ((PsiClassType) iterationType).resolve();
if (!(psiClass instanceof GrTypeDefinition))
return null;
final GroovyResolveResult[] nexts = ResolveUtil.getMethodCandidates(iterationType, "next", range);
final GroovyResolveResult[] previouses = ResolveUtil.getMethodCandidates(iterationType, "previous", range);
final GroovyResolveResult[] compareTos = ResolveUtil.getMethodCandidates(iterationType, "compareTo", range, iterationType);
if (countImplementations(psiClass, nexts) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddMethodFix("next", (GrTypeDefinition) psiClass));
}
if (countImplementations(psiClass, previouses) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddMethodFix("previous", (GrTypeDefinition) psiClass));
}
if (!InheritanceUtil.isInheritor(iterationType, CommonClassNames.JAVA_LANG_COMPARABLE) || countImplementations(psiClass, compareTos) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddClassToExtendsFix((GrTypeDefinition) psiClass, CommonClassNames.JAVA_LANG_COMPARABLE));
}
return new GroovyFix() {
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
for (GroovyFix fix : fixes) {
fix.applyFix(project, descriptor);
}
}
@NotNull
@Override
public String getName() {
return GroovyInspectionBundle.message("fix.class", psiClass.getName());
}
@Nls
@NotNull
@Override
public String getFamilyName() {
return "Fix range class";
}
};
}
return null;
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class UnusedMessageFormatParameterInspection method checkFile.
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof PropertiesFile))
return null;
PropertiesFile propertiesFile = (PropertiesFile) file;
final List<IProperty> properties = propertiesFile.getProperties();
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
for (IProperty property : properties) {
@NonNls String name = property.getName();
if (name != null) {
if (name.startsWith("log4j"))
continue;
if (name.startsWith(REGEXP + ".") || name.endsWith("." + REGEXP))
continue;
}
String value = property.getValue();
Set<Integer> parameters = new HashSet<>();
if (value != null) {
int index = value.indexOf('{');
while (index != -1) {
value = value.substring(index + 1);
final int comma = value.indexOf(',');
final int brace = value.indexOf('}');
//misformatted string
if (brace == -1)
break;
if (comma == -1) {
index = brace;
} else {
index = Math.min(comma, brace);
}
try {
parameters.add(new Integer(value.substring(0, index)));
} catch (NumberFormatException e) {
break;
}
index = value.indexOf('{');
}
for (Integer integer : parameters) {
for (int i = 0; i < integer.intValue(); i++) {
if (!parameters.contains(new Integer(i))) {
ASTNode[] nodes = property.getPsiElement().getNode().getChildren(null);
PsiElement valElement = nodes.length < 3 ? property.getPsiElement() : nodes[2].getPsi();
final String message = PropertiesBundle.message("unused.message.format.parameter.problem.descriptor", integer.toString(), Integer.toString(i));
final String propertyKey = property.getKey();
final LocalQuickFix[] fixes = isOnTheFly ? new LocalQuickFix[] { new RenameElementFix(((Property) property), propertyKey == null ? REGEXP : propertyKey + "." + REGEXP) } : null;
problemDescriptors.add(manager.createProblemDescriptor(valElement, message, isOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
break;
}
}
}
}
}
return problemDescriptors.isEmpty() ? null : problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
Aggregations