Java Code Examples for com.intellij.lang.xml.XMLLanguage

The following examples show how to use com.intellij.lang.xml.XMLLanguage. 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: FluidInjector.java    License: MIT License 6 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
    if (context.getLanguage() == XMLLanguage.INSTANCE) return;
    final Project project = context.getProject();
    if (!FluidIndexUtil.hasFluid(project)) return;

    final PsiElement parent = context.getParent();
    if (context instanceof XmlAttributeValueImpl && parent instanceof XmlAttribute) {
        final int length = context.getTextLength();
        final String name = ((XmlAttribute) parent).getName();

        if (isInjectableAttribute(project, length, name)) {
            registrar
                .startInjecting(FluidLanguage.INSTANCE)
                .addPlace(null, null, (PsiLanguageInjectionHost) context, ElementManipulators.getValueTextRange(context))
                .doneInjecting();
        }
    }
}
 
Example 2
public XmlHaxelibCompletionContributor() {
  HaxelibCache haxelibCache = HaxelibCache.getInstance();
  availableHaxelibs = haxelibCache.getAvailableHaxelibs();
  localHaxelibs = haxelibCache.getLocalHaxelibs();

  extend(CompletionType.BASIC, PlatformPatterns.psiElement().inside(
    XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute("name"))
      .withSuperParent(2, XmlPatterns.xmlTag().withName("haxelib")).withLanguage(XMLLanguage.INSTANCE)),
         new CompletionProvider<CompletionParameters>() {
           @Override
           protected void addCompletions(@NotNull CompletionParameters parameters,
                                         ProcessingContext context,
                                         @NotNull CompletionResultSet result) {
             for (int i = 0; i < availableHaxelibs.size(); i++) {
               result.addElement(LookupElementBuilder.create(availableHaxelibs.get(i))
                                   .withTailText(" available at haxelib", true));
             }

             for (int i = 0; i < localHaxelibs.size(); i++) {
               result.addElement(LookupElementBuilder.create(localHaxelibs.get(i))
                                   .withTailText(" installed", true));
             }
           }
         });
}
 
Example 3
Source Project: idea-php-symfony2-plugin   Source File: TranslationUtilTest.java    License: MIT License 6 votes vote down vote up
public void testGetTargetForXlfAsXmlFileInVersion12() {
    PsiFile fileFromText = PsiFileFactory.getInstance(getProject()).createFileFromText(XMLLanguage.INSTANCE, "" +
        "<?xml version=\"1.0\"?>\n" +
        "<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n" +
        "    <file source-language=\"en\" datatype=\"plaintext\" original=\"file.ext\">\n" +
        "        <body>\n" +
        "            <trans-unit id=\"1\">\n" +
        "                <source>This value should be false.</source>\n" +
        "            </trans-unit>\n" +
        "        </body>\n" +
        "    </file>\n" +
        "</xliff>\n"
    );

    Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "This value should be false.");

    assertNotNull(ContainerUtil.find(files, psiElement ->
        psiElement instanceof XmlTag && "This value should be false.".equals(((XmlTag) psiElement).getValue().getText()))
    );
}
 
Example 4
Source Project: idea-php-symfony2-plugin   Source File: TranslationUtilTest.java    License: MIT License 6 votes vote down vote up
public void testGetTargetForXlfAsXmlFileInVersion20() {
    PsiFile fileFromText = PsiFileFactory.getInstance(getProject()).createFileFromText(XMLLanguage.INSTANCE, "" +
        "<?xml version=\"1.0\"?>\n" +
        "<xliff xmlns=\"urn:oasis:names:tc:xliff:document:2.0\"\n" +
        "       version=\"2.0\" srcLang=\"en-US\" trgLang=\"ja-JP\">\n" +
        "    <file id=\"f1\" original=\"Graphic Example.psd\">\n" +
        "        <skeleton href=\"Graphic Example.psd.skl\"/>\n" +
        "        <group id=\"1\">\n" +
        "            <unit id=\"1\">\n" +
        "                <segment>\n" +
        "                    <source>foo</source>\n" +
        "                </segment>\n" +
        "            </unit>\n" +
        "        </group>\n" +
        "    </file>\n" +
        "</xliff>"
    );

    Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "foo");

    assertNotNull(ContainerUtil.find(files, psiElement ->
        psiElement instanceof XmlTag && "foo".equals(((XmlTag) psiElement).getValue().getText()))
    );
}
 
Example 5
Source Project: idea-php-symfony2-plugin   Source File: TranslationUtilTest.java    License: MIT License 6 votes vote down vote up
public void testGetTargetForXlfAsXmlFileInVersion20Shortcut() {
    PsiFile fileFromText = PsiFileFactory.getInstance(getProject()).createFileFromText(XMLLanguage.INSTANCE, "" +
        "<xliff xmlns=\"urn:oasis:names:tc:xliff:document:2.0\" version=\"2.0\"\n" +
        " srcLang=\"en-US\" trgLang=\"ja-JP\">\n" +
        " <file id=\"f1\" original=\"Graphic Example.psd\">\n" +
        "  <skeleton href=\"Graphic Example.psd.skl\"/>\n" +
        "  <unit id=\"1\">\n" +
        "   <segment>\n" +
        "    <source>foo</source>\n" +
        "   </segment>\n" +
        "  </unit>\n" +
        " </file>\n" +
        "</xliff>"
    );

    Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "foo");

    assertNotNull(ContainerUtil.find(files, psiElement ->
        psiElement instanceof XmlTag && "foo".equals(((XmlTag) psiElement).getValue().getText()))
    );
}
 
