use of com.intellij.psi.impl.source.PsiJavaFileImpl in project intellij-community by JetBrains.
the class JavaParsingTestCase method createPsiFile.
private PsiFile createPsiFile(final String name, final String text, final TestParser parser) {
if (TEST_FILE_ELEMENT_TYPE == null) {
TEST_FILE_ELEMENT_TYPE = new MyIFileElementType();
}
TEST_PARSER = parser;
final LightVirtualFile virtualFile = new LightVirtualFile(name + '.' + myFileExt, StdFileTypes.JAVA, text, -1);
final FileViewProvider viewProvider = new SingleRootFileViewProvider(PsiManager.getInstance(getProject()), virtualFile, true);
return new PsiJavaFileImpl(viewProvider) {
@NotNull
@Override
protected FileElement createFileElement(@NotNull final CharSequence text) {
return new FileElement(TEST_FILE_ELEMENT_TYPE, text);
}
};
}
use of com.intellij.psi.impl.source.PsiJavaFileImpl in project intellij-community by JetBrains.
the class InnerClassesScannerTest method mayContainClassesInside.
private static boolean mayContainClassesInside(PsiElement psiElement, final CharSequence fileBuffer) {
PsiFile psiFile = psiElement.getContainingFile();
boolean mayHaveClassesInside = false;
if (psiFile instanceof PsiJavaFileImpl) {
Lexer originalLexer = JavaParserDefinition.createLexer(((PsiJavaFileImpl) psiFile).getLanguageLevel());
FilterLexer lexer = new FilterLexer(originalLexer, new FilterLexer.SetFilter(StdTokenSets.WHITE_SPACE_OR_COMMENT_BIT_SET));
final TextRange range = psiElement.getTextRange();
lexer.start(fileBuffer, range.getStartOffset(), range.getEndOffset());
boolean isInNewExpression = false;
boolean isRightAfterNewExpression = false;
int angleLevel = 0;
int parenLevel = 0;
do {
IElementType tokenType = lexer.getTokenType();
if (tokenType == null)
break;
if (tokenType == JavaTokenType.NEW_KEYWORD) {
isInNewExpression = true;
} else if (tokenType == JavaTokenType.LPARENTH) {
if (isInNewExpression)
parenLevel++;
} else if (tokenType == JavaTokenType.LT) {
if (isInNewExpression)
angleLevel++;
} else if (tokenType == JavaTokenType.GT) {
if (isInNewExpression)
angleLevel--;
} else if (tokenType == JavaTokenType.RPARENTH) {
if (isInNewExpression) {
parenLevel--;
if (parenLevel == 0) {
isRightAfterNewExpression = true;
}
}
} else if (tokenType == JavaTokenType.LBRACE) {
if (isInNewExpression || isRightAfterNewExpression) {
mayHaveClassesInside = true;
}
} else if (tokenType == JavaTokenType.LBRACKET) {
if (parenLevel == 0 && angleLevel == 0)
isInNewExpression = false;
} else if (tokenType == JavaTokenType.INTERFACE_KEYWORD || tokenType == JavaTokenType.CLASS_KEYWORD || tokenType == JavaTokenType.ENUM_KEYWORD) {
mayHaveClassesInside = true;
}
if (isInNewExpression && isRightAfterNewExpression) {
isInNewExpression = false;
} else {
isRightAfterNewExpression = false;
}
lexer.advance();
} while (!mayHaveClassesInside);
}
return mayHaveClassesInside;
}
Aggregations