-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from jenkinsci/idea-stapler-plugin-172
Report custom tag attributes that are marked deprecated.
- Loading branch information
Showing
8 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ava/io/jenkins/stapler/idea/jelly/DeprecatedStaplerJellyCustomTagAttributeInspection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.jenkins.stapler.idea.jelly; | ||
|
||
import com.intellij.codeInspection.LocalInspectionTool; | ||
import com.intellij.codeInspection.ProblemsHolder; | ||
import com.intellij.psi.PsiElementVisitor; | ||
import com.intellij.psi.XmlElementVisitor; | ||
import com.intellij.psi.xml.XmlAttribute; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.kohsuke.stapler.idea.descriptor.StaplerCustomJellyTagfileXmlAttributeDescriptor; | ||
|
||
public class DeprecatedStaplerJellyCustomTagAttributeInspection extends LocalInspectionTool { | ||
@Override | ||
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
return new XmlElementVisitor() { | ||
@Override | ||
public void visitXmlAttribute(@NotNull XmlAttribute attribute) { | ||
if (attribute.getDescriptor() instanceof StaplerCustomJellyTagfileXmlAttributeDescriptor descriptor && descriptor.getModel().isDeprecated()) { | ||
holder.registerProblem(attribute, String.format("Attribute '%s' is deprecated. Use \"Go to declaration\" to find the recommended solution.", attribute.getName())); | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/resources/inspectionDescriptions/DeprecatedStaplerJellyCustomTagAttribute.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<body> | ||
Reports usages of deprecated tag attributes in Jelly files. | ||
<p> | ||
It only analyzes custom tag libraries (a package of Jelly files with a marker file <code>taglib</code>). For attribute to be recognized and considered deprecated it must be explicitly documented and marked as deprecated. Use "Navigate to definition" to jump to the documentation to find the resolution. | ||
</p> | ||
</body> | ||
</html> |
29 changes: 29 additions & 0 deletions
29
...io/jenkins/stapler/idea/jelly/DeprecatedStaplerJellyCustomTagAttributeInspectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.jenkins.stapler.idea.jelly; | ||
|
||
import com.intellij.codeInsight.daemon.impl.HighlightInfo; | ||
import com.intellij.lang.annotation.HighlightSeverity; | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase; | ||
|
||
import java.util.List; | ||
|
||
public class DeprecatedStaplerJellyCustomTagAttributeInspectionTest extends BasePlatformTestCase { | ||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
myFixture.enableInspections(new DeprecatedStaplerJellyCustomTagAttributeInspection()); | ||
} | ||
|
||
@Override | ||
protected String getTestDataPath() { | ||
return "src/test/testData"; | ||
} | ||
|
||
public void testDeprecateTagAttribute() { | ||
myFixture.copyDirectoryToProject("testlib", "testlib"); | ||
myFixture.configureByFile(getTestName(true) + ".jelly"); | ||
|
||
List<HighlightInfo> highlightInfos = myFixture.doHighlighting(HighlightSeverity.WARNING); | ||
assertNotEmpty(highlightInfos); | ||
assertEquals("Attribute 'title' is deprecated. Use \"Go to declaration\" to find the recommended solution.", highlightInfos.get(0).getDescription()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:t="/testlib"> | ||
<t:test title="Hello, World!" /> | ||
</j:jelly> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"> | ||
<st:documentation> | ||
<st:attribute name="title" deprecated="true">title, deprecated use tooltip instead, or htmlTooltip if you intend to pass HTML.</st:attribute> | ||
</st:documentation> | ||
<p>Test</p> | ||
</j:jelly> |