mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[devkit] merge ExtensionPointBeanClassInspection into PluginXmlDomInspection
This commit is contained in:
@@ -85,12 +85,6 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
implementationClass="org.jetbrains.idea.devkit.inspections.InspectionMappingConsistencyInspection"/>
|
||||
<localInspection language="XML" shortName="ExtensionPointBeanClass" applyToDialects="false"
|
||||
groupKey="inspections.group.name"
|
||||
displayName="<extensionPoint> beanClass specification"
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
implementationClass="org.jetbrains.idea.devkit.inspections.ExtensionPointBeanClassInspection"/>
|
||||
|
||||
<localInspection language="JAVA" shortName="UndesirableClassUsage" displayName="Undesirable class usage"
|
||||
groupKey="inspections.group.name"
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Ensures that an <extensionPoint> tag has <with> subtags specifying types for all class fields.
|
||||
<!-- tooltip end -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.idea.devkit.dom;
|
||||
|
||||
import com.intellij.ide.presentation.Presentation;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.util.xml.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -89,4 +90,11 @@ public interface ExtensionPoint extends DomElement {
|
||||
*/
|
||||
@Nullable
|
||||
String getNamePrefix();
|
||||
|
||||
/**
|
||||
* Returns EP fields missing {@code <with>} declaration to specify type.
|
||||
*
|
||||
* @return Fields.
|
||||
*/
|
||||
List<PsiField> collectMissingWithTags();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -16,12 +16,18 @@
|
||||
package org.jetbrains.idea.devkit.dom.impl;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.xml.DomUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.devkit.dom.ExtensionPoint;
|
||||
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ExtensionPointImpl implements ExtensionPoint {
|
||||
|
||||
@NotNull
|
||||
@@ -55,4 +61,21 @@ public abstract class ExtensionPointImpl implements ExtensionPoint {
|
||||
|
||||
return getNamePrefix() + "." + getName().getRawText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PsiField> collectMissingWithTags() {
|
||||
PsiClass beanClass = getBeanClass().getValue();
|
||||
if (beanClass == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<PsiField> result = new SmartList<>();
|
||||
for (PsiField field : beanClass.getAllFields()) {
|
||||
if (ExtensionDomExtender.isClassField(field.getName()) &&
|
||||
ExtensionDomExtender.findWithElement(getWithElements(), field) == null) {
|
||||
result.add(field);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import com.intellij.util.xml.highlighting.BasicDomElementsInspection;
|
||||
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder;
|
||||
import com.intellij.util.xml.highlighting.DomHighlightingHelper;
|
||||
import org.jetbrains.idea.devkit.dom.ExtensionPoint;
|
||||
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
|
||||
import org.jetbrains.idea.devkit.dom.impl.ExtensionDomExtender;
|
||||
import org.jetbrains.idea.devkit.inspections.quickfix.AddWithTagFix;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class ExtensionPointBeanClassInspection extends BasicDomElementsInspection<IdeaPlugin> {
|
||||
|
||||
public ExtensionPointBeanClassInspection() {
|
||||
super(IdeaPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
|
||||
if (element instanceof ExtensionPoint) {
|
||||
ExtensionPoint extensionPoint = (ExtensionPoint)element;
|
||||
if (extensionPoint.getWithElements().isEmpty() && !collectMissingWithTags(extensionPoint).isEmpty()) {
|
||||
holder.createProblem(extensionPoint,
|
||||
"<extensionPoint> does not have <with> tags to specify the types of class fields",
|
||||
new AddWithTagFix());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PsiField> collectMissingWithTags(ExtensionPoint element) {
|
||||
final List<PsiField> result = new ArrayList<>();
|
||||
PsiClass beanClass = element.getBeanClass().getValue();
|
||||
if (beanClass != null) {
|
||||
for (PsiField field : beanClass.getAllFields()) {
|
||||
if (ExtensionDomExtender.isClassField(field.getName()) &&
|
||||
ExtensionDomExtender.findWithElement(element.getWithElements(), field) == null) {
|
||||
result.add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.intellij.diagnostic.ITNReporter;
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
|
||||
import com.intellij.ide.plugins.PluginManagerCore;
|
||||
import com.intellij.ide.plugins.PluginManagerMain;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -41,6 +42,7 @@ import com.intellij.util.xml.reflect.DomAttributeChildDescription;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.dom.*;
|
||||
import org.jetbrains.idea.devkit.inspections.quickfix.AddWithTagFix;
|
||||
import org.jetbrains.idea.devkit.util.PsiUtil;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
|
||||
@@ -75,6 +77,9 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
|
||||
else if (element instanceof Extension) {
|
||||
annotateExtension((Extension)element, holder);
|
||||
}
|
||||
else if (element instanceof ExtensionPoint) {
|
||||
annotateExtensionPoint((ExtensionPoint)element, holder);
|
||||
}
|
||||
else if (element instanceof Vendor) {
|
||||
annotateVendor((Vendor)element, holder);
|
||||
}
|
||||
@@ -123,6 +128,15 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateExtensionPoint(ExtensionPoint extensionPoint, DomElementAnnotationHolder holder) {
|
||||
if (extensionPoint.getWithElements().isEmpty() &&
|
||||
!extensionPoint.collectMissingWithTags().isEmpty()) {
|
||||
holder.createProblem(extensionPoint,
|
||||
"<extensionPoint> does not have <with> tags to specify the types of class fields",
|
||||
new AddWithTagFix());
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateExtensions(Extensions extensions, DomElementAnnotationHolder holder) {
|
||||
final GenericAttributeValue<IdeaPlugin> xmlnsAttribute = extensions.getXmlns();
|
||||
if (DomUtil.hasXml(xmlnsAttribute)) {
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.dom.ExtensionPoint;
|
||||
import org.jetbrains.idea.devkit.dom.With;
|
||||
import org.jetbrains.idea.devkit.dom.impl.PluginFieldNameConverter;
|
||||
import org.jetbrains.idea.devkit.inspections.ExtensionPointBeanClassInspection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -53,7 +52,7 @@ public class AddWithTagFix implements LocalQuickFix {
|
||||
return;
|
||||
}
|
||||
ExtensionPoint extensionPoint = (ExtensionPoint)element;
|
||||
List<PsiField> fields = ExtensionPointBeanClassInspection.collectMissingWithTags(extensionPoint);
|
||||
List<PsiField> fields = extensionPoint.collectMissingWithTags();
|
||||
PsiElement navTarget = null;
|
||||
for (PsiField field : fields) {
|
||||
With with = extensionPoint.addWith();
|
||||
|
||||
Reference in New Issue
Block a user