Java Code Examples for com.intellij.ide.highlighter.XmlFileType

The following examples show how to use com.intellij.ide.highlighter.XmlFileType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: idea-php-typo3-plugin   Source File: XLFFileTypeListener.java    License: MIT License 6 votes vote down vote up
@Override
public void projectOpened(@NotNull Project project) {
    if (!(FileTypeManager.getInstance().getFileTypeByExtension("xlf") instanceof XmlFileType)) {
        WriteCommandAction.runWriteCommandAction(ProjectManager.getInstance().getOpenProjects()[0], () -> {
            FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, "xlf");

            ApplicationManager.getApplication().invokeLater(() -> {
                Notification notification = GROUP_DISPLAY_ID_INFO.createNotification(
                    "TYPO3 CMS Plugin",
                    "XLF File Type Association",
                    "The XLF File Type was re-assigned to XML to prevent errors with the XLIFF Plugin and allow autocompletion. Please re-index your projects.",
                    NotificationType.INFORMATION
                );
                Project[] projects = ProjectManager.getInstance().getOpenProjects();
                Notifications.Bus.notify(notification, projects[0]);
            });
        });
    }
}
 
Example 2
Source Project: camel-idea-plugin   Source File: IdeaUtils.java    License: Apache License 2.0 6 votes vote down vote up
public void iterateXmlDocumentRoots(Module module, Consumer<XmlTag> rootTag) {
    final GlobalSearchScope moduleScope = module.getModuleContentScope();
    final GlobalSearchScope xmlFiles = GlobalSearchScope.getScopeRestrictedByFileTypes(moduleScope, XmlFileType.INSTANCE);

    ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex();
    fileIndex.iterateContent(f -> {
        if (xmlFiles.contains(f)) {
            PsiFile file = PsiManager.getInstance(module.getProject()).findFile(f);
            if (file instanceof XmlFile) {
                XmlFile xmlFile = (XmlFile) file;
                XmlTag root = xmlFile.getRootTag();
                if (root != null) {
                    rootTag.accept(xmlFile.getRootTag());
                }
            }
        }
        return true;
    });
}
 
Example 3
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile psiFile) {
            if(psiFile.getFileType() == PhpFileType.INSTANCE) {
                phpVisitor(holder, psiFile);
            } else if(psiFile.getFileType() == YAMLFileType.YML) {
                yamlVisitor(holder, psiFile);
            } else if(psiFile.getFileType() == XmlFileType.INSTANCE) {
                xmlVisitor(holder, psiFile);
            }
        }
    };
}
 
Example 4
public void testXmlServiceLineMarkerForClassName() {
    myFixture.configureByText(XmlFileType.INSTANCE,
        "<container>\n" +
            "  <services>\n" +
            "      <service id=\"Service\\Bar\"/>\n" +
            "  </services>\n" +
            "</container>"
    );

    assertLineMarker(PhpPsiElementFactory.createPsiFileFromText(getProject(), "<?php\n" +
        "namespace Service{\n" +
        "    class Bar{}\n" +
        "}"
    ), new LineMarker.ToolTipEqualsAssert("Navigate to definition"));

    assertLineMarker(PhpPsiElementFactory.createPsiFileFromText(getProject(), "<?php\n" +
        "namespace Service{\n" +
        "    class Bar{}\n" +
        "}"
    ), new LineMarker.TargetAcceptsPattern("Navigate to definition", XmlPatterns.xmlTag().withName("service").withAttributeValue("id", "Service\\Bar")));
}
 
Example 5
Source Project: idea-php-symfony2-plugin   Source File: ServiceUtil.java    License: MIT License 6 votes vote down vote up
/**
 * Get parameter def inside xml or yaml file
 */
public static Collection<PsiElement> getParameterDefinition(Project project, String parameterName) {

    if(parameterName.length() > 2 && parameterName.startsWith("%") && parameterName.endsWith("%")) {
        parameterName = parameterName.substring(1, parameterName.length() - 1);
    }

    Collection<PsiElement> psiElements = new ArrayList<>();

    Collection<VirtualFile> fileCollection = FileBasedIndex.getInstance().getContainingFiles(ContainerParameterStubIndex.KEY, parameterName, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), XmlFileType.INSTANCE, YAMLFileType.YML));
    for(VirtualFile virtualFile: fileCollection) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        if(psiFile != null) {
            psiElements.addAll(ServiceIndexUtil.findParameterDefinitions(psiFile, parameterName));
        }
    }

    return psiElements;

}
 
