当前位置: 首页>>代码示例>>Java>>正文


Java PsiJavaFileImpl类代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:PsiClassUtil.java

示例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;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:20,代码来源:ExtensionClassAnnotator.java

示例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);
}
 
开发者ID:wangjiegulu,项目名称:AndroidParcelablePlugin,代码行数:24,代码来源:ParcelableGenerator.java

示例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();


}
 
开发者ID:wangjiegulu,项目名称:AndroidParcelablePlugin,代码行数:36,代码来源:ParcelableGenerator.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo-ikvm,代码行数:39,代码来源:JavaRepresentationProvider.java

示例6: createFile

import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
@Override
public PsiFile createFile(final FileViewProvider viewProvider) {
  return new PsiJavaFileImpl(viewProvider);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:JavaParserDefinition.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:64,代码来源:InnerClassesScannerTest.java

示例8: createFile

import com.intellij.psi.impl.source.PsiJavaFileImpl; //导入依赖的package包/类
@Override
public PsiFile createFile(@NotNull final FileViewProvider viewProvider)
{
	return new PsiJavaFileImpl(viewProvider);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:6,代码来源:JavaParserDefinition.java


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