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


Java PsiJavaFile.getClasses方法代码示例

本文整理汇总了Java中com.intellij.psi.PsiJavaFile.getClasses方法的典型用法代码示例。如果您正苦于以下问题:Java PsiJavaFile.getClasses方法的具体用法?Java PsiJavaFile.getClasses怎么用?Java PsiJavaFile.getClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.PsiJavaFile的用法示例。


在下文中一共展示了PsiJavaFile.getClasses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTemplateText

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Nullable
public String getTemplateText(final PsiFile psiFile, String fileText, String nameWithoutExtension) {
  if(psiFile instanceof PsiJavaFile){
    PsiJavaFile javaFile = (PsiJavaFile)psiFile;
    String packageName = javaFile.getPackageName();
    if (packageName.length() > 0){
      fileText = StringUtil.replace(fileText, packageName, "${PACKAGE_NAME}");
    }
    PsiClass[] classes = javaFile.getClasses();
    PsiClass psiClass = null;
    if((classes.length > 0)){
      for (PsiClass aClass : classes) {
        if (nameWithoutExtension.equals(aClass.getName())) {
          psiClass = aClass;
          break;
        }
      }
    }
    if(psiClass != null){
      //todo[myakovlev] ? PsiIdentifier nameIdentifier = psiClass.getNameIdentifier();
      return StringUtil.replace(fileText, nameWithoutExtension,"${NAME}");
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:SaveJavaAsTemplateHandler.java

示例2: buildFix

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
  final PsiJavaFile file = (PsiJavaFile)infos[0];
  final String fileName = file.getName();
  final int prefixIndex = fileName.indexOf((int)'.');
  final String filenameWithoutPrefix = fileName.substring(0, prefixIndex);
  final PsiClass[] classes = file.getClasses();
  for (PsiClass psiClass : classes) {
    final String className = psiClass.getName();
    if (filenameWithoutPrefix.equals(className)) {
      return null;
    }
  }
  return new RenameFix(filenameWithoutPrefix);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ClassNameDiffersFromFileNameInspection.java

示例3: adjustElement

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Nullable
public PsiElement adjustElement(final PsiElement psiElement) {
  final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
  final PsiFile containingFile = psiElement.getContainingFile();
  if (containingFile != null) {
    final VirtualFile file = containingFile.getVirtualFile();
    if (file != null && (index.isInSourceContent(file) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
      if (psiElement instanceof PsiJavaFile) {
        final PsiJavaFile psiJavaFile = (PsiJavaFile)psiElement;
        if (psiJavaFile.getViewProvider().getBaseLanguage() == JavaLanguage.INSTANCE) {
          final PsiClass[] psiClasses = psiJavaFile.getClasses();
          if (psiClasses.length == 1) {
            return psiClasses[0];
          }
        }
      }
      if (psiElement instanceof PsiClass) return psiElement;
    }
    return containingFile;
  }
  return psiElement.isPhysical() ? psiElement : null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:JavaNavBarExtension.java

示例4: buildFix

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos)
{
	final PsiJavaFile file = (PsiJavaFile) infos[0];
	final String fileName = file.getName();
	final int prefixIndex = fileName.indexOf((int) '.');
	final String filenameWithoutPrefix = fileName.substring(0, prefixIndex);
	final PsiClass[] classes = file.getClasses();
	for(PsiClass psiClass : classes)
	{
		final String className = psiClass.getName();
		if(filenameWithoutPrefix.equals(className))
		{
			return null;
		}
	}
	return new RenameFix(filenameWithoutPrefix);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:ClassNameDiffersFromFileNameInspection.java

示例5: changeClassTextAndTryToNavigate

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
private static void changeClassTextAndTryToNavigate(final String newClassString,
		PsiJavaFile psiFile,
		final AbstractProjectViewPSIPane pane,
		final String expected) throws IOException, InterruptedException
{
	PsiClass psiClass = psiFile.getClasses()[0];
	final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
	final JTree tree = pane.getTree();
	writeToFile(virtualFile, newClassString.getBytes());

	PlatformTestUtil.waitForAlarm(600);

	psiClass = psiFile.getClasses()[0];
	pane.select(psiClass, virtualFile, true);
	PlatformTestUtil.assertTreeEqual(tree, expected, true);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:NavigateFromSourceTest.java

示例6: isInterfaceMadeStructuralByExtension

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
private boolean isInterfaceMadeStructuralByExtension( PsiClass psiInterface, ManModule module )
{
  final String fqn = psiInterface.getQualifiedName();
  ManModule manModule = ManProject.getModule( module.getIjModule() );
  for( ITypeManifold sp : manModule.getTypeManifolds() )
  {
    if( sp.getProducerKind() == Supplemental )
    {
      if( sp.isType( fqn ) )
      {
        List<IFile> files = sp.findFilesForType( fqn );
        for( IFile file : files )
        {
          VirtualFile vExtensionClassFile = ((IjFile)file).getVirtualFile();
          if( !vExtensionClassFile.isValid() )
          {
            continue;
          }

          PsiJavaFile psiExtClassJavaFile =
            (PsiJavaFile)PsiManager.getInstance( module.getIjModule().getProject() ).findFile( vExtensionClassFile );
          PsiClass[] classes = psiExtClassJavaFile.getClasses();
          if( classes.length > 0 )
          {
            PsiClass psiExtClass = classes[0];
            if( psiExtClass.getModifierList().findAnnotation( Structural.class.getName() ) != null )
            {
              return true;
            }
          }
        }
      }
    }
  }
  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:37,代码来源:ExtensionClassAnnotator.java

示例7: createPsiClass

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
private PsiClass createPsiClass( ManModule module, String fqn, String source )
{
  PsiManager manager = PsiManagerImpl.getInstance( module.getIjProject() );
  final PsiJavaFile aFile = createDummyJavaFile( fqn, manager, source );
  final PsiClass[] classes = aFile.getClasses();
  if( classes.length == 0 )
  {
    return PsiErrorClassUtil.create( module.getIjProject(), new RuntimeException( "Invalid class: " + fqn ) );
  }
  return classes[0];
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:12,代码来源:ManifoldPsiClassCache.java

示例8: deleteChildInternal

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
  if (child.getElementType() == JavaElementType.CLASS) {
    PsiJavaFile file = SourceTreeToPsiMap.treeToPsiNotNull(this);
    if (file.getClasses().length == 1) {
      file.delete();
      return;
    }
  }
  super.deleteChildInternal(child);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:JavaFileElement.java

示例9: testGotoClass

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
public void testGotoClass() throws Exception {

    PsiJavaFile file = (PsiJavaFile)myFixture.configureByText("Foo.java", "public class Foo {\n" +
                                                         "}\n" +
                                                         "\n" +
                                                         "class Bar {}\n");

    VirtualFile virtualFile = file.getVirtualFile();
    assertNotNull(virtualFile);
    myManager.openFile(virtualFile, true);
    assertEquals(0, getOffset(virtualFile));
    myManager.closeAllFiles();

    PsiClass psiClass = file.getClasses()[1];
    int identifierOffset = psiClass.getNameIdentifier().getTextOffset();
    NavigationUtil.activateFileWithPsiElement(psiClass);
    assertEquals(identifierOffset, getOffset(virtualFile));

    getEditor(virtualFile).getCaretModel().moveToOffset(identifierOffset + 3); // it's still inside the class, so keep it

    myManager.closeAllFiles();
    NavigationUtil.activateFileWithPsiElement(psiClass);
    assertEquals(identifierOffset + 3, getOffset(virtualFile));

    getEditor(virtualFile).getCaretModel().moveToOffset(0);
    NavigationUtil.activateFileWithPsiElement(psiClass);
    assertEquals(identifierOffset, getOffset(virtualFile));

    myManager.closeAllFiles();
    NavigationUtil.activateFileWithPsiElement(file); // GoTo file should keep offset
    assertEquals(identifierOffset, getOffset(virtualFile));
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:GotoClassTest.java

示例10: getPublicAnnotatedClass

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
/**
 * NOTE: requires readAction, if not on the dispatch thread Get the public class in a file that is
 * annotated with a certain annotation.
 */
public static PsiClass getPublicAnnotatedClass(PsiJavaFile psiJavaFile, String annotationFqn) {
  PsiClass[] classes = psiJavaFile.getClasses();
  for (PsiClass cls : classes) {
    PsiModifierList modifierList = cls.getModifierList();
    if (modifierList != null && modifierList.hasExplicitModifier(PsiModifier.PUBLIC)) {
      if (AnnotationUtil.isAnnotated(cls, annotationFqn, false)) {
        return cls;
      }
    }
  }
  return null;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:17,代码来源:PsiUtils.java

示例11: isTableModel

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
public static boolean isTableModel(@NotNull PsiFile psiFile) {
    boolean result = false;
    if (psiFile instanceof PsiJavaFile) {
        PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
        PsiClass psiClass = psiJavaFile.getClasses()[0];
        if (psiClass instanceof PsiModifierListOwner) {
            result = AnnotationUtil.isAnnotated(psiClass, TABLE_NAME, false);
        }
    }
    return result;
}
 
开发者ID:nrudenko,项目名称:OrmGeneratorPlugin,代码行数:12,代码来源:PsiFileChecker.java

示例12: deleteChildInternal

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
public void deleteChildInternal(@NotNull ASTNode child)
{
	if(child.getElementType() == JavaElementType.CLASS)
	{
		PsiJavaFile file = SourceTreeToPsiMap.treeToPsiNotNull(this);
		if(file.getClasses().length == 1)
		{
			file.delete();
			return;
		}
	}
	super.deleteChildInternal(child);
}
 
开发者ID:consulo,项目名称:consulo-javaee,代码行数:15,代码来源:JspJavaFileElement.java

示例13: actionPerformed

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    Project project = anActionEvent.getProject();
    PsiJavaFile javaFile = (PsiJavaFile) anActionEvent.getData(PlatformDataKeys.PSI_FILE);
    if (javaFile == null) {
        return;
    }
    PsiClass[] classes = javaFile.getClasses();
    if (classes.length < 1) {
        return;
    }
    PsiClass currentClass = classes[0];
    List<PsiClass> selectClasses = new ArrayList<>();
    selectClasses.add(currentClass);
    CodeTemplate codeTemplate = settings.getCodeTemplate(templateKey);
    //select the other class by classChooser
    for (int i = 1; i < codeTemplate.getClassNumber(); i++) {
        PsiClass psiClass = CodeMakerUtil.chooseClass(project, currentClass);
        if (psiClass == null) {
            return;
        }
        selectClasses.add(psiClass);
    }

    Map<String, Object> map = new HashMap<>();
    for (int i = 0; i < selectClasses.size(); i++) {
        map.put("class" + i, ClassEntry.create(selectClasses.get(i)));
    }
    try {
        Date now = new Date();
        map.put("YEAR", DateFormatUtils.format(now, "yyyy"));
        map.put("TIME", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        map.put("USER", System.getProperty("user.name"));
        String className = VelocityUtil.evaluate(codeTemplate.getClassNameVm(), map);
        map.put("ClassName", className);

        String content = VelocityUtil.evaluate(codeTemplate.getCodeTemplate(), map);
        // async write action
        ApplicationManager.getApplication().runWriteAction(
            new CreateFileAction(CodeMakerUtil.generateClassPath(
                CodeMakerUtil.getSourcePath(currentClass), className), content, anActionEvent.getDataContext()));

    } catch (Exception e) {
        Messages.showMessageDialog(project, e.getMessage(), "Generate Failed", null);
    }

}
 
开发者ID:zeng198821,项目名称:CodeGenerate,代码行数:48,代码来源:CodeMakerAction.java

示例14: addMethods

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
private void addMethods( String fqn, PsiClass psiClass, List<PsiElement> augFeatures, Module start, Module module )
{
  ManModule manModule = ManProject.getModule( module );
  for( ITypeManifold sp : manModule.getTypeManifolds() )
  {
    if( sp.getProducerKind() == Supplemental )
    {
      if( sp.isType( fqn ) )
      {
        List<IFile> files = sp.findFilesForType( fqn );
        for( IFile file : files )
        {
          VirtualFile vFile = ((IjFile)file).getVirtualFile();
          if( !vFile.isValid() )
          {
            continue;
          }

          PsiFile psiFile = PsiManager.getInstance( module.getProject() ).findFile( vFile );
          PsiJavaFile psiJavaFile = (PsiJavaFile)psiFile;
          PsiClass[] classes = psiJavaFile.getClasses();
          if( classes.length > 0 )
          {
            SrcClass srcExtClass = new StubBuilder().make( classes[0].getQualifiedName(), manModule );
            SrcClass scratchClass = new SrcClass( psiClass.getQualifiedName(), psiClass.isInterface() ? SrcClass.Kind.Interface : SrcClass.Kind.Class );
            for( PsiTypeParameter tv : psiClass.getTypeParameters() )
            {
              scratchClass.addTypeVar( new SrcType( StubBuilder.makeTypeVar( tv ) ) );
            }
            for( AbstractSrcMethod m : srcExtClass.getMethods() )
            {
              SrcMethod srcMethod = addExtensionMethod( scratchClass, m, psiClass );
              if( srcMethod != null )
              {
                PsiMethod extMethod = makePsiMethod( srcMethod, psiClass );
                if( extMethod != null )
                {
                  PsiMethod plantedMethod = plantMethodInPsiClass( extMethod, psiClass, classes[0] );
                  augFeatures.add( plantedMethod );
                }
              }
            }
          }
        }
      }
    }
  }
  for( Dependency d : manModule.getDependencies() )
  {
    if( module == start || d.isExported() )
    {
      addMethods( fqn, psiClass, augFeatures, start, ((ManModule)d.getModule()).getIjModule() );
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:56,代码来源:ManAugmentProvider.java

示例15: invoke

import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
public void invoke(@NotNull Project project, @NotNull PsiJavaFile psiFile) {
  for (PsiClass psiClass : psiFile.getClasses()) {
    invoke(project, psiClass, true);
  }
  finish(project, psiFile);
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:7,代码来源:BaseDelombokHandler.java


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