use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class HtmlUnknownTagInspectionBase method checkTag.
@Override
protected void checkTag(@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (!(tag instanceof HtmlTag) || !XmlHighlightVisitor.shouldBeValidated(tag)) {
return;
}
XmlElementDescriptor descriptorFromContext = XmlUtil.getDescriptorFromContext(tag);
PsiElement parent = tag.getParent();
XmlElementDescriptor parentDescriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
XmlElementDescriptor ownDescriptor = isAbstractDescriptor(descriptorFromContext) ? tag.getDescriptor() : descriptorFromContext;
if (isAbstractDescriptor(ownDescriptor) || (parentDescriptor instanceof HtmlElementDescriptorImpl && ownDescriptor instanceof HtmlElementDescriptorImpl && isAbstractDescriptor(descriptorFromContext))) {
final String name = tag.getName();
if (!isCustomValuesEnabled() || !isCustomValue(name)) {
final AddCustomHtmlElementIntentionAction action = new AddCustomHtmlElementIntentionAction(TAG_KEY, name, XmlBundle.message("add.custom.html.tag", name));
// todo: support "element is not allowed" message for html5
// some tags in html5 cannot be found in xhtml5.xsd if they are located in incorrect context, so they get any-element descriptor (ex. "canvas: tag)
final String message = isAbstractDescriptor(ownDescriptor) ? XmlErrorMessages.message("unknown.html.tag", name) : XmlErrorMessages.message("element.is.not.allowed.here", name);
final PsiElement startTagName = XmlTagUtil.getStartTagNameElement(tag);
assert startTagName != null;
final PsiElement endTagName = XmlTagUtil.getEndTagNameElement(tag);
List<LocalQuickFix> quickfixes = new ArrayList<>();
quickfixes.add(action);
if (isOnTheFly) {
PsiFile file = startTagName.getContainingFile();
if (file instanceof XmlFile) {
quickfixes.add(XmlQuickFixFactory.getInstance().createNSDeclarationIntentionFix(startTagName, "", null));
}
// People using non-HTML as their template data language (but having not changed this in the IDE)
// will most likely see 'unknown html tag' error, because HTML is usually the default.
// So if they check quick fixes for this error they'll discover Change Template Data Language feature.
ContainerUtil.addIfNotNull(quickfixes, createChangeTemplateDataFix(file));
}
if (HtmlUtil.isHtml5Tag(name) && !HtmlUtil.hasNonHtml5Doctype(tag)) {
quickfixes.add(new SwitchToHtml5WithHighPriorityAction());
}
ProblemHighlightType highlightType = tag.getContainingFile().getContext() == null ? ProblemHighlightType.GENERIC_ERROR_OR_WARNING : ProblemHighlightType.INFORMATION;
if (startTagName.getTextLength() > 0) {
holder.registerProblem(startTagName, message, highlightType, quickfixes.toArray(new LocalQuickFix[quickfixes.size()]));
}
if (endTagName != null) {
holder.registerProblem(endTagName, message, highlightType, quickfixes.toArray(new LocalQuickFix[quickfixes.size()]));
}
}
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class MavenDomAnnotator method addProblems.
private static void addProblems(DomElement element, MavenDomProjectModel model, DomElementAnnotationHolder holder, MavenProjectProblem.ProblemType... types) {
MavenProject mavenProject = MavenDomUtil.findProject(model);
if (mavenProject != null) {
for (MavenProjectProblem each : mavenProject.getProblems()) {
MavenProjectProblem.ProblemType type = each.getType();
if (!Arrays.asList(types).contains(type))
continue;
VirtualFile problemFile = LocalFileSystem.getInstance().findFileByPath(each.getPath());
LocalQuickFix[] fixes = LocalQuickFix.EMPTY_ARRAY;
if (problemFile != null && !Comparing.equal(mavenProject.getFile(), problemFile)) {
fixes = new LocalQuickFix[] { new OpenProblemFileFix(problemFile) };
}
holder.createProblem(element, HighlightSeverity.ERROR, each.getDescription(), fixes);
}
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class XsltValidator method checkUnusedVariable.
public static void checkUnusedVariable(XsltVariable variable, ProblemsHolder holder) {
if (variable instanceof XsltParameter) {
if (((XsltParameter) variable).isAbstract()) {
return;
}
} else {
if (variable.isVoid()) {
return;
}
}
final XmlTag tag = variable.getTag();
final XmlTag templateTag = XsltCodeInsightUtil.getTemplateTag(tag, false);
if (templateTag == null) {
return;
}
final XmlAttribute attribute = tag.getAttribute("name");
if (attribute == null) {
return;
}
final PsiElement token = XsltSupport.getAttValueToken(attribute);
if (token == null) {
return;
}
final SearchScope scope = new LocalSearchScope(templateTag);
final Query<PsiReference> refs = ReferencesSearch.search(variable, scope, false);
if (isUnused(variable, refs)) {
final String name = variable.getName();
assert name != null;
final LocalQuickFix[] fixes;
if (variable instanceof XsltParameter) {
fixes = new LocalQuickFix[] { new DeleteUnusedParameterFix(name, (XsltParameter) variable) };
} else {
fixes = new LocalQuickFix[] { new DeleteUnusedVariableFix(name, variable) };
}
holder.registerProblem(token, ((DeleteUnusedElementBase) fixes[0]).getType() + " '" + name + "' is never used", ProblemHighlightType.LIKE_UNUSED_SYMBOL, fixes);
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class PropertyReference method getQuickFixes.
public LocalQuickFix[] getQuickFixes() {
List<PropertiesFile> propertiesFiles = retrievePropertyFilesByBundleName(myBundleName, getElement());
LocalQuickFix fix = PropertiesQuickFixFactory.getInstance().createCreatePropertyFix(myElement, myKey, propertiesFiles);
return new LocalQuickFix[] { fix };
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class SkeletonTestTask method runTestOn.
@Override
public void runTestOn(@NotNull final String sdkHome) throws IOException, InvalidSdkException {
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
final File skeletonsPath = new File(PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()));
// File with module skeleton
File skeletonFileOrDirectory = new File(skeletonsPath, myModuleNameToBeGenerated);
// Module may be stored in "moduleName.py" or "moduleName/__init__.py"
if (skeletonFileOrDirectory.isDirectory()) {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory, PyNames.INIT_DOT_PY);
} else {
skeletonFileOrDirectory = new File(skeletonFileOrDirectory.getAbsolutePath() + PyNames.DOT_PY);
}
final File skeletonFile = skeletonFileOrDirectory;
if (skeletonFile.exists()) {
// To make sure we do not reuse it
assert skeletonFile.delete() : "Failed to delete file " + skeletonFile;
}
ApplicationManager.getApplication().invokeAndWait(() -> {
// File that uses CLR library
myFixture.copyFileToProject("dotNet/" + mySourceFileToRunGenerationOn, mySourceFileToRunGenerationOn);
// Library itself
myFixture.copyFileToProject("dotNet/PythonLibs.dll", "PythonLibs.dll");
// Another library
myFixture.copyFileToProject("dotNet/SingleNameSpace.dll", "SingleNameSpace.dll");
myFixture.configureByFile(mySourceFileToRunGenerationOn);
}, ModalityState.NON_MODAL);
// This inspection should suggest us to generate stubs
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
final String intentionName = PyBundle.message("sdk.gen.stubs.for.binary.modules", myUseQuickFixWithThisModuleOnly);
final IntentionAction intention = myFixture.findSingleIntention(intentionName);
Assert.assertNotNull("No intention found to generate skeletons!", intention);
Assert.assertThat("Intention should be quick fix to run", intention, Matchers.instanceOf(QuickFixWrapper.class));
final LocalQuickFix quickFix = ((QuickFixWrapper) intention).getFix();
Assert.assertThat("Quick fix should be 'generate binary skeletons' fix to run", quickFix, Matchers.instanceOf(GenerateBinaryStubsFix.class));
final Task fixTask = ((GenerateBinaryStubsFix) quickFix).getFixTask(myFixture.getFile());
fixTask.run(new AbstractProgressIndicatorBase());
}
});
FileUtil.copy(skeletonFile, new File(myFixture.getTempDirPath(), skeletonFile.getName()));
if (myExpectedSkeletonFile != null) {
final String actual = StreamUtil.readText(new FileInputStream(skeletonFile), Charset.defaultCharset());
final String skeletonText = StreamUtil.readText(new FileInputStream(new File(getTestDataPath(), myExpectedSkeletonFile)), Charset.defaultCharset());
// TODO: Move to separate method ?
if (!Matchers.equalToIgnoringWhiteSpace(removeGeneratorVersion(skeletonText)).matches(removeGeneratorVersion(actual))) {
throw new FileComparisonFailure("asd", skeletonText, actual, skeletonFile.getAbsolutePath());
}
}
myFixture.configureByFile(skeletonFile.getName());
}
Aggregations