-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add xliff file type with schema
- Loading branch information
Showing
8 changed files
with
2,374 additions
and
0 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
src/main/java/de/vette/idea/neos/lang/xliff/XliffFile.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,14 @@ | ||
package de.vette.idea.neos.lang.xliff; | ||
|
||
import com.intellij.psi.FileViewProvider; | ||
import com.intellij.psi.impl.source.xml.XmlFileImpl; | ||
import com.intellij.psi.tree.IElementType; | ||
import com.intellij.psi.tree.IFileElementType; | ||
import com.intellij.psi.xml.XmlFile; | ||
|
||
public class XliffFile extends XmlFileImpl implements XmlFile { | ||
static final IFileElementType XLIFF_FILE_ELEMENT_TYPE = new IFileElementType("XLIFF_FILE_ELEMENT_TYPE", XliffLanguage.INSTANCE); | ||
public XliffFile(FileViewProvider viewProvider) { | ||
super(viewProvider, XLIFF_FILE_ELEMENT_TYPE); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/de/vette/idea/neos/lang/xliff/XliffFileType.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,48 @@ | ||
package de.vette.idea.neos.lang.xliff; | ||
|
||
import com.intellij.ide.highlighter.XmlLikeFileType; | ||
import com.intellij.lang.Language; | ||
import com.intellij.lang.html.HTMLLanguage; | ||
import com.intellij.openapi.fileTypes.FileType; | ||
import com.intellij.openapi.util.NlsContexts; | ||
import com.intellij.openapi.util.NlsSafe; | ||
import de.vette.idea.neos.NeosIcons; | ||
import de.vette.idea.neos.lang.eel.EelFileType; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
|
||
public class XliffFileType extends XmlLikeFileType { | ||
@NonNls public static final String DOT_DEFAULT_EXTENSION = ".xlf"; | ||
|
||
public static final XliffFileType INSTANCE = new XliffFileType(); | ||
|
||
private XliffFileType() { | ||
super(XliffLanguage.INSTANCE); | ||
} | ||
|
||
protected XliffFileType(Language language) { | ||
super(language); | ||
} | ||
|
||
@Override | ||
public @NonNls @NotNull String getName() { | ||
return "Neos XLIFF"; | ||
} | ||
|
||
@Override | ||
public @NlsContexts.Label @NotNull String getDescription() { | ||
return "Neos XLIFF"; | ||
} | ||
|
||
@Override | ||
public @NlsSafe @NotNull String getDefaultExtension() { | ||
return "xlf"; | ||
} | ||
|
||
@Override | ||
public Icon getIcon() { | ||
return NeosIcons.NODE_TYPE; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/de/vette/idea/neos/lang/xliff/XliffLanguage.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 de.vette.idea.neos.lang.xliff; | ||
|
||
import com.intellij.lang.Language; | ||
import com.intellij.lang.html.HTMLLanguage; | ||
import com.intellij.lang.xml.XMLLanguage; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class XliffLanguage extends XMLLanguage { | ||
public static final XliffLanguage INSTANCE = new XliffLanguage(); | ||
|
||
private XliffLanguage() { | ||
super(XMLLanguage.INSTANCE, "XLIFF", "application/xliff+xml", "application/x-xliff+xml"); | ||
} | ||
|
||
protected XliffLanguage(@NotNull Language baseLanguage, @NonNls @NotNull String name, @NonNls @NotNull String @NotNull ... mime) { | ||
super(baseLanguage, name, mime); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/de/vette/idea/neos/lang/xliff/XliffParserDefinition.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,56 @@ | ||
package de.vette.idea.neos.lang.xliff; | ||
|
||
import com.intellij.lang.*; | ||
import com.intellij.lang.xml.XMLLanguage; | ||
import com.intellij.lexer.Lexer; | ||
import com.intellij.lexer.XmlLexer; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.FileViewProvider; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.impl.source.parsing.xml.XmlParser; | ||
import com.intellij.psi.tree.IFileElementType; | ||
import com.intellij.psi.tree.TokenSet; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class XliffParserDefinition implements ParserDefinition { | ||
@Override | ||
public @NotNull Lexer createLexer(Project project) { | ||
return new XmlLexer(); | ||
} | ||
|
||
@Override | ||
public @NotNull PsiParser createParser(Project project) { | ||
return LanguageParserDefinitions.INSTANCE.forLanguage(Language.findInstance(XMLLanguage.class)).createParser(project); | ||
} | ||
|
||
@Override | ||
public @NotNull IFileElementType getFileNodeType() { | ||
return XliffFile.XLIFF_FILE_ELEMENT_TYPE; | ||
} | ||
|
||
@Override | ||
public @NotNull TokenSet getCommentTokens() { | ||
return LanguageParserDefinitions.INSTANCE.forLanguage(Language.findInstance(XMLLanguage.class)).getCommentTokens(); | ||
} | ||
|
||
@Override | ||
public @NotNull TokenSet getStringLiteralElements() { | ||
return TokenSet.EMPTY; | ||
} | ||
|
||
@Override | ||
public @NotNull TokenSet getWhitespaceTokens() { | ||
return LanguageParserDefinitions.INSTANCE.forLanguage(Language.findInstance(XMLLanguage.class)).getWhitespaceTokens(); | ||
} | ||
|
||
@Override | ||
public @NotNull PsiElement createElement(ASTNode node) { | ||
throw new IllegalArgumentException("Unknown element: "+node); | ||
} | ||
|
||
@Override | ||
public @NotNull PsiFile createFile(@NotNull FileViewProvider viewProvider) { | ||
return new XliffFile(viewProvider); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/de/vette/idea/neos/lang/xliff/XliffSchemaProvider.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,37 @@ | ||
package de.vette.idea.neos.lang.xliff; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.util.io.FileUtilRt; | ||
import com.intellij.openapi.vfs.VfsUtil; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.xml.XmlFile; | ||
import com.intellij.xml.XmlSchemaProvider; | ||
import org.iso_relax.dispatcher.IslandSchema; | ||
import org.iso_relax.dispatcher.IslandVerifier; | ||
import org.iso_relax.dispatcher.SchemaProvider; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.net.URL; | ||
import java.util.Iterator; | ||
|
||
public class XliffSchemaProvider extends XmlSchemaProvider { | ||
|
||
@Override | ||
public @Nullable XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull PsiFile baseFile) { | ||
final URL resource = XliffSchemaProvider.class.getResource("/de/vette/idea/neos/xsd/xliff/xliff12.xsd"); | ||
final VirtualFile fileByURL = VfsUtil.findFileByURL(resource); | ||
PsiFile result = baseFile.getManager().findFile(fileByURL); | ||
if (result instanceof XmlFile) { | ||
return (XmlFile)result.copy(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isAvailable(final @NotNull XmlFile file) { | ||
return FileUtilRt.extensionEquals(file.getName(), XliffFileType.INSTANCE.getDefaultExtension()); | ||
} | ||
} |
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
Oops, something went wrong.