Example 6
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {

    if(psiElement.getContainingFile().getFileType() != XmlFileType.INSTANCE || !Symfony2ProjectComponent.isEnabled(psiElement.getProject())) {
        return false;
    }

    XmlTag serviceTagValid = getServiceTagValid(psiElement);
    if(serviceTagValid == null) {
        return false;
    }

    if(!ServiceActionUtil.isValidXmlParameterInspectionService(serviceTagValid)) {
        return false;
    }

    return ServiceActionUtil.getXmlMissingArgumentTypes(serviceTagValid, true, new ContainerCollectionResolver.LazyServiceCollector(project)).size() > 0;
}
 
Example 7
public void testDocumentNameCompletion() {
    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-mapping><document name=\"<caret>\"/></doctrine-mapping>",
        "MyDateTime"
    );

    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-mongo-mapping><document name=\"<caret>\"/></doctrine-mongo-mapping>",
        "MyDateTime"
    );

    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-foo-mapping><document name=\"<caret>\"/></doctrine-foo-mapping>",
        "MyDateTime"
    );
}
 
Example 8
/**
 * @see DoctrineMetadataPattern#getXmlTargetDocumentClass()
 */
public void testTargetDocumentNavigation() {
    for(String s : new String[] {"reference-one", "reference-many", "embed-many", "embed-one"}) {
        assertNavigationMatch(
            XmlFileType.INSTANCE,
            "<doctrine-mapping><document><" + s + " target-document=\"Foo\\Bar\\Ns<caret>\\BarRepo\"/></document></doctrine-mapping>",
            PlatformPatterns.psiElement(PhpClass.class)
        );

        assertNavigationMatch(
            XmlFileType.INSTANCE,
            "<doctrine-foo-mapping><document><" + s + " target-document=\"Foo\\Bar\\Ns<caret>\\BarRepo\"/></document></doctrine-foo-mapping>",
            PlatformPatterns.psiElement(PhpClass.class)
        );

        assertNavigationMatch(
            XmlFileType.INSTANCE,
            "<doctrine-foo-mapping><document name=\"Foo\\Bar\\Ns\\Foo\"><" + s + " target-document=\"Foo\\Bar\\Ns<caret>\\BarRepo\"/></document></doctrine-foo-mapping>",
            PlatformPatterns.psiElement(PhpClass.class)
        );
    }
}
 
Example 9
public void testDoctrineRepositoryDefinitionLineMarker() {
    myFixture.configureByText(XmlFileType.INSTANCE, "" +
            "<doctrine-mapping>\n" +
            "    <document name=\"Foo\" repository-class=\"Entity\\Bar\"/>\n" +
            "</doctrine-mapping>"
    );

    myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
            "namespace Entity{\n" +
            "    class Bar{}\n" +
            "}"
    );

    assertLineMarker(PhpPsiElementFactory.createPsiFileFromText(getProject(), "<?php\n" +
            "namespace Entity{\n" +
            "    class Bar{}\n" +
            "}"
    ), new LineMarker.ToolTipEqualsAssert("Navigate to metadata"));
}
 
Example 10
public void testIdInsideServiceTagShouldCompleteWithClassName() {
    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<services><service id=\"<caret>\" class=\"MyFoo\\Foo\\Apple\"/></services>",
        "my_foo.foo.apple"
    );

    assertCompletionNotContains(
        XmlFileType.INSTANCE,
        "<service id=\"<caret>\" class=\"MyFoo\\Foo\\Apple\"/>",
        "my_foo.foo.apple"
    );

    assertCompletionNotContains(
        XmlFileType.INSTANCE,
        "<service id=\"<caret>\"/>",
        "my_foo.foo.apple"
    );
}
 
