mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
InspectionMappingConsistency inspection
This commit is contained in:
@@ -13,8 +13,12 @@
|
||||
<junitPatcher implementation="org.jetbrains.idea.devkit.run.JUnitDevKitPatcher"/>
|
||||
<antBuildGen implementation="org.jetbrains.idea.devkit.build.ant.ChunkBuildPluginExtension"/>
|
||||
<compiler.buildParticipantProvider implementation="org.jetbrains.idea.devkit.build.PluginBuildParticipantProvider"/>
|
||||
|
||||
<dom.fileDescription implementation="org.jetbrains.idea.devkit.dom.impl.PluginXmlDomFileDescription"/>
|
||||
<dom.extender domClass="org.jetbrains.idea.devkit.dom.Extensions" extenderClass="org.jetbrains.idea.devkit.dom.impl.ExtensionDomExtender"/>
|
||||
<dom.implementation interfaceClass="org.jetbrains.idea.devkit.dom.IdeaPlugin" implementationClass="org.jetbrains.idea.devkit.dom.impl.IdeaPluginImpl"/>
|
||||
<dom.implementation interfaceClass="org.jetbrains.idea.devkit.dom.Extension" implementationClass="org.jetbrains.idea.devkit.dom.impl.ExtensionImpl"/>
|
||||
|
||||
<configurationType implementation="org.jetbrains.idea.devkit.run.PluginConfigurationType"/>
|
||||
<moduleType id="PLUGIN_MODULE" implementationClass="org.jetbrains.idea.devkit.module.PluginModuleType" classpathProvider="true"/>
|
||||
<sdkType implementation="org.jetbrains.idea.devkit.projectRoots.IdeaJdk"/>
|
||||
@@ -46,6 +50,13 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
implementationClass="org.jetbrains.idea.devkit.inspections.TitleCapitalizationInspection"/>
|
||||
<localInspection language="XML" shortName="InspectionMappingConsistency"
|
||||
bundle="org.jetbrains.idea.devkit.DevKitBundle"
|
||||
groupKey="inspections.group.name"
|
||||
displayName="<inspection> tag consistency"
|
||||
enabledByDefault="true"
|
||||
level="ERROR"
|
||||
implementationClass="org.jetbrains.idea.devkit.inspections.InspectionMappingConsistencyInspection"/>
|
||||
|
||||
<moduleConfigurationEditorProvider implementation="org.jetbrains.idea.devkit.module.PluginModuleEditorsProvider"/>
|
||||
<implicitUsageProvider implementation="org.jetbrains.idea.devkit.inspections.DevKitEntryPoints"/>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<span style="font-family: verdana,serif; font-size: smaller;">Checks inspection mappings consistency</span>
|
||||
</body>
|
||||
</html>
|
||||
@@ -29,4 +29,5 @@ public interface Extension extends DomElement {
|
||||
|
||||
GenericAttributeValue<String> getOrder();
|
||||
|
||||
ExtensionPoint getExtensionPoint();
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ public interface IdeaPlugin extends DomElement {
|
||||
|
||||
|
||||
@NotNull
|
||||
@SubTagList("resource-bundle")
|
||||
List<GenericDomValue<String>> getResourceBundles();
|
||||
GenericDomValue<String> addResourceBundle();
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.dom.impl;
|
||||
|
||||
import com.intellij.pom.PomTargetPsiElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.xml.DomTarget;
|
||||
import org.jetbrains.idea.devkit.dom.Extension;
|
||||
import org.jetbrains.idea.devkit.dom.ExtensionPoint;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 10/10/11
|
||||
*/
|
||||
public abstract class ExtensionImpl implements Extension {
|
||||
|
||||
@Override
|
||||
public ExtensionPoint getExtensionPoint() {
|
||||
PsiElement declaration = getChildDescription().getDeclaration(getManager().getProject());
|
||||
if (declaration instanceof PomTargetPsiElement) {
|
||||
return (ExtensionPoint)((DomTarget)((PomTargetPsiElement)declaration).getTarget()).getDomElement();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,6 @@ public class PluginXmlDomFileDescription extends DomFileDescription<IdeaPlugin>
|
||||
super(IdeaPlugin.class, "idea-plugin");
|
||||
}
|
||||
|
||||
protected void initializeFileDescription() {
|
||||
super.initializeFileDescription();
|
||||
registerImplementation(IdeaPlugin.class, IdeaPluginImpl.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getFileIcon(int flags) {
|
||||
return ICON;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.XmlElementVisitor;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import com.intellij.util.xml.DomUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.dom.Extension;
|
||||
import org.jetbrains.idea.devkit.dom.ExtensionPoint;
|
||||
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 10/10/11
|
||||
*/
|
||||
public class InspectionMappingConsistencyInspection extends DevKitInspectionBase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder,
|
||||
boolean isOnTheFly,
|
||||
@NotNull LocalInspectionToolSession session) {
|
||||
return new XmlElementVisitor() {
|
||||
@Override
|
||||
public void visitXmlTag(XmlTag tag) {
|
||||
DomElement element = DomUtil.getDomElement(tag);
|
||||
if (element instanceof Extension) {
|
||||
ExtensionPoint target = ((Extension)element).getExtensionPoint();
|
||||
if (InheritanceUtil.isInheritor(target.getBeanClass().getValue(), "com.intellij.codeInspection.InspectionEP")) {
|
||||
if (tag.getAttribute("key") != null || tag.getAttribute("bundleKey") != null) {
|
||||
if (tag.getAttribute("bundle") == null && tag.getAttribute("groupBundle") == null) {
|
||||
IdeaPlugin plugin = DomUtil.getParentOfType(element, IdeaPlugin.class, true);
|
||||
if (plugin != null && plugin.getResourceBundles().isEmpty()) {
|
||||
Pair<TextRange,PsiElement> range = DomUtil.getProblemRange(element.getXmlTag());
|
||||
holder.registerProblem(range.second, range.first, "Bundle should be specified");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "<inspection> tag consistency";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return "InspectionMappingConsistency";
|
||||
}
|
||||
}
|
||||
@@ -620,7 +620,7 @@
|
||||
enabledByDefault="false" level="WARNING"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyConstructorNamedArgumentsInspection"/>
|
||||
<localInspection language="Groovy" shortName="GroovyDocCheck" displayName="GroovyDoc issues" groupName="Probable bugs"
|
||||
enabledByDefault="true" level="ERROR" key="groovy.doc.issues"
|
||||
enabledByDefault="true" level="ERROR"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyDocCheckInspection"/>
|
||||
<localInspection language="Groovy" shortName="GroovyRangeTypeCheck" bundle="org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle"
|
||||
key="incorrect.range.argument" groupName="Probable bugs" enabledByDefault="false" level="WARNING"
|
||||
|
||||
+3
-16
@@ -28,11 +28,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import com.intellij.util.xml.GenericAttributeValue;
|
||||
import com.intellij.util.xml.GenericValue;
|
||||
import com.intellij.util.xml.DomFileElement;
|
||||
import com.intellij.xml.util.XmlTagUtil;
|
||||
import com.intellij.util.xml.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -151,7 +147,7 @@ public class DomElementProblemDescriptorImpl implements DomElementProblemDescrip
|
||||
if (element != null) {
|
||||
assert element.isValid() : element;
|
||||
if (element instanceof XmlTag) {
|
||||
return createTagNameRange((XmlTag)element);
|
||||
return DomUtil.getProblemRange((XmlTag)element);
|
||||
}
|
||||
|
||||
int length = element.getTextRange().getLength();
|
||||
@@ -167,20 +163,11 @@ public class DomElementProblemDescriptorImpl implements DomElementProblemDescrip
|
||||
|
||||
final XmlTag tag = getParentXmlTag();
|
||||
if (tag != null) {
|
||||
return createTagNameRange(tag);
|
||||
return DomUtil.getProblemRange(tag);
|
||||
}
|
||||
return NO_PROBLEM;
|
||||
}
|
||||
|
||||
private static Pair<TextRange, PsiElement> createTagNameRange(final XmlTag tag) {
|
||||
final PsiElement startToken = XmlTagUtil.getStartTagNameElement(tag);
|
||||
if (startToken == null) {
|
||||
return Pair.create(tag.getTextRange(), (PsiElement)tag);
|
||||
}
|
||||
|
||||
return Pair.create(startToken.getTextRange().shiftRight(-tag.getTextRange().getStartOffset()), (PsiElement)tag);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return myDomElement + "; " + myMessage;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -21,6 +22,7 @@ import com.intellij.util.xml.reflect.DomAttributeChildDescription;
|
||||
import com.intellij.util.xml.reflect.DomCollectionChildDescription;
|
||||
import com.intellij.util.xml.reflect.DomFixedChildDescription;
|
||||
import com.intellij.util.xml.reflect.DomGenericInfo;
|
||||
import com.intellij.xml.util.XmlTagUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -444,5 +446,13 @@ public class DomUtil {
|
||||
public static boolean hasXml(@NotNull DomElement element) {
|
||||
return element.getXmlElement() != null;
|
||||
}
|
||||
|
||||
|
||||
public static Pair<TextRange, PsiElement> getProblemRange(final XmlTag tag) {
|
||||
final PsiElement startToken = XmlTagUtil.getStartTagNameElement(tag);
|
||||
if (startToken == null) {
|
||||
return Pair.create(tag.getTextRange(), (PsiElement)tag);
|
||||
}
|
||||
|
||||
return Pair.create(startToken.getTextRange().shiftRight(-tag.getTextRange().getStartOffset()), (PsiElement)tag);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user