use of com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix 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()]);
}
use of com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method checkNamedObjectIsInCorrespondingFile.
private void checkNamedObjectIsInCorrespondingFile(final JSNamedElement aClass) {
final PsiFile containingFile = aClass.getContainingFile();
if (containingFile.getContext() != null)
return;
final VirtualFile file = containingFile.getVirtualFile();
if (file != null && !file.getNameWithoutExtension().equals(aClass.getName()) && ProjectRootManager.getInstance(containingFile.getProject()).getFileIndex().getSourceRootForFile(file) != null) {
final ASTNode node = aClass.findNameIdentifier();
if (node != null) {
final String name = aClass.getName();
String nameWithExtension = name + "." + file.getExtension();
final String message = JSBundle.message(aClass instanceof JSClass ? "javascript.validation.message.class.should.be.in.file" : aClass instanceof JSNamespaceDeclaration ? "javascript.validation.message.namespace.should.be.in.file" : aClass instanceof JSVariable ? "javascript.validation.message.variable.should.be.in.file" : "javascript.validation.message.function.should.be.in.file", name, nameWithExtension);
final Annotation annotation = myHolder.createErrorAnnotation(node, message);
annotation.registerFix(new RenameFileFix(nameWithExtension));
annotation.registerFix(new RenameElementFix(aClass) {
final String text;
final String familyName;
{
String term = message.substring(0, message.indexOf(' '));
text = super.getText().replace("class", StringUtil.decapitalize(term));
familyName = super.getFamilyName().replace("Class", term);
}
@NotNull
@Override
public String getText() {
return text;
}
@NotNull
@Override
public String getFamilyName() {
return familyName;
}
});
}
}
checkFileUnderSourceRoot(aClass, new SimpleErrorReportingClient());
}
Aggregations