Example 11
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
    if(System.getenv("PHPSTORM_ENV") != null) return;

    try {
        myFixture.addFileToProject("app/Resources/views/foo.html.twig", "");
    } catch (Exception e) {
        e.printStackTrace();
    }

    assertCompletionContains(XmlFileType.INSTANCE, "" +
            "    <route id=\"root\" path=\"/wp-admin\">\n" +
            "        <default key=\"template\"><caret></default>\n" +
            "    </route>",
        "foo.html.twig"
    );

    assertNavigationMatch(XmlFileType.INSTANCE, "" +
        "    <route id=\"root\" path=\"/wp-admin\">\n" +
        "        <default key=\"template\">foo.ht<caret>ml.twig</default>\n" +
        "    </route>"
    );
}
 
Example 12
public void testThatDecoratesServiceTagProvidesReferences() {
    assertCompletionContains(XmlFileType.INSTANCE, "" +
            "<?xml version=\"1.0\"?>\n" +
            "<container>\n" +
            "    <services>\n" +
            "        <service class=\"Foo\\Foobar\" decorates=\"<caret>\"/>\n" +
            "    </services>\n" +
            "</container>\n",
        "service_container"
    );

    assertNavigationMatch(XmlFileType.INSTANCE, "" +
            "<?xml version=\"1.0\"?>\n" +
            "<container>\n" +
            "    <services>\n" +
            "        <service class=\"Foo\\Foobar\" decorates=\"foo.bar_<caret>factory\"/>\n" +
            "    </services>\n" +
            "</container>\n",
        PlatformPatterns.psiElement(PhpClass.class)
    );
}
 
Example 13
Source Project: idea-php-symfony2-plugin   Source File: XmlHelperTest.java    License: MIT License 6 votes vote down vote up
/**
 * @see XmlHelper#visitServiceCallArgumentMethodIndex
 */
public void testVisitServiceCallArgument() {
    myFixture.configureByText(XmlFileType.INSTANCE, "" +
        "<service class=\"Foo\\Bar\">\n" +
        "   <call method=\"setBar\">\n" +
        "      <argument/>\n" +
        "      <argument type=\"service\" id=\"ma<caret>iler\" />\n" +
        "   </call>\n" +
        "</service>"
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    PsiElement parent = psiElement.getParent();

    Collection<String> results = new ArrayList<>();

    XmlHelper.visitServiceCallArgument((XmlAttributeValue) parent, visitor ->
        results.add(visitor.getClassName() + ":" + visitor.getMethod() + ":" + visitor.getParameterIndex())
    );

    assertContainsElements(results, "Foo\\Bar:setBar:1");
}
 
Example 14
Source Project: idea-php-symfony2-plugin   Source File: XmlHelperTest.java    License: MIT License 6 votes vote down vote up
/**
 * @see XmlHelper#visitServiceCallArgumentMethodIndex
 */
public void testVisitServiceCallArgumentParameter() {
    myFixture.configureByText(XmlFileType.INSTANCE, "" +
        "<service class=\"Foo\\Bar\">\n" +
        "   <call method=\"setBar\">\n" +
        "      <argument/>\n" +
        "      <argument type=\"service\" id=\"ma<caret>iler\" />\n" +
        "   </call>\n" +
        "</service>"
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    PsiElement parent = psiElement.getParent();

    Collection<Parameter> results = new ArrayList<>();

    XmlHelper.visitServiceCallArgumentMethodIndex((XmlAttributeValue) parent, results::add);

    assertNotNull(
        ContainerUtil.find(results, parameter -> "arg2".equals(parameter.getName()))
    );
}
 
Example 15
Source Project: idea-php-symfony2-plugin   Source File: XmlHelperTest.java    License: MIT License 6 votes vote down vote up
/**
 * @see XmlHelper#getServiceDefinitionClass
 */
public void testGetServiceDefinitionClass() {
    myFixture.configureByText(XmlFileType.INSTANCE, "" +
        "<service class=\"Foo\\Bar\">\n" +
        "      <tag type=\"service\" method=\"ma<caret>iler\" />\n" +
        "</service>"
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertEquals("Foo\\Bar", XmlHelper.getServiceDefinitionClass(psiElement));

    myFixture.configureByText(XmlFileType.INSTANCE, "" +
        "<service id=\"Foo\\Bar\">\n" +
        "      <tag type=\"service\" method=\"ma<caret>iler\" />\n" +
        "</service>"
    );

    psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertEquals("Foo\\Bar", XmlHelper.getServiceDefinitionClass(psiElement));
}
 
Example 16
Source Project: idea-php-symfony2-plugin   Source File: XmlHelperTest.java    License: MIT License 6 votes vote down vote up
/**
 * @see XmlHelper#getArgumentIndex
 */
public void testGetArgumentIndexOnIndex() {
    myFixture.configureByText(XmlFileType.INSTANCE, "" +
        "<service class=\"Foo\\Bar\">\n" +
        "      <argum<caret>ent index=\"2\" />\n" +
        "</service>"
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertEquals(2, XmlHelper.getArgumentIndex((XmlTag) psiElement.getParent()));

    myFixture.configureByText(XmlFileType.INSTANCE, "" +
        "<service class=\"Foo\\Bar\">\n" +
        "      <argum<caret>ent index=\"foobar\" />\n" +
        "</service>"
    );

    psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertEquals(-1, XmlHelper.getArgumentIndex((XmlTag) psiElement.getParent()));
}
 
Example 17
Source Project: idea-php-typo3-plugin   Source File: TranslatorTest.java    License: MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
        FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, "xlf");
    });

    FileBasedIndex.getInstance().requestRebuild(TranslationIndex.KEY);

    myFixture.addFileToProject("typo3conf/ext/foo/ext_emconf.php", "");
}
 
