File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
java/com/cedricziel/idea/typo3/codeInspection/daemon
test/java/com/cedricziel/idea/typo3/codeInspection/daemon
testData/com/cedricziel/idea/typo3/codeInspection/daemon Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .cedricziel .idea .typo3 .codeInspection .daemon ;
2+
3+ import com .intellij .codeInsight .daemon .ImplicitUsageProvider ;
4+ import com .intellij .lang .xml .XMLLanguage ;
5+ import com .intellij .psi .PsiElement ;
6+ import com .intellij .psi .xml .XmlAttribute ;
7+ import org .jetbrains .annotations .NotNull ;
8+
9+ public class XmlNamespaceImplicitUsageProvider implements ImplicitUsageProvider {
10+ /**
11+ * @param element The element
12+ * @return true if element should not be reported as unused
13+ */
14+ @ Override
15+ public boolean isImplicitUsage (@ NotNull PsiElement element ) {
16+ if (!(element .getLanguage () instanceof XMLLanguage )) {
17+ return false ;
18+ }
19+
20+ if (!(element instanceof XmlAttribute )) {
21+ return false ;
22+ }
23+
24+ if (!((XmlAttribute ) element ).isNamespaceDeclaration ()) {
25+ return false ;
26+ }
27+
28+ String namespace = ((XmlAttribute ) element ).getValue ();
29+
30+ return namespace != null && namespace .contains ("typo3.org/ns" );
31+ }
32+
33+ /**
34+ * @param element The element
35+ * @return true if element should not be reported as "assigned but not used"
36+ */
37+ @ Override
38+ public boolean isImplicitRead (@ NotNull PsiElement element ) {
39+ return false ;
40+ }
41+
42+ /**
43+ * @param element The element
44+ * @return true if element should not be reported as "referenced but never assigned"
45+ */
46+ @ Override
47+ public boolean isImplicitWrite (@ NotNull PsiElement element ) {
48+ return false ;
49+ }
50+ }
Original file line number Diff line number Diff line change 194194 implementationClass =" com.cedricziel.idea.typo3.codeInspection.XmlUnusedNamespaceDeclarationSuppressor" />
195195 <lang .inspectionSuppressor language =" XHTML"
196196 implementationClass =" com.cedricziel.idea.typo3.codeInspection.XmlUnusedNamespaceDeclarationSuppressor" />
197+ <implicitUsageProvider implementation =" com.cedricziel.idea.typo3.codeInspection.daemon.XmlNamespaceImplicitUsageProvider" />
197198 </extensions >
198199
199200 <actions >
Original file line number Diff line number Diff line change 1+ package com .cedricziel .idea .typo3 .codeInspection .daemon ;
2+
3+ import com .cedricziel .idea .typo3 .AbstractTestCase ;
4+ import com .intellij .codeInsight .daemon .impl .analysis .XmlUnusedNamespaceInspection ;
5+
6+ public class XmlNamespaceImplicitUsageProviderTest extends AbstractTestCase {
7+ @ Override
8+ protected String getTestDataPath () {
9+ return super .getTestDataPath () + "/codeInspection/daemon" ;
10+ }
11+
12+ public void testOptimizeImportsDoesNotRemoveImports () {
13+ myFixture .enableInspections (new XmlUnusedNamespaceInspection ());
14+
15+ myFixture .configureByFile ("unused_namespace.html" );
16+ myFixture .performEditorAction ("OptimizeImports" );
17+ myFixture .checkResultByFile ("unused_namespace.html" );
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ < div xmlns ="http://www.w3.org/1999/xhtml " lang ="en "
2+ xmlns:v ="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers "
3+ xmlns:f ="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers "
4+ xmlns:flux ="http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers "
5+ xmlns:yp ="http://typo3.org/ns/Vendor/YourPlugin/ViewHelpers "
6+
7+ flux:schemaLocation ="http://fluidtypo3.org/schemas/flux-7.0.0.xsd "
8+ v:schemaLocation ="http://fluidtypo3.org/schemas/vhs-1.8.5.xsd ">
9+ <!-- Fluid goes here -->
10+ </ div >
You can’t perform that action at this time.
0 commit comments