Skip to content

Commit

Permalink
Merge pull request #333 from cedricziel/ns-implicit-usage
Browse files Browse the repository at this point in the history
[T3CMS] Add ImplicitUsageProvider for TYPO3 XML Namespaces
  • Loading branch information
cedricziel authored Sep 30, 2020
2 parents 28910b5 + 1dcd818 commit e39e04b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
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;
}
}
1 change: 1 addition & 0 deletions typo3-cms/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
implementationClass="com.cedricziel.idea.typo3.codeInspection.XmlUnusedNamespaceDeclarationSuppressor"/>
<lang.inspectionSuppressor language="XHTML"
implementationClass="com.cedricziel.idea.typo3.codeInspection.XmlUnusedNamespaceDeclarationSuppressor"/>
<implicitUsageProvider implementation="com.cedricziel.idea.typo3.codeInspection.daemon.XmlNamespaceImplicitUsageProvider"/>
</extensions>

<actions>
Expand Down
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");
}
}
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>

0 comments on commit e39e04b

Please sign in to comment.