Do not show invalid javadoc tag warnings for maven plugin annotations (IDEA-139132)

This commit is contained in:
Yaroslav Lepenkin
2015-04-20 17:42:31 +03:00
parent d732967110
commit 5934fe7406
8 changed files with 236 additions and 0 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2000-2015 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 com.intellij.psi.javadoc;
import com.intellij.openapi.extensions.ExtensionPointName;
import java.util.List;
public interface CustomJavadocTagProvider {
ExtensionPointName<CustomJavadocTagProvider> EP_NAME = ExtensionPointName.create(
"com.intellij.customJavadocTagProvider");
List<JavadocTagInfo> getSupportedTags();
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.CustomJavadocTagProvider;
import com.intellij.psi.javadoc.JavadocManager;
import com.intellij.psi.javadoc.JavadocTagInfo;
import org.jetbrains.annotations.NotNull;
@@ -65,7 +66,11 @@ public class JavadocManagerImpl implements JavadocManager {
myInfos.add(new ExceptionTagInfo("exception"));
myInfos.add(new ExceptionTagInfo("throws"));
myInfos.add(new ValueDocTagInfo());
Collections.addAll(myInfos, Extensions.getExtensions(JavadocTagInfo.EP_NAME, project));
for (CustomJavadocTagProvider extension : Extensions.getExtensions(CustomJavadocTagProvider.EP_NAME)) {
myInfos.addAll(extension.getSupportedTags());
}
}
@Deprecated
@@ -0,0 +1,119 @@
/*
* Copyright 2000-2015 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.maven.javadoc;/*
* Copyright 2000-2015 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.
*/
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.javadoc.CustomJavadocTagProvider;
import com.intellij.psi.javadoc.JavadocTagInfo;
import com.intellij.psi.javadoc.PsiDocTagValue;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class MojoClassAnnotationTagProvider implements CustomJavadocTagProvider {
private static final String[] ANNOTATION_NAMES = {
"goal",
"requiresDependencyResolution",
"requiresProject",
"requiresReports",
"aggregator",
"requiresOnline",
"requiresDirectInvocation",
"phase",
"execute"
};
@Override
public List<JavadocTagInfo> getSupportedTags() {
return ContainerUtil.map(ANNOTATION_NAMES, new Function<String, JavadocTagInfo>() {
@Override
public JavadocTagInfo fun(String name) {
return new MojoAnnotationInfo(name);
}
});
}
}
class MojoAnnotationInfo implements JavadocTagInfo {
private static final String BASE_CLASS = "org.apache.maven.plugin.Mojo";
private final String myName;
public MojoAnnotationInfo(@NotNull String name) {
myName = name;
}
@Override
public String getName() {
return myName;
}
@Override
public boolean isInline() {
return false;
}
@Override
public boolean isValidInContext(PsiElement element) {
if (element instanceof PsiClass) {
PsiClass psiClass = (PsiClass)element;
return InheritanceUtil.isInheritor(psiClass, BASE_CLASS);
}
return false;
}
@Override
public Object[] getPossibleValues(PsiElement context, PsiElement place, String prefix) {
return null;
}
@Nullable
@Override
public String checkTagValue(PsiDocTagValue value) {
return null;
}
@Nullable
@Override
public PsiReference getReference(PsiDocTagValue value) {
return null;
}
}
@@ -34,6 +34,7 @@
<depends optional="true" config-file="groovy-support.xml">org.intellij.groovy</depends>
<extensions defaultExtensionNs="com.intellij">
<customJavadocTagProvider implementation="org.jetbrains.idea.maven.javadoc.MojoClassAnnotationTagProvider"/>
<fileTypeFactory implementation="org.jetbrains.idea.maven.utils.MavenFileTypeFactory"/>
<projectImportProvider implementation="org.jetbrains.idea.maven.wizards.MavenProjectImportProvider"/>
<projectOpenProcessor implementation="org.jetbrains.idea.maven.wizards.MavenProjectOpenProcessor"/>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>TestMojo.java</file>
<line>13</line>
<description>Wrong tag &lt;code&gt;ololo&lt;/code&gt;</description>
</problem>
</problems>
@@ -0,0 +1,19 @@
package org.apache.maven.plugin;
/**
* @goal
* @requiresDependencyResolution
* @requiresProject
* @requiresReports
* @aggregator
* @requiresOnline
* @requiresDirectInvocation
* @phase
* @execute
* @ololo
*/
class TestMojo implements Mojo {
}
interface Mojo {
}
@@ -0,0 +1,32 @@
/*
* Copyright 2000-2015 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.maven.inspections;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.testFramework.InspectionTestCase;
public class MojoAnnotationInJavadocTest extends InspectionTestCase {
@Override
protected String getTestDataPath() {
return PluginPathManager.getPluginHomePath("maven") + "/src/test/data/inspections";
}
public void testJavadocMojoValidTags() throws Exception {
doTest(getTestName(true), new JavaDocLocalInspection());
}
}
+1
View File
@@ -188,6 +188,7 @@
</extensionPoint>
<extensionPoint name="javadocTagInfo" area="IDEA_PROJECT" interface="com.intellij.psi.javadoc.JavadocTagInfo"/>
<extensionPoint name="customJavadocTagProvider" interface="com.intellij.psi.javadoc.CustomJavadocTagProvider"/>
<extensionPoint name="refactoring.introduceParameterMethodUsagesProcessor" interface="com.intellij.refactoring.introduceParameter.IntroduceParameterMethodUsagesProcessor"/>