-
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #333 from cedricziel/ns-implicit-usage
[T3CMS] Add ImplicitUsageProvider for TYPO3 XML Namespaces
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...va/com/cedricziel/idea/typo3/codeInspection/daemon/XmlNamespaceImplicitUsageProvider.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,50 @@ | ||
package com.cedricziel.idea.typo3.codeInspection.daemon; | ||
|
||
import com.intellij.codeInsight.daemon.ImplicitUsageProvider; | ||
import com.intellij.lang.xml.XMLLanguage; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.xml.XmlAttribute; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class XmlNamespaceImplicitUsageProvider implements ImplicitUsageProvider { | ||
/** | ||
* @param element The element | ||
* @return true if element should not be reported as unused | ||
*/ | ||
@Override | ||
public boolean isImplicitUsage(@NotNull PsiElement element) { | ||
if (!(element.getLanguage() instanceof XMLLanguage)) { | ||
return false; | ||
} | ||
|
||
if (!(element instanceof XmlAttribute)) { | ||
return false; | ||
} | ||
|
||
if (!((XmlAttribute) element).isNamespaceDeclaration()) { | ||
return false; | ||
} | ||
|
||
String namespace = ((XmlAttribute) element).getValue(); | ||
|
||
return namespace != null && namespace.contains("typo3.org/ns"); | ||
} | ||
|
||
/** | ||
* @param element The element | ||
* @return true if element should not be reported as "assigned but not used" | ||
*/ | ||
@Override | ||
public boolean isImplicitRead(@NotNull PsiElement element) { | ||
return false; | ||
} | ||
|
||
/** | ||
* @param element The element | ||
* @return true if element should not be reported as "referenced but never assigned" | ||
*/ | ||
@Override | ||
public boolean isImplicitWrite(@NotNull PsiElement element) { | ||
return false; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...om/cedricziel/idea/typo3/codeInspection/daemon/XmlNamespaceImplicitUsageProviderTest.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,19 @@ | ||
package com.cedricziel.idea.typo3.codeInspection.daemon; | ||
|
||
import com.cedricziel.idea.typo3.AbstractTestCase; | ||
import com.intellij.codeInsight.daemon.impl.analysis.XmlUnusedNamespaceInspection; | ||
|
||
public class XmlNamespaceImplicitUsageProviderTest extends AbstractTestCase { | ||
@Override | ||
protected String getTestDataPath() { | ||
return super.getTestDataPath() + "/codeInspection/daemon"; | ||
} | ||
|
||
public void testOptimizeImportsDoesNotRemoveImports() { | ||
myFixture.enableInspections(new XmlUnusedNamespaceInspection()); | ||
|
||
myFixture.configureByFile("unused_namespace.html"); | ||
myFixture.performEditorAction("OptimizeImports"); | ||
myFixture.checkResultByFile("unused_namespace.html"); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
typo3-cms/testData/com/cedricziel/idea/typo3/codeInspection/daemon/unused_namespace.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,10 @@ | ||
<div xmlns="http://www.w3.org/1999/xhtml" lang="en" | ||
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers" | ||
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers" | ||
xmlns:flux="http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers" | ||
xmlns:yp="http://typo3.org/ns/Vendor/YourPlugin/ViewHelpers" | ||
|
||
flux:schemaLocation="http://fluidtypo3.org/schemas/flux-7.0.0.xsd" | ||
v:schemaLocation="http://fluidtypo3.org/schemas/vhs-1.8.5.xsd"> | ||
<!-- Fluid goes here --> | ||
</div> |