本文整理汇总了Java中com.intellij.psi.impl.source.PsiJavaFileImpl类的典型用法代码示例。如果您正苦于以下问题:Java PsiJavaFileImpl类的具体用法?Java PsiJavaFileImpl怎么用?Java PsiJavaFileImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiJavaFileImpl类属于com.intellij.psi.impl.source包,在下文中一共展示了PsiJavaFileImpl类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJavaSrc
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
public static PsiDirectory getJavaSrc(PsiFile psiFile) {
PsiDirectory psiDirectory = null;
if (psiFile instanceof PsiJavaFileImpl) {
String packageName = ((PsiJavaFileImpl) psiFile).getPackageName();
String[] arg = packageName.split("\\.");
psiDirectory = psiFile.getContainingDirectory();
for (int i = 0; i < arg.length; i++) {
psiDirectory = psiDirectory.getParent();
if (psiDirectory == null) {
break;
}
}
}
return psiDirectory;
}
示例2: findExtensionClass
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
private PsiClass findExtensionClass( PsiElement element )
{
PsiFile containingFile = element.getContainingFile();
if( !(containingFile instanceof PsiJavaFileImpl) )
{
return null;
}
PsiJavaFileImpl file = (PsiJavaFileImpl)containingFile;
for( PsiClass psiClass : file.getClasses() )
{
if( psiClass.getModifierList().findAnnotation( Extension.class.getName() ) != null )
{
return psiClass;
}
}
return null;
}
示例3: getPsiClassFromContext
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
/**
* Get parent which the cursor locate.
*
* @return
*/
private PsiClass getPsiClassFromContext() {
// Get all classes in current file.
PsiClass[] classes = ((PsiJavaFileImpl) psiFile).getClasses();
int len = classes.length;
// Return null if there is no class in this file
if (len <= 0) {
return null;
}
// If there is only one class in this file, return it directly.
if (1 == len) {
return classes[0];
}
// If there is more than one classes, return the class which cursor located.
int offset = editor.getCaretModel().getOffset(); // the location of cursor.
PsiElement elementAt = psiFile.findElementAt(offset);
return PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
}
示例4: actionPerformed
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
public void actionPerformed(AnActionEvent e) {
project = e.getProject();
if (null == project) {
return;
}
PsiFile pf = e.getData(LangDataKeys.PSI_FILE);
editor = e.getData(PlatformDataKeys.EDITOR);
if (pf == null || editor == null) {
return;
}
if (!(pf instanceof PsiJavaFileImpl)) {
return;
}
psiFile = (PsiJavaFileImpl) pf;
final PsiClass targetPsiClass = getPsiClassFromContext();
if (null == targetPsiClass) {
return;
}
factory = JavaPsiFacade.getElementFactory(project);
new WriteCommandAction.Simple(project, targetPsiClass.getContainingFile()) {
@Override
protected void run() throws Throwable {
startGenerate(targetPsiClass);
}
}.execute();
}
示例5: transform
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
@NotNull
@Override
@RequiredReadAction
public PsiFile transform(String fileName, @NotNull MsilFile msilFile)
{
DotNetNamedElement[] members = msilFile.getMembers();
StringBuilder builder = new StringBuilder();
for(DotNetNamedElement member : members)
{
JavaClassStubBuilder build = StubBuilder.build((DotNetTypeDeclaration) member);
if(build == null)
{
continue;
}
build.buildToText(builder, null);
builder.append("\n");
}
VirtualFile virtualFile = new MsilFileRepresentationVirtualFile(fileName, JavaFileType.INSTANCE, builder);
SingleRootFileViewProvider viewProvider = new SingleRootFileViewProvider(PsiManager.getInstance(msilFile.getProject()), virtualFile, true);
final PsiJavaFileImpl file = new PsiJavaFileImpl(viewProvider);
viewProvider.forceCachedPsi(file);
((PsiManagerEx) PsiManager.getInstance(msilFile.getProject())).getFileManager().setViewProvider(virtualFile, viewProvider);
new WriteCommandAction.Simple<Object>(file.getProject(), file)
{
@Override
protected void run() throws Throwable
{
CodeStyleManager.getInstance(getProject()).reformat(file);
}
}.execute();
return file;
}
示例6: createFile
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
@Override
public PsiFile createFile(final FileViewProvider viewProvider) {
return new PsiJavaFileImpl(viewProvider);
}
示例7: mayContainClassesInside
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
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;
}
示例8: createFile
import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
@Override
public PsiFile createFile(@NotNull final FileViewProvider viewProvider)
{
return new PsiJavaFileImpl(viewProvider);
}