use of com.intellij.ide.highlighter.custom.SyntaxTable in project intellij-community by JetBrains.
the class CommentByLineCommentHandler method getBlockSuitableCommenter.
private static Commenter getBlockSuitableCommenter(final PsiFile file, int offset, int endOffset) {
final Language languageSuitableForCompleteFragment;
if (offset >= endOffset) {
// we are on empty line
PsiElement element = file.findElementAt(offset);
if (element != null)
languageSuitableForCompleteFragment = element.getParent().getLanguage();
else
languageSuitableForCompleteFragment = null;
} else {
languageSuitableForCompleteFragment = PsiUtilBase.reallyEvaluateLanguageInRange(offset, endOffset, file);
}
Commenter blockSuitableCommenter = languageSuitableForCompleteFragment == null ? LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()) : null;
if (blockSuitableCommenter == null && file.getFileType() instanceof CustomSyntaxTableFileType) {
blockSuitableCommenter = new Commenter() {
final SyntaxTable mySyntaxTable = ((CustomSyntaxTableFileType) file.getFileType()).getSyntaxTable();
@Override
@Nullable
public String getLineCommentPrefix() {
return mySyntaxTable.getLineComment();
}
@Override
@Nullable
public String getBlockCommentPrefix() {
return mySyntaxTable.getStartComment();
}
@Override
@Nullable
public String getBlockCommentSuffix() {
return mySyntaxTable.getEndComment();
}
@Override
public String getCommentedBlockCommentPrefix() {
return null;
}
@Override
public String getCommentedBlockCommentSuffix() {
return null;
}
};
}
return blockSuitableCommenter;
}
use of com.intellij.ide.highlighter.custom.SyntaxTable in project intellij-community by JetBrains.
the class FileTypesTest method testRemappingToInstalledPluginExtension.
// for IDEA-114804 File types mapped to text are not remapped when corresponding plugin is installed
public void testRemappingToInstalledPluginExtension() throws WriteExternalException, InvalidDataException {
ApplicationManager.getApplication().runWriteAction(() -> myFileTypeManager.associatePattern(PlainTextFileType.INSTANCE, "*.fromPlugin"));
Element element = myFileTypeManager.getState();
//String s = JDOMUtil.writeElement(element);
final AbstractFileType typeFromPlugin = new AbstractFileType(new SyntaxTable());
PlatformTestUtil.registerExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP, new FileTypeFactory() {
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
consumer.consume(typeFromPlugin, "fromPlugin");
}
}, getTestRootDisposable());
myFileTypeManager.initStandardFileTypes();
myFileTypeManager.loadState(element);
myFileTypeManager.initComponent();
Map<FileNameMatcher, Pair<FileType, Boolean>> mappings = myFileTypeManager.getRemovedMappings();
assertEquals(1, mappings.size());
assertEquals(typeFromPlugin, mappings.values().iterator().next().first);
}
use of com.intellij.ide.highlighter.custom.SyntaxTable in project intellij-community by JetBrains.
the class AbstractFileType method readSyntaxTable.
@NotNull
public static SyntaxTable readSyntaxTable(@NotNull Element root) {
SyntaxTable table = new SyntaxTable();
for (Element element : root.getChildren()) {
if (ELEMENT_OPTIONS.equals(element.getName())) {
for (final Object o1 : element.getChildren(ELEMENT_OPTION)) {
Element e = (Element) o1;
String name = e.getAttributeValue(ATTRIBUTE_NAME);
String value = e.getAttributeValue(ATTRIBUTE_VALUE);
if (VALUE_LINE_COMMENT.equals(name)) {
table.setLineComment(value);
} else if (VALUE_COMMENT_START.equals(name)) {
table.setStartComment(value);
} else if (VALUE_COMMENT_END.equals(name)) {
table.setEndComment(value);
} else if (VALUE_HEX_PREFIX.equals(name)) {
table.setHexPrefix(value);
} else if (VALUE_NUM_POSTFIXES.equals(name)) {
table.setNumPostfixChars(value);
} else if (VALUE_LINE_COMMENT_AT_START.equals(name)) {
table.lineCommentOnlyAtStart = Boolean.valueOf(value).booleanValue();
} else if (VALUE_HAS_BRACES.equals(name)) {
table.setHasBraces(Boolean.valueOf(value).booleanValue());
} else if (VALUE_HAS_BRACKETS.equals(name)) {
table.setHasBrackets(Boolean.valueOf(value).booleanValue());
} else if (VALUE_HAS_PARENS.equals(name)) {
table.setHasParens(Boolean.valueOf(value).booleanValue());
} else if (VALUE_HAS_STRING_ESCAPES.equals(name)) {
table.setHasStringEscapes(Boolean.valueOf(value).booleanValue());
}
}
} else if (ELEMENT_KEYWORDS.equals(element.getName())) {
boolean ignoreCase = Boolean.valueOf(element.getAttributeValue(ATTRIBUTE_IGNORE_CASE)).booleanValue();
table.setIgnoreCase(ignoreCase);
loadKeywords(element, table.getKeywords1());
} else if (ELEMENT_KEYWORDS2.equals(element.getName())) {
loadKeywords(element, table.getKeywords2());
} else if (ELEMENT_KEYWORDS3.equals(element.getName())) {
loadKeywords(element, table.getKeywords3());
} else if (ELEMENT_KEYWORDS4.equals(element.getName())) {
loadKeywords(element, table.getKeywords4());
}
}
boolean DUMP_TABLE = false;
if (DUMP_TABLE) {
Element element = new Element("temp");
writeTable(element, table);
XMLOutputter outputter = JDOMUtil.createOutputter("\n");
try {
outputter.output((Element) element.getContent().get(0), System.out);
} catch (IOException ignored) {
}
}
return table;
}
Aggregations