Java Code Examples for com.intellij.lang.java.parser.JavaParserUtil

The following are top voted examples for showing how to use com.intellij.lang.java.parser.JavaParserUtil. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: intellij-ce-playground   File: PsiJavaParserFacadeImpl.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final boolean isStaticImport = context instanceof PsiImportStaticStatement &&
                                 !((PsiImportStaticStatement)context).isOnDemand();
  final boolean mayHaveDiamonds = context instanceof PsiNewExpression &&
                                  PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7);
  final JavaParserUtil.ParserWrapper wrapper = isStaticImport ? STATIC_IMPORT_REF : mayHaveDiamonds ? DIAMOND_REF : REFERENCE;
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiJavaCodeReferenceElement)) {
    throw new IncorrectOperationException("Incorrect reference '" + text + "'");
  }
  return (PsiJavaCodeReferenceElement)element;
}
 
Example 2
Project: intellij-ce-playground   File: JavaDummyElement.java   Source Code and License 5 votes vote down vote up
public JavaDummyElement(@Nullable final CharSequence text,
                        @NotNull final JavaParserUtil.ParserWrapper parser,
                        @NotNull final LanguageLevel level,
                        final boolean consumeAll) {
  super(JavaElementType.DUMMY_ELEMENT, text);
  myParser = parser;
  myLanguageLevel = level;
  myConsumeAll = consumeAll;
}
 
Example 3
Project: tools-idea   File: PsiJavaParserFacadeImpl.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final boolean isStaticImport = context instanceof PsiImportStaticStatement &&
                                 !((PsiImportStaticStatement)context).isOnDemand();
  final boolean mayHaveDiamonds = context instanceof PsiNewExpression &&
                                  PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7);
  final JavaParserUtil.ParserWrapper wrapper = isStaticImport ? STATIC_IMPORT_REF : mayHaveDiamonds ? DIAMOND_REF : REFERENCE;
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiJavaCodeReferenceElement)) {
    throw new IncorrectOperationException("Incorrect reference \"" + text + "\".");
  }
  return (PsiJavaCodeReferenceElement)element;
}
 
Example 4
Project: tools-idea   File: JavaDummyElement.java   Source Code and License 5 votes vote down vote up
public JavaDummyElement(@Nullable final CharSequence text,
                        @NotNull final JavaParserUtil.ParserWrapper parser,
                        @NotNull final LanguageLevel level,
                        final boolean consumeAll) {
  super(JavaElementType.DUMMY_ELEMENT, text);
  myParser = parser;
  myLanguageLevel = level;
  myConsumeAll = consumeAll;
}
 
Example 5
Project: consulo-javaee   File: JspJavaFileElementType.java   Source Code and License 5 votes vote down vote up
@NotNull
private PsiBuilder doParse(@NotNull ASTNode chameleon, Project project, LanguageVersion languageVersion)
{
	LanguageLevel languageLevel = LanguageLevel.HIGHEST;
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new JspJavaLexer(languageLevel), JavaLanguage.INSTANCE, languageVersion, chameleon.getChars());
	JavaParserUtil.setLanguageLevel(builder, languageLevel);
	PsiParser parser = new JavaInJspParser();
	parser.parse(this, builder, languageVersion);
	return builder;
}
 
Example 6
Project: consulo-java   File: PsiJavaParserFacadeImpl.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException
{
	final boolean isStaticImport = context instanceof PsiImportStaticStatement && !((PsiImportStaticStatement) context).isOnDemand();
	final boolean mayHaveDiamonds = context instanceof PsiNewExpression && PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7);
	final JavaParserUtil.ParserWrapper wrapper = isStaticImport ? STATIC_IMPORT_REF : mayHaveDiamonds ? DIAMOND_REF : REFERENCE;
	final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context);
	final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
	if(!(element instanceof PsiJavaCodeReferenceElement))
	{
		throw new IncorrectOperationException("Incorrect reference '" + text + "'");
	}
	return (PsiJavaCodeReferenceElement) element;
}
 
Example 7
Project: consulo-java   File: JavaElementType.java   Source Code and License 5 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
	JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true);
	return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 8
Project: consulo-java   File: JavaElementType.java   Source Code and License 5 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon)
{
	final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
	JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true);
	return builder.getLightTree();
}
 