Example 18
Source Project: idea-php-typo3-plugin   Source File: AbstractTranslationTest.java    License: MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
        FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, "xlf");
    });

    FileBasedIndex.getInstance().requestRebuild(TranslationIndex.KEY);

    myFixture.addFileToProject("typo3conf/ext/foo/ext_emconf.php", "");

    myFixture.copyFileToProject("sample.xlf", "typo3conf/ext/foo/sample.xlf");
    myFixture.copyFileToProject("de.sample.xlf", "typo3conf/ext/foo/de.sample.xlf");
}
 
Example 19
Source Project: idea-php-typo3-plugin   Source File: FluidTagNameProvider.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public String[][] getDefaultNamespaces(@NotNull XmlFile file) {
    return (file.getFileType() == FluidFileType.INSTANCE || file.getFileType() == HtmlFileType.INSTANCE|| file.getFileType() == XmlFileType.INSTANCE) ? new String[][]{
        {"f", "http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"},
        {"", "http://www.w3.org/1999/html"}
    } : null;
}
 
Example 20
public void testThatResourceProvidesLineMarker() {
    myFixture.copyFileToProject("BundleScopeLineMarkerProvider.php");

    Collection<String[]> providers = new ArrayList<String[]>() {{
        add(new String[] {"@FooBundle/foo.php"});
        add(new String[] {"@FooBundle"});
        add(new String[] {"@FooBundle/"});
    }};

    for (String[] provider : providers) {
        myFixture.configureByText(
            XmlFileType.INSTANCE,
           String.format("<routes><import resource=\"%s\" /></routes>", provider[0] )
        );

        PsiFile psiFile = myFixture.configureByText("foo.php", "");
        assertLineMarker(
            psiFile,
            new LineMarker.ToolTipEqualsAssert("Navigate to resource")
        );

        assertLineMarker(
            psiFile,
            new LineMarker.TargetAcceptsPattern("Navigate to resource", XmlPatterns.xmlTag().withName("import").withAttributeValue("resource", provider[0]))
        );
    }
}
 
Example 21
Source Project: arma-intellij-plugin   Source File: ArmaPluginUtil.java    License: MIT License 5 votes vote down vote up
/**
 * @param module {@link Module} instance to get a stringtable.xml file for
 * @return a {@link VirtualFile} that maps to a Stringtable.xml file (name case sensitivity doesn't matter),
 * or null if couldn't be found
 */
@Nullable
public static VirtualFile getStringTableXmlFile(@NotNull Module module) {
	Collection<VirtualFile> files = FileTypeIndex.getFiles(XmlFileType.INSTANCE, module.getModuleContentScope());
	for (VirtualFile virtFile : files) {
		if (virtFile.getName().equalsIgnoreCase("stringtable.xml")) {
			return virtFile;
		}
	}
	return null;
}
 
