com.intellij.lang.xml.XMLLanguage Java Examples

The following examples show how to use com.intellij.lang.xml.XMLLanguage. 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 File: FluidInjector.java    From idea-php-typo3-plugin with 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
Source File: XmlHaxelibCompletionContributor.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
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 File: TranslationUtilTest.java    From idea-php-symfony2-plugin with 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 File: TranslationUtilTest.java    From idea-php-symfony2-plugin with 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 File: TranslationUtilTest.java    From idea-php-symfony2-plugin with 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 File: TranslationUtilTest.java    From idea-php-symfony2-plugin with 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 File: LatteXmlFileInspection.java    From intellij-latte with 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 File: LatteFileViewProvider.java    From intellij-latte with 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 File: DefaultViewHelpersProvider.java    From idea-php-typo3-plugin with 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 File: IdeaUtils.java    From camel-idea-plugin with 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 File: LatteFileViewProvider.java    From intellij-latte with MIT License 4 votes vote down vote up
@NotNull
@Override
public Language getTemplateDataLanguage() {
	return isXml() ? XMLLanguage.INSTANCE : HTMLLanguage.INSTANCE;
}
 
Example #12
Source File: NMMLFileType.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public NMMLFileType() {
  super(XMLLanguage.INSTANCE);
}
 
Example #13
Source File: TranslationTagGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
private PsiElementPattern.Capture<XmlToken> getTranslationTagValuePattern() {
    return PlatformPatterns.psiElement(XmlToken.class)
        .inVirtualFile(new VirtualFilePattern().withExtension("twig"))
        .withLanguage(XMLLanguage.INSTANCE);
}