Skip to content

Commit e39e04b

Browse files
authored
Merge pull request #333 from cedricziel/ns-implicit-usage
[T3CMS] Add ImplicitUsageProvider for TYPO3 XML Namespaces
2 parents 28910b5 + 1dcd818 commit e39e04b

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

typo3-cms/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
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>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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>

0 commit comments

Comments
 (0)