-
-
Notifications
You must be signed in to change notification settings - Fork 137
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 #2366 from Haehnchen/feature/inspection-language
provide inspection language attributes for deprecated class and controller method inspections
- Loading branch information
Showing
9 changed files
with
256 additions
and
176 deletions.
There are no files selected for viewing
239 changes: 137 additions & 102 deletions
239
...brault/idea/symfony2plugin/codeInspection/service/ServiceDeprecatedClassesInspection.java
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
|
||
import com.intellij.codeInspection.LocalInspectionTool; | ||
import com.intellij.codeInspection.ProblemsHolder; | ||
import com.intellij.lang.Language; | ||
import com.intellij.lang.xml.XMLLanguage; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiElementVisitor; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
|
@@ -18,90 +16,90 @@ | |
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.yaml.YAMLLanguage; | ||
import org.jetbrains.yaml.psi.YAMLKeyValue; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class ControllerMethodInspection extends LocalInspectionTool { | ||
|
||
@NotNull | ||
@Override | ||
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) { | ||
return super.buildVisitor(holder, isOnTheFly); | ||
} | ||
public class ControllerMethodInspection { | ||
public static class ControllerMethodInspectionYaml extends LocalInspectionTool { | ||
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) { | ||
return super.buildVisitor(holder, isOnTheFly); | ||
} | ||
|
||
return new PsiElementVisitor() { | ||
@Override | ||
public void visitElement(@NotNull PsiElement element) { | ||
Language language = element.getLanguage(); | ||
return new PsiElementVisitor() { | ||
@Override | ||
public void visitElement(@NotNull PsiElement element) { | ||
if (YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) { | ||
String text = PsiElementUtils.trimQuote(element.getText()); | ||
if (StringUtils.isNotBlank(text)) { | ||
InspectionUtil.inspectController(element, text, holder, new YamlLazyRouteName(element)); | ||
} | ||
} | ||
|
||
if (language == YAMLLanguage.INSTANCE) { | ||
visitYamlElement(element, holder); | ||
} else if(language == XMLLanguage.INSTANCE) { | ||
visitXmlElement(element, holder); | ||
super.visitElement(element); | ||
} | ||
|
||
super.visitElement(element); | ||
} | ||
}; | ||
} | ||
|
||
private void visitYamlElement(@NotNull PsiElement element, @NotNull ProblemsHolder holder) { | ||
if (YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) { | ||
String text = PsiElementUtils.trimQuote(element.getText()); | ||
if (StringUtils.isNotBlank(text)) { | ||
InspectionUtil.inspectController(element, text, holder, new YamlLazyRouteName(element)); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
public void visitXmlElement(@NotNull PsiElement element, @NotNull ProblemsHolder holder) { | ||
if(XmlHelper.getRouteControllerPattern().accepts(element)) { | ||
String text = PsiElementUtils.trimQuote(element.getText()); | ||
if(StringUtils.isNotBlank(text)) { | ||
InspectionUtil.inspectController(element, text, holder, new XmlLazyRouteName(element)); | ||
public static class ControllerMethodInspectionXml extends LocalInspectionTool { | ||
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) { | ||
return super.buildVisitor(holder, isOnTheFly); | ||
} | ||
|
||
return new PsiElementVisitor() { | ||
@Override | ||
public void visitElement(@NotNull PsiElement element) { | ||
if(XmlHelper.getRouteControllerPattern().accepts(element)) { | ||
String text = PsiElementUtils.trimQuote(element.getText()); | ||
if(StringUtils.isNotBlank(text)) { | ||
InspectionUtil.inspectController(element, text, holder, new XmlLazyRouteName(element)); | ||
} | ||
} | ||
|
||
super.visitElement(element); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
private record YamlLazyRouteName(@NotNull PsiElement psiElement) implements InspectionUtil.LazyControllerNameResolve { | ||
@Nullable | ||
@Override | ||
public String getRouteName() { | ||
YAMLKeyValue defaultKeyValue = PsiTreeUtil.getParentOfType(this.psiElement.getParent(), YAMLKeyValue.class); | ||
if (defaultKeyValue == null) { | ||
return null; | ||
} | ||
|
||
YAMLKeyValue def = PsiTreeUtil.getParentOfType(defaultKeyValue, YAMLKeyValue.class); | ||
if (def == null) { | ||
return null; | ||
} | ||
@Override | ||
public String getRouteName() { | ||
YAMLKeyValue defaultKeyValue = PsiTreeUtil.getParentOfType(this.psiElement.getParent(), YAMLKeyValue.class); | ||
if (defaultKeyValue == null) { | ||
return null; | ||
} | ||
|
||
return YamlHelper.getYamlKeyName(def); | ||
YAMLKeyValue def = PsiTreeUtil.getParentOfType(defaultKeyValue, YAMLKeyValue.class); | ||
if (def == null) { | ||
return null; | ||
} | ||
|
||
return YamlHelper.getYamlKeyName(def); | ||
} | ||
} | ||
|
||
private record XmlLazyRouteName(@NotNull PsiElement psiElement) implements InspectionUtil.LazyControllerNameResolve { | ||
|
||
@Nullable | ||
@Override | ||
public String getRouteName() { | ||
XmlTag defaultTag = PsiTreeUtil.getParentOfType(this.psiElement, XmlTag.class); | ||
if (defaultTag != null) { | ||
XmlTag routeTag = PsiTreeUtil.getParentOfType(defaultTag, XmlTag.class); | ||
if (routeTag != null) { | ||
XmlAttribute id = routeTag.getAttribute("id"); | ||
if (id != null) { | ||
return id.getValue(); | ||
} | ||
@Override | ||
public String getRouteName() { | ||
XmlTag defaultTag = PsiTreeUtil.getParentOfType(this.psiElement, XmlTag.class); | ||
if (defaultTag != null) { | ||
XmlTag routeTag = PsiTreeUtil.getParentOfType(defaultTag, XmlTag.class); | ||
if (routeTag != null) { | ||
XmlAttribute id = routeTag.getAttribute("id"); | ||
if (id != null) { | ||
return id.getValue(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/ControllerMethodXml.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,5 @@ | ||
<html> | ||
<body> | ||
<!-- tooltip end --> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/ControllerMethodYaml.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,5 @@ | ||
<html> | ||
<body> | ||
<!-- tooltip end --> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/DeprecatedClassesXml.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,5 @@ | ||
<html> | ||
<body> | ||
<!-- tooltip end --> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/DeprecatedClassesYaml.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,5 @@ | ||
<html> | ||
<body> | ||
<!-- tooltip end --> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/ServiceDeprecatedClassesInspectionXml.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,5 @@ | ||
<html> | ||
<body> | ||
<!-- tooltip end --> | ||
</body> | ||
</html> |
6 changes: 0 additions & 6 deletions
6
src/main/resources/inspectionDescriptions/YamlDeprecatedClasses.html
This file was deleted.
Oops, something went wrong.