@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; }
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; }
@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; }
@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; }
@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; }
@Override public ASTNode parseContents(final ASTNode chameleon) { final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon); JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true); return builder.getTreeBuilt().getFirstChildNode(); }
@Override public FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon) { final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon); JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true); return builder.getLightTree(); }
@Override public FlyweightCapableTreeStructure<LighterASTNode> parseContentsLight(final ASTNode chameleon) { final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon); doParse(builder); return builder.getLightTree(); }
@Override public ASTNode parseContents(final ASTNode chameleon) { final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon); doParse(builder); return builder.getTreeBuilt().getFirstChildNode(); }
@Nullable @Override public ASTNode parseContents(final ASTNode chameleon) { return JavaParserUtil.parseFragment(chameleon, myParser, false, LanguageLevel.JDK_1_3); }
@Nullable @Override public ASTNode parseContents(final ASTNode chameleon) { return JavaParserUtil.parseFragment(chameleon, myParser); }
public JavaDummyElement(@Nullable final CharSequence text, @NotNull final JavaParserUtil.ParserWrapper parser, @NotNull final LanguageLevel level) { this(text, parser, level, false); }
@NotNull public JavaParserUtil.ParserWrapper getParser() { return myParser; }