Example 6
Source Project: idea-php-symfony2-plugin   Source File: TranslationUtilTest.java    License: MIT License 6 votes vote down vote up
public void testGetTargetForXlfAsXmlFileInVersion12AndResname() {
    PsiFile fileFromText = PsiFileFactory.getInstance(getProject()).createFileFromText(XMLLanguage.INSTANCE, "" +
        "<?xml version=\"1.0\"?>\n" +
        "<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n" +
        "    <file source-language=\"en\" datatype=\"plaintext\" original=\"file.ext\">\n" +
        "        <body>\n" +
        "            <trans-unit id=\"1\" resname=\"index.hello_world\">\n" +
        "                <source>foo</source>\n" +
        "            </trans-unit>\n" +
        "        </body>\n" +
        "    </file>\n" +
        "</xliff>\n"
    );

    Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "index.hello_world");

    assertNotNull(ContainerUtil.find(files, psiElement ->
        psiElement instanceof XmlTag && "index.hello_world".equals(((XmlTag) psiElement).getAttributeValue("resname")))
    );
}
 
Example 7
Source Project: intellij-latte   Source File: LatteXmlFileInspection.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof XmlFile) || file.getLanguage() != XMLLanguage.INSTANCE || !file.getName().equals(LatteFileConfiguration.FILE_NAME)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();

	XmlDocument xmlDocument = ((XmlFile) file).getDocument();
	if (xmlDocument == null) {
		addError(manager, problems, file, "Root tag <latte> is missing", isOnTheFly);
		return problems.toArray(new ProblemDescriptor[0]);
	}

	if (xmlDocument.getRootTag() == null || !xmlDocument.getRootTag().getName().equals("latte")) {
		addError(manager, problems, file, "Root tag <latte> is missing", isOnTheFly);
		return problems.toArray(new ProblemDescriptor[0]);
	}

	XmlTag rootTag = xmlDocument.getRootTag();
	if (rootTag.getAttribute("vendor") == null) {
		PsiElement psiElement = rootTag.getFirstChild().getNextSibling();
		addError(
				manager,
				problems,
				psiElement != null ? psiElement : file,
				"Missing required attribute `vendor` on tag <latte>. It must be unique name like composer package name.",
				isOnTheFly
		);
	}

	return problems.toArray(new ProblemDescriptor[0]);
}
 
Example 8
Source Project: intellij-latte   Source File: LatteFileViewProvider.java    License: MIT License 5 votes vote down vote up
@Nullable
protected PsiFile createFile(@NotNull Language lang) {
	ParserDefinition parser = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
	if (parser == null) {
		return null;
	} else if (lang == XMLLanguage.INSTANCE || lang == HTMLLanguage.INSTANCE) {
		PsiFileImpl file = (PsiFileImpl) parser.createFile(this);
		file.setContentElementType(templateDataElement);
		return file;
	} else {
		return lang == this.getBaseLanguage() ? parser.createFile(this) : null;
	}
}
 
Example 9
Source Project: idea-php-typo3-plugin   Source File: DefaultViewHelpersProvider.java    License: MIT License 4 votes vote down vote up
private synchronized Map<String, ViewHelper> getStringViewHelperMap(@NotNull Project project, String schemaLocation) {
    if (myCache.containsKey(schemaLocation)) {

        return myCache.get(schemaLocation);
    }

    String schema = readSchema(schemaLocation);

    XmlFile xmlLanguage = (XmlFile) PsiFileFactory.getInstance(project).createFileFromText(XMLLanguage.INSTANCE, schema);

    ViewHelperSchemaRecursiveElementVisitor visitor = new ViewHelperSchemaRecursiveElementVisitor();
    visitor.visitXmlFile(xmlLanguage);

    myCache.put(schemaLocation, visitor.viewHelpers);

    return myCache.get(schemaLocation);
}
 
Example 10
Source Project: camel-idea-plugin   Source File: IdeaUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Is the element from XML language
 */
public boolean isXmlLanguage(PsiElement element) {
    return element != null && PsiUtil.getNotAnyLanguage(element.getNode()).is(XMLLanguage.INSTANCE);
}
 
Example 11
Source Project: intellij-latte   Source File: LatteFileViewProvider.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public Language getTemplateDataLanguage() {
	return isXml() ? XMLLanguage.INSTANCE : HTMLLanguage.INSTANCE;
}
 
Example 12
Source Project: intellij-haxe   Source File: NMMLFileType.java    License: Apache License 2.0 4 votes vote down vote up
public NMMLFileType() {
  super(XMLLanguage.INSTANCE);
}
 
Example 13
@NotNull
private PsiElementPattern.Capture<XmlToken> getTranslationTagValuePattern() {
    return PlatformPatterns.psiElement(XmlToken.class)
        .inVirtualFile(new VirtualFilePattern().withExtension("twig"))
        .withLanguage(XMLLanguage.INSTANCE);
}