• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DocumentBasedFormattingModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.psi.formatter.DocumentBasedFormattingModel的典型用法代码示例。如果您正苦于以下问题:Java DocumentBasedFormattingModel类的具体用法?Java DocumentBasedFormattingModel怎么用?Java DocumentBasedFormattingModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DocumentBasedFormattingModel类属于com.intellij.psi.formatter包,在下文中一共展示了DocumentBasedFormattingModel类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
/**
 * We have to override {@link com.intellij.formatting.templateLanguages.TemplateLanguageFormattingModelBuilder#createModel}
 * since after we delegate to some templated languages, those languages (xml/html for sure, potentially others)
 * delegate right back to us to format the DustTypes.OUTER_TYPE token we tell them to ignore,
 * causing an stack-overflowing loop.
 */
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {

  final PsiFile file = element.getContainingFile();
  Block rootBlock;

  ASTNode node = element.getNode();

  if (node.getElementType() == DustFileViewProvider.OUTER_TYPE) {
    // If we're looking at a DustTypes.HTML element, then we've been invoked by our templated
    // language.  Make a dummy block to allow that formatter to continue
    return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
  } else {
    rootBlock = getRootBlock(file, file.getViewProvider(), settings);
  }

  return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file);
}
 
开发者ID:yifanz,项目名称:Intellij-Dust,代码行数:25,代码来源:DustFormattingModelBuilder.java


示例2: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  final PsiFile file = element.getContainingFile();

  if (element.getNode().getElementType() == SoyTypes.OTHER) {
    return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
  } else {
    return new DocumentBasedFormattingModel(
        getRootBlock(file, file.getViewProvider(), settings),
        element.getProject(),
        settings,
        file.getFileType(),
        file);
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:16,代码来源:SoyFormattingModelBuilder.java


示例3: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    final PsiFile file = element.getContainingFile();
    Block rootBlock;
    ASTNode node = element.getNode();
    if (node.getElementType() == RYTHM) {
        return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);

    } else {
        rootBlock = getRootBlock(file, file.getViewProvider(), settings);
    }
    return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file);
}
 
开发者ID:scireum-incubator,项目名称:rythm_plugin,代码行数:14,代码来源:RythmFormattingModelBuilder.java


示例4: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
  if (element instanceof PsiFile) {
    final FileViewProvider viewProvider = ((PsiFile)element).getViewProvider();
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
      final Language language = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage();
      FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language);
      if (builder != null) {
        return builder.createModel(viewProvider.getPsi(language), settings);
      }
    }
  }

  final PsiFile file = element.getContainingFile();
  return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {
    @Override
    protected List<Block> buildChildren() {
      return Collections.emptyList();
    }

    @Override
    public Spacing getSpacing(final Block child1, @NotNull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  }, element.getProject(), settings, file.getFileType(), file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:SimpleTemplateLanguageFormattingModelBuilder.java


示例5: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  final PsiFile file = element.getContainingFile();
  Block rootBlock = getRootBlock(file, file.getViewProvider(), settings);
  return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:TemplateLanguageFormattingModelBuilder.java


示例6: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@NotNull
@Override
public FormattingModel createModel(@NotNull final PsiElement element, @NotNull final CodeStyleSettings settings) {
    final PsiFile psiFile = element.getContainingFile();
    final ASTNode rootNode = psiFile instanceof SquirrelFile ? psiFile.getNode() : element.getNode();
    final SquirrelBlock rootBlock = new SquirrelBlock(rootNode, null, null, settings);
    return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, psiFile.getFileType(), psiFile);
}
 
开发者ID:shvetsgroup,项目名称:squirrel-lang-idea-plugin,代码行数:9,代码来源:SquirrelFormattingModelBuilder.java


示例7: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
@Nonnull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
  if (element instanceof PsiFile) {
    final FileViewProvider viewProvider = ((PsiFile)element).getViewProvider();
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
      final Language language = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage();
      FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language);
      if (builder != null) {
        return builder.createModel(viewProvider.getPsi(language), settings);
      }
    }
  }

  final PsiFile file = element.getContainingFile();
  return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {
    @Override
    protected List<Block> buildChildren() {
      return Collections.emptyList();
    }

    @Override
    public Spacing getSpacing(final Block child1, @Nonnull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  }, element.getProject(), settings, file.getFileType(), file);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:33,代码来源:SimpleTemplateLanguageFormattingModelBuilder.java


示例8: createModel

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
@Nonnull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  final PsiFile file = element.getContainingFile();
  Block rootBlock = getRootBlock(file, file.getViewProvider(), settings);
  return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:8,代码来源:TemplateLanguageFormattingModelBuilder.java


