本文整理汇总了Java中com.intellij.lang.LanguageFormatting类的典型用法代码示例。如果您正苦于以下问题:Java LanguageFormatting类的具体用法?Java LanguageFormatting怎么用?Java LanguageFormatting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LanguageFormatting类属于com.intellij.lang包,在下文中一共展示了LanguageFormatting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestLineToIndentMapping
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
private static void doTestLineToIndentMapping(@NotNull String text, int... spacesForLine) {
configureFromFileText("x.java", text);
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
Assert.assertNotNull(document);
Assert.assertNotNull(builder);
FormattingModel model = builder.createModel(myFile, CodeStyleSettingsManager.getSettings(getProject()));
Block block = model.getRootBlock();
List<LineIndentInfo> list = new FormatterBasedLineIndentInfoBuilder(document, block).build();
Assert.assertEquals(list.size(), spacesForLine.length);
for (int i = 0; i < spacesForLine.length; i++) {
int indentSize = list.get(i).getIndentSize();
Assert.assertEquals("Mismatch on line " + i, spacesForLine[i], indentSize);
}
}
示例2: setUp
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
myWorkingDirectory = TestFileStructure.createDirectory(getProject(), getSourceRoot(), TEMP_DIR_NAME);
myRealChangeListManager = ChangeListManager.getInstance(getProject());
myMockChangeListManager = new MockChangeListManager();
registerChangeListManager(myMockChangeListManager);
myRealCodeStyleManger = CodeStyleManager.getInstance(getProject());
myMockCodeStyleManager = new MockCodeStyleManager();
registerCodeStyleManager(myMockCodeStyleManager);
myRealVcsContextFactory = ServiceManager.getService(VcsContextFactory.class);
registerVcsContextFactory(new MockVcsContextFactory(getSourceRoot().getFileSystem()));
myMockPlainTextFormattingModelBuilder = new MockPlainTextFormattingModelBuilder();
LanguageFormatting.INSTANCE.addExplicitExtension(PlainTextLanguage.INSTANCE, myMockPlainTextFormattingModelBuilder);
}
示例3: canBeFormatted
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
private static boolean canBeFormatted(PsiFile file) {
if (LanguageFormatting.INSTANCE.forContext(file) == null) {
return false;
}
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return true;
if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;
for (GeneratedSourcesFilter filter : GeneratedSourcesFilter.EP_NAME.getExtensions()) {
if (filter.isGeneratedSource(virtualFile, file.getProject())) {
return false;
}
}
return true;
}
示例4: update
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
DataContext dataContext = event.getDataContext();
Project project = CommonDataKeys.PROJECT.getData(dataContext);
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
if (project == null || editor == null) {
presentation.setEnabled(false);
return;
}
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null || file.getVirtualFile() == null) {
presentation.setEnabled(false);
return;
}
if (LanguageFormatting.INSTANCE.forContext(file) != null) {
presentation.setEnabled(true);
}
}
示例5: indentBlock
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
static void indentBlock(Project project, Editor editor, final int startOffset, final int endOffset, int originalCaretCol) {
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitAllDocuments();
final Document document = editor.getDocument();
PsiFile file = documentManager.getPsiFile(document);
if (file == null) {
return;
}
if (LanguageFormatting.INSTANCE.forContext(file) != null) {
indentBlockWithFormatter(project, document, startOffset, endOffset, file);
}
else {
indentPlainTextBlock(document, startOffset, endOffset, originalCaretCol);
}
}
示例6: addInjectedLanguageBlockWrapper
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
public void addInjectedLanguageBlockWrapper(final List<Block> result, final ASTNode injectedNode,
final Indent indent, int offset, @Nullable TextRange range) {
//
// Do not create a block for an empty range
//
if (range != null) {
if (range.getLength() == 0) return;
if(StringUtil.isEmptyOrSpaces(range.substring(injectedNode.getText()))) {
return;
}
}
final PsiElement childPsi = injectedNode.getPsi();
final Language childLanguage = childPsi.getLanguage();
final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(childLanguage, childPsi);
LOG.assertTrue(builder != null);
final FormattingModel childModel = builder.createModel(childPsi, getSettings());
Block original = childModel.getRootBlock();
if ((original.isLeaf() && !injectedNode.getText().trim().isEmpty()) || !original.getSubBlocks().isEmpty()) {
result.add(createInjectedBlock(injectedNode, original, indent, offset, range, childLanguage));
}
}
示例7: getSignificantRange
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
private static TextRange getSignificantRange(final PsiFile file, final int offset) {
final ASTNode elementAtOffset =
SourceTreeToPsiMap.psiElementToTree(CodeStyleManagerImpl.findElementInTreeWithFormatterEnabled(file, offset));
if (elementAtOffset == null) {
int significantRangeStart = CharArrayUtil.shiftBackward(file.getText(), offset - 1, "\r\t ");
return new TextRange(Math.max(significantRangeStart, 0), offset);
}
final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(file);
final TextRange textRange = builder.getRangeAffectingIndent(file, offset, elementAtOffset);
if (textRange != null) {
return textRange;
}
return elementAtOffset.getTextRange();
}
示例8: getRootBlock
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
protected Block getRootBlock(PsiElement element, FileViewProvider viewProvider, CodeStyleSettings settings) {
ASTNode node = element.getNode();
if (node == null) {
return createDummyBlock(node);
}
if (viewProvider instanceof TemplateLanguageFileViewProvider) {
final Language dataLanguage = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage();
final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(dataLanguage);
if (builder instanceof DelegatingFormattingModelBuilder && ((DelegatingFormattingModelBuilder)builder).dontFormatMyModel()) {
return createDummyBlock(node);
}
if (builder != null) {
final FormattingModel model = builder.createModel(viewProvider.getPsi(dataLanguage), settings);
List<DataLanguageBlockWrapper> childWrappers = buildChildWrappers(model.getRootBlock());
if (childWrappers.size() == 1) {
childWrappers = buildChildWrappers(childWrappers.get(0).getOriginal());
}
return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null,
filterBlocksByRange(childWrappers, node.getTextRange()), settings);
}
}
return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, Collections.<DataLanguageBlockWrapper>emptyList(), settings);
}
示例9: initComponent
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
@SuppressWarnings({"StringEquality"})
public void initComponent() {
final Language xmlLang = StdFileTypes.XML.getLanguage();
// intentionManager.addAction(new DeleteUnusedParameterFix());
// intentionManager.addAction(new DeleteUnusedVariableFix());
final XsltFormattingModelBuilder builder = new XsltFormattingModelBuilder(LanguageFormatting.INSTANCE.forLanguage(xmlLang));
LanguageFormatting.INSTANCE.addExplicitExtension(xmlLang, builder);
try {
// TODO: put this into com.intellij.refactoring.actions.IntroduceParameterAction, just like IntroduceVariableAction
ActionManager.getInstance().getAction("IntroduceParameter").setInjectedContext(true);
}
catch (Exception e) {
Logger.getInstance(XsltConfigImpl.class.getName()).error(e);
}
}
示例10: createModel
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
if(element instanceof JSFile || element.getContainingFile() instanceof JSFile) {
final JSFile file = (JSFile)(element instanceof JSFile ? element : element.getContainingFile());
file.putUserData(WANT_DEFAULT_FORMATTER_KEY, true);
try {
final FormattingModelBuilder formattingModelBuilder = LanguageFormatting.INSTANCE.forContext(file.getLanguage(), element);
if (formattingModelBuilder != null) {
final FormattingModel model = formattingModelBuilder.createModel(element, settings);
final Block rootBlock = model.getRootBlock();
return new DelegatingFormattingModel(model, new JSGraphQLBlockWrapper(rootBlock, null, element.getNode(), rootBlock.getWrap(), rootBlock.getAlignment(), createSpaceBuilder(settings, element), settings));
}
} finally {
file.putUserData(WANT_DEFAULT_FORMATTER_KEY, null);
}
}
throw new IllegalArgumentException("Unsupported element '" + element + "'. It must be an element in a JSFile with its own default formatter to support injected GraphQL formatting");
}
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:20,代码来源:JSGraphQLInjectedFormattingModelBuilder.java
示例11: addInjectedLanguageBlockWrapper
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
public void addInjectedLanguageBlockWrapper(final List<Block> result, final ASTNode injectedNode,
final Indent indent, int offset, @Nullable TextRange range) {
//
// Do not create a block for an empty range
//
if (range != null) {
if (range.getLength() == 0) return;
if(StringUtil.isEmptyOrSpaces(range.substring(injectedNode.getText()))) {
return;
}
}
final PsiElement childPsi = injectedNode.getPsi();
final Language childLanguage = childPsi.getLanguage();
final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(childLanguage, childPsi);
LOG.assertTrue(builder != null);
final FormattingModel childModel = builder.createModel(childPsi, getSettings());
Block original = childModel.getRootBlock();
if ((original.isLeaf() && injectedNode.getText().trim().length() > 0) || original.getSubBlocks().size() != 0) {
result.add(createInjectedBlock(injectedNode, original, indent, offset, range, childLanguage));
}
}
示例12: getSignificantRange
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
private static TextRange getSignificantRange(final PsiFile file, final int offset) {
final ASTNode elementAtOffset =
SourceTreeToPsiMap.psiElementToTree(CodeStyleManagerImpl.findElementInTreeWithFormatterEnabled(file, offset));
if (elementAtOffset == null) {
int significantRangeStart = CharArrayUtil.shiftBackward(file.getText(), offset - 1, "\r\t ");
return new TextRange(significantRangeStart, offset);
}
final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(file);
final TextRange textRange = builder.getRangeAffectingIndent(file, offset, elementAtOffset);
if (textRange != null) {
return textRange;
}
return elementAtOffset.getTextRange();
}
示例13: initComponent
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@SuppressWarnings({ "StringEquality" })
public void initComponent() {
final Language xmlLang = StdFileTypes.XML.getLanguage();
// intentionManager.addAction(new DeleteUnusedParameterFix());
// intentionManager.addAction(new DeleteUnusedVariableFix());
final XsltFormattingModelBuilder builder = new XsltFormattingModelBuilder(LanguageFormatting.INSTANCE.forLanguage(xmlLang));
LanguageFormatting.INSTANCE.addExplicitExtension(xmlLang, builder);
try {
// TODO: put this into com.intellij.refactoring.actions.IntroduceParameterAction, just like IntroduceVariableAction
ActionManager.getInstance().getAction("IntroduceParameter").setInjectedContext(true);
} catch (Exception e) {
Logger.getInstance(XsltConfigImpl.class.getName()).error(e);
}
}
示例14: update
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
DataContext dataContext = event.getDataContext();
Project project = dataContext.getData(CommonDataKeys.PROJECT);
Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
if (project == null || editor == null) {
presentation.setEnabled(false);
return;
}
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null || file.getVirtualFile() == null) {
presentation.setEnabled(false);
return;
}
if (LanguageFormatting.INSTANCE.forContext(file) != null) {
presentation.setEnabled(true);
}
}
示例15: initComponent
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@SuppressWarnings({ "StringEquality" })
public void initComponent() {
final Language xmlLang = XMLLanguage.INSTANCE;
// intentionManager.addAction(new DeleteUnusedParameterFix());
// intentionManager.addAction(new DeleteUnusedVariableFix());
final XsltFormattingModelBuilder builder = new XsltFormattingModelBuilder(LanguageFormatting.INSTANCE.forLanguage(xmlLang));
LanguageFormatting.INSTANCE.addExplicitExtension(xmlLang, builder);
try {
// TODO: put this into com.intellij.refactoring.actions.IntroduceParameterAction, just like IntroduceVariableAction
ActionManager.getInstance().getAction("IntroduceParameter").setInjectedContext(true);
} catch (Exception e) {
Logger.getInstance(XsltConfigImpl.class.getName()).error(e);
}
}