本文整理汇总了Java中com.intellij.lang.LanguageFormatting类的典型用法代码示例。如果您正苦于以下问题:Java LanguageFormatting类的具体用法?Java LanguageFormatting怎么用?Java LanguageFormatting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LanguageFormatting类属于com.intellij.lang包,在下文中一共展示了LanguageFormatting类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JavaAutoDetectIndentTest.java
示例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);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ReformatOnlyVcsChangedTextTest.java
示例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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AbstractLayoutCodeProcessor.java
示例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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ShowReformatFileDialog.java
示例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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PasteHandler.java
示例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));
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:InjectedLanguageBlockBuilder.java
示例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();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CodeStyleManagerRunnable.java
示例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);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:TemplateLanguageFormattingModelBuilder.java
示例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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:XsltConfigImpl.java
示例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));
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:InjectedLanguageBlockBuilder.java
示例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();
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:CodeStyleManagerRunnable.java
示例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);
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:XsltConfigImpl.java
示例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);
}
}
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:ShowReformatFileDialog.java
示例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);
}
}
开发者ID:consulo,项目名称:consulo-xslt,代码行数:18,代码来源:XsltConfigImpl.java
示例16: newLineBlockIterator
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@NotNull
protected static Iterator<Block> newLineBlockIterator() {
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
Assert.assertNotNull(builder);
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
FormattingModel model = builder.createModel(myFile, settings);
Block root = model.getRootBlock();
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
Assert.assertNotNull(document);
return new NewLineBlocksIterator(root, document);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:AbstractNewLineBlocksIteratorTest.java
示例17: tearDown
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
public void tearDown() throws Exception {
registerChangeListManager(myRealChangeListManager);
registerCodeStyleManager(myRealCodeStyleManger);
registerVcsContextFactory(myRealVcsContextFactory);
LanguageFormatting.INSTANCE.removeExplicitExtension(PlainTextLanguage.INSTANCE, myMockPlainTextFormattingModelBuilder);
TestFileStructure.delete(myWorkingDirectory.getVirtualFile());
super.tearDown();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ReformatOnlyVcsChangedTextTest.java
示例18: setUp
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
myWorkingDirectory = TestFileStructure.createDirectory(getProject(), getSourceRoot(), TEMP_DIR_NAME);
myRealCodeStyleManger = CodeStyleManager.getInstance(getProject());
myMockCodeStyleManager = new MockCodeStyleManager();
registerCodeStyleManager(myMockCodeStyleManager);
myMockPlainTextFormattingModelBuilder = new MockPlainTextFormattingModelBuilder();
LanguageFormatting.INSTANCE.addExplicitExtension(PlainTextLanguage.INSTANCE, myMockPlainTextFormattingModelBuilder);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ReformatFilesWithFiltersTest.java
示例19: tearDown
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@Override
public void tearDown() throws Exception {
if (myRealCodeStyleManger != null) registerCodeStyleManager(myRealCodeStyleManger);
if (myMockPlainTextFormattingModelBuilder != null) {
LanguageFormatting.INSTANCE.removeExplicitExtension(PlainTextLanguage.INSTANCE, myMockPlainTextFormattingModelBuilder);
}
if (myWorkingDirectory != null) TestFileStructure.delete(myWorkingDirectory.getVirtualFile());
super.tearDown();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ReformatFilesWithFiltersTest.java
示例20: getMaxUsedIndentInfo
import com.intellij.lang.LanguageFormatting; //导入依赖的package包/类
@NotNull
private IndentUsageInfo getMaxUsedIndentInfo() {
configureByFile(getFileNameWithExtension());
Document document = getDocument(myFile);
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
Assert.assertNotNull(builder);
FormattingModel model = builder.createModel(myFile, CodeStyleSettingsManager.getSettings(getProject()));
List<LineIndentInfo> lines = new FormatterBasedLineIndentInfoBuilder(document, model.getRootBlock()).build();
IndentUsageStatistics statistics = new IndentUsageStatisticsImpl(lines);
return statistics.getKMostUsedIndentInfo(0);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:AbstractIndentAutoDetectionTest.java
注:本文中的com.intellij.lang.LanguageFormatting类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论