Example 9
Project: consulo-java   File: JavaDummyElement.java   Source Code and License 5 votes vote down vote up
public JavaDummyElement(@Nullable final CharSequence text,
                        @NotNull final JavaParserUtil.ParserWrapper parser,
                        @NotNull final LanguageLevel level,
                        final boolean consumeAll) {
  super(JavaElementType.DUMMY_ELEMENT, text);
  myParser = parser;
  myLanguageLevel = level;
  myConsumeAll = consumeAll;
}
 
Example 10
Project: consulo-java   File: JavaFileElementType.java   Source Code and License 5 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContentsLight(final ASTNode chameleon)
{
	final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
	doParse(builder);
	return builder.getLightTree();
}
 
Example 11
Project: consulo-java   File: JavaFileElementType.java   Source Code and License 5 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
	doParse(builder);
	return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 12
Project: intellij-ce-playground   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3);
}
 
Example 13
Project: intellij-ce-playground   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3);
}
 
Example 14
Project: intellij-ce-playground   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 15
Project: intellij-ce-playground   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true);
  return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 16
Project: intellij-ce-playground   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true);
  return builder.getLightTree();
}
 
Example 17
Project: intellij-ce-playground   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 18
Project: intellij-ce-playground   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 19
Project: intellij-ce-playground   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 20
Project: intellij-ce-playground   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 21
Project: intellij-ce-playground   File: JavaDummyElement.java   Source Code and License 4 votes vote down vote up
public JavaDummyElement(@Nullable final CharSequence text,
                        @NotNull final JavaParserUtil.ParserWrapper parser,
                        @NotNull final LanguageLevel level) {
  this(text, parser, level, false);
}
 
Example 22
Project: intellij-ce-playground   File: JavaDummyElement.java   Source Code and License 4 votes vote down vote up
@NotNull
public JavaParserUtil.ParserWrapper getParser() {
  return myParser;
}
 
Example 23
Project: intellij-ce-playground   File: JavaFileElementType.java   Source Code and License 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContentsLight(final ASTNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  doParse(builder);
  return builder.getLightTree();
}
 
Example 24
Project: intellij-ce-playground   File: JavaFileElementType.java   Source Code and License 4 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  doParse(builder);
  return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 25
Project: tools-idea   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3);
}
 
Example 26
Project: tools-idea   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3);
}
 
Example 27
Project: tools-idea   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 28
Project: tools-idea   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true);
  return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 29
Project: tools-idea   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true);
  return builder.getLightTree();
}
 
Example 30
Project: tools-idea   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 31
Project: tools-idea   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 32
Project: tools-idea   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 33
Project: tools-idea   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 34
Project: tools-idea   File: JavaDummyElement.java   Source Code and License 4 votes vote down vote up
public JavaDummyElement(@Nullable final CharSequence text,
                        @NotNull final JavaParserUtil.ParserWrapper parser,
                        @NotNull final LanguageLevel level) {
  this(text, parser, level, false);
}
 
Example 35
Project: tools-idea   File: JavaDummyElement.java   Source Code and License 4 votes vote down vote up
@NotNull
public JavaParserUtil.ParserWrapper getParser() {
  return myParser;
}
 
Example 36
Project: tools-idea   File: JavaFileElementType.java   Source Code and License 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContentsLight(final ASTNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  doParse(builder);
  return builder.getLightTree();
}
 
Example 37
Project: tools-idea   File: JavaFileElementType.java   Source Code and License 4 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon) {
  final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
  doParse(builder);
  return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 38
Project: consulo-java   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3);
}
 
Example 39
Project: consulo-java   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3);
}
 
Example 40
Project: consulo-java   File: JavaDocElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 41
Project: consulo-java   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 42
Project: consulo-java   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 43
Project: consulo-java   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 44
Project: consulo-java   File: JavaElementType.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon)
{
	return JavaParserUtil.parseFragment(chameleon, myParser);
}
 
Example 45
Project: consulo-java   File: JavaDummyElement.java   Source Code and License 4 votes vote down vote up
public JavaDummyElement(@Nullable final CharSequence text,
                        @NotNull final JavaParserUtil.ParserWrapper parser,
                        @NotNull final LanguageLevel level) {
  this(text, parser, level, false);
}
 
Example 46
Project: consulo-java   File: JavaDummyElement.java   Source Code and License 4 votes vote down vote up
@NotNull
public JavaParserUtil.ParserWrapper getParser() {
  return myParser;
}