Example 22
Source Project: arma-intellij-plugin   Source File: ArmaPluginUtil.java    License: MIT License 5 votes vote down vote up
/**
 * @param module {@link Module} instance to get a stringtable.xml file for
 * @return a {@link VirtualFile} that maps to a Stringtable.xml file (name case sensitivity doesn't matter),
 * or null if couldn't be found
 */
@Nullable
public static VirtualFile getStringTableXmlFile(@NotNull Module module) {
	Collection<VirtualFile> files = FileTypeIndex.getFiles(XmlFileType.INSTANCE, module.getModuleContentScope());
	for (VirtualFile virtFile : files) {
		if (virtFile.getName().equalsIgnoreCase("stringtable.xml")) {
			return virtFile;
		}
	}
	return null;
}
 
Example 23
public void testThatFactoryMethodAttributeProvidesReferenceForService() {
    assertReferenceMatchOnParent(XmlFileType.INSTANCE, "" +
            "<?xml version=\"1.0\"?>\n" +
            "<container>\n" +
            "    <services>\n" +
            "        <service>\n" +
            "            <factory service=\"foo.bar_factory\" method=\"cr<caret>eate\"/>\n" +
            "        </service>\n" +
            "    </services>\n" +
            "</container>\n",
        PlatformPatterns.psiElement(Method.class).withName("create")
    );
}
 
Example 24
Source Project: idea-php-symfony2-plugin   Source File: ServiceActionUtilTest.java    License: MIT License 5 votes vote down vote up
@NotNull
private XmlTag createServiceXmlTag(@NotNull String content) {
    myFixture.configureByText(XmlFileType.INSTANCE, content);

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    return (XmlTag) psiElement.getParent();
}
 
Example 25
Source Project: idea-php-symfony2-plugin   Source File: ServiceUtil.java    License: MIT License 5 votes vote down vote up
public static Set<String> getTaggedServices(Project project, String tagName) {
    Set<String> service = new HashSet<>();

    for(String serviceName: SymfonyProcessors.createResult(project, ServicesTagStubIndex.KEY)) {
        List<Set<String>> serviceDefinitions = FileBasedIndex.getInstance().getValues(ServicesTagStubIndex.KEY, serviceName, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), XmlFileType.INSTANCE, YAMLFileType.YML));
        for(Set<String> strings: serviceDefinitions) {
            if(strings.contains(tagName)) {
                service.add(serviceName);
            }
        }
    }

    return service;
}
 
Example 26
Source Project: idea-php-symfony2-plugin   Source File: XmlServiceTagIntention.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {

    if(psiElement.getContainingFile().getFileType() != XmlFileType.INSTANCE || !Symfony2ProjectComponent.isEnabled(psiElement.getProject())) {
        return false;
    }

    return XmlServiceArgumentIntention.getServiceTagValid(psiElement) != null;
}
 
Example 27
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    if(file.getFileType() != XmlFileType.INSTANCE || !Symfony2ProjectComponent.isEnabled(project)) {
        return false;
    }

    return getMatchXmlTag(editor, file) != null;
}
 
Example 28
public void testEntityNameCompletion() {
    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-mapping><entity name=\"<caret>\"/></doctrine-mapping>",
        "MyDateTime"
    );

    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-foo-mapping><entity name=\"<caret>\"/></doctrine-foo-mapping>>",
        "MyDateTime"
    );
}
 
Example 29
public void testDocumentEmbeddedNameCompletion() {
    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-mongo-mapping><embedded-document name=\"<caret>\"/></doctrine-mongo-mapping>",
        "MyDateTime"
    );

    assertCompletionContains(
        XmlFileType.INSTANCE,
        "<doctrine-foo-mapping><embedded name=\"<caret>\"/></doctrine-foo-mapping>",
        "MyDateTime"
    );
}
 
Example 30
public void testDocumentNameNonSupportedCompletion() {
    assertCompletionNotContains(
        XmlFileType.INSTANCE,
        "<doctrine1-foo-mapping><document name=\"<caret>\"/></doctrine1-foo-mapping>",
        "MyDateTime"
    );

    assertCompletionNotContains(
        XmlFileType.INSTANCE,
        "<doctrine1-mapping><document name=\"<caret>\"/></doctrine1-mapping>",
        "MyDateTime"
    );
}