示例9: replaceWithPsiInLeaf

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
protected String replaceWithPsiInLeaf(final TextRange textRange, String whiteSpace, ASTNode leafElement) {
   if (!myCanModifyAllWhiteSpaces) {
     if (leafElement.getElementType() == TokenType.WHITE_SPACE) return null;
     ASTNode prevNode = TreeUtil.prevLeaf(leafElement);

     if (prevNode != null) {
       IElementType type = prevNode.getElementType();
       if(type == TokenType.WHITE_SPACE) {
         final String text = prevNode.getText();

         @NonNls final String cdataStartMarker = "<![CDATA[";
         final int cdataPos = text.indexOf(cdataStartMarker);
         if (cdataPos != -1 && whiteSpace.indexOf(cdataStartMarker) == -1) {
           whiteSpace = DocumentBasedFormattingModel.mergeWsWithCdataMarker(whiteSpace, text, cdataPos);
           if (whiteSpace == null) return null;
         }

         prevNode = TreeUtil.prevLeaf(prevNode);
         type = prevNode != null ? prevNode.getElementType():null;
       }

       @NonNls final String cdataEndMarker = "]]>";
       if(type == XmlTokenType.XML_CDATA_END && whiteSpace.indexOf(cdataEndMarker) == -1) {
         final ASTNode at = findElementAt(prevNode.getStartOffset());

         if (at != null && at.getPsi() instanceof PsiWhiteSpace) {
           final String s = at.getText();
           final int cdataEndPos = s.indexOf(cdataEndMarker);
           whiteSpace = DocumentBasedFormattingModel.mergeWsWithCdataMarker(whiteSpace, s, cdataEndPos);
           leafElement = at;
         } else {
           whiteSpace = null;
         }
         if (whiteSpace == null) return null;
       }
     }
   }
   FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, TokenType.WHITE_SPACE, textRange);
   return whiteSpace;
 }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:PsiBasedFormatterModelWithShiftIndentInside.java


示例10: replaceWithPsiInLeaf

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
protected String replaceWithPsiInLeaf(final TextRange textRange, String whiteSpace, ASTNode leafElement) {
   if (!myCanModifyAllWhiteSpaces) {
     if (leafElement.getElementType() == TokenType.WHITE_SPACE) return null;
     ASTNode prevNode = TreeUtil.prevLeaf(leafElement);

     if (prevNode != null) {
       IElementType type = prevNode.getElementType();
       if(type == TokenType.WHITE_SPACE) {
         final String text = prevNode.getText();

         final @NonNls String cdataStartMarker = "<![CDATA[";
         final int cdataPos = text.indexOf(cdataStartMarker);
         if (cdataPos != -1 && whiteSpace.indexOf(cdataStartMarker) == -1) {
           whiteSpace = DocumentBasedFormattingModel.mergeWsWithCdataMarker(whiteSpace, text, cdataPos);
           if (whiteSpace == null) return null;
         }

         prevNode = TreeUtil.prevLeaf(prevNode);
         type = prevNode != null ? prevNode.getElementType():null;
       }

       final @NonNls String cdataEndMarker = "]]>";
       if(type == XmlElementType.XML_CDATA_END && whiteSpace.indexOf(cdataEndMarker) == -1) {
         final ASTNode at = findElementAt(prevNode.getStartOffset());

         if (at != null && at.getPsi() instanceof PsiWhiteSpace) {
           final String s = at.getText();
           final int cdataEndPos = s.indexOf(cdataEndMarker);
           whiteSpace = DocumentBasedFormattingModel.mergeWsWithCdataMarker(whiteSpace, s, cdataEndPos);
           leafElement = at;
         } else {
           whiteSpace = null;
         }
         if (whiteSpace == null) return null;
       }
     }
   }
   FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, TokenType.WHITE_SPACE, textRange);
   return whiteSpace;
 }
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:42,代码来源:PsiBasedFormatterModelWithShiftIndentInside.java


示例11: replaceWithPsiInLeaf

import com.intellij.psi.formatter.DocumentBasedFormattingModel; //导入依赖的package包/类
@Override
protected String replaceWithPsiInLeaf(final TextRange textRange, String whiteSpace, ASTNode leafElement)
{
	if(!myCanModifyAllWhiteSpaces)
	{
		if(leafElement.getElementType() == TokenType.WHITE_SPACE)
		{
			return null;
		}
		ASTNode prevNode = TreeUtil.prevLeaf(leafElement);

		if(prevNode != null)
		{
			IElementType type = prevNode.getElementType();
			if(type == TokenType.WHITE_SPACE)
			{
				final String text = prevNode.getText();

				@NonNls final String cdataStartMarker = "<![CDATA[";
				final int cdataPos = text.indexOf(cdataStartMarker);
				if(cdataPos != -1 && whiteSpace.indexOf(cdataStartMarker) == -1)
				{
					whiteSpace = DocumentBasedFormattingModel.mergeWsWithCdataMarker(whiteSpace, text, cdataPos);
					if(whiteSpace == null)
					{
						return null;
					}
				}

				prevNode = TreeUtil.prevLeaf(prevNode);
				type = prevNode != null ? prevNode.getElementType() : null;
			}

			@NonNls final String cdataEndMarker = "]]>";
			if(type == XmlTokenType.XML_CDATA_END && whiteSpace.indexOf(cdataEndMarker) == -1)
			{
				final ASTNode at = findElementAt(prevNode.getStartOffset());

				if(at != null && at.getPsi() instanceof PsiWhiteSpace)
				{
					final String s = at.getText();
					final int cdataEndPos = s.indexOf(cdataEndMarker);
					whiteSpace = DocumentBasedFormattingModel.mergeWsWithCdataMarker(whiteSpace, s, cdataEndPos);
					leafElement = at;
				}
				else
				{
					whiteSpace = null;
				}
				if(whiteSpace == null)
				{
					return null;
				}
			}
		}
	}
	FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, TokenType.WHITE_SPACE, textRange);
	return whiteSpace;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:60,代码来源:PsiBasedFormatterModelWithShiftIndentInside.java



注:本文中的com.intellij.psi.formatter.DocumentBasedFormattingModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DateFormatterRegistrar类代码示例发布时间:2022-05-23
下一篇:
Java SpringServletContainerInitializer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap