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


Java ClassUtil类代码示例

本文整理汇总了Java中com.intellij.psi.util.ClassUtil的典型用法代码示例。如果您正苦于以下问题:Java ClassUtil类的具体用法?Java ClassUtil怎么用?Java ClassUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: errrantThisOrExtension

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
private void errrantThisOrExtension( PsiElement element, AnnotationHolder holder )
{
  if( element instanceof PsiModifierList )
  {
    PsiModifierList mods = (PsiModifierList)element;
    PsiAnnotation annotation;
    if( (annotation = mods.findAnnotation( Extension.class.getName() )) != null ||
        (annotation = mods.findAnnotation( This.class.getName() )) != null)
    {
      TextRange range = new TextRange( annotation.getTextRange().getStartOffset(),
                                       annotation.getTextRange().getEndOffset() );
      //noinspection ConstantConditions
      holder.createErrorAnnotation( range, ExtIssueMsg.MSG_NOT_IN_EXTENSION_CLASS.get( ClassUtil.extractClassName( annotation.getQualifiedName() ) ) );
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:17,代码来源:ExtensionClassAnnotator.java

示例2: findPsiClasses

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
private void findPsiClasses( @NotNull @NonNls String name, @NotNull GlobalSearchScope scope, Set<PsiClass> psiClasses, ManModule start, ManModule module )
{
  for( ITypeManifold tm: module.getTypeManifolds() )
  {
    for( String fqn: tm.getAllTypeNames() )
    {
      String simpleName = ClassUtil.extractClassName( fqn );
      if( simpleName.equals( name ) )
      {
        PsiClass psiClass = ManifoldPsiClassCache.instance().getPsiClass( scope, module, fqn );
        if( psiClass == null )
        {
          return;
        }
        psiClasses.add( psiClass );
      }
    }
  }
  for( Dependency d : module.getDependencies() )
  {
    if( module == start || d.isExported() )
    {
      findPsiClasses( name, scope, psiClasses, start, (ManModule)d.getModule() );
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:27,代码来源:ManShortNamesCache.java

示例3: findClassFqns

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
private void findClassFqns( @NotNull HashSet<String> dest, ManModule start, ManModule module )
{
  for( ITypeManifold tm: module.getTypeManifolds() )
  {
    if( tm.getProducerKind() == ITypeManifold.ProducerKind.Supplemental )
    {
      continue;
    }
    dest.addAll( tm.getAllTypeNames().stream().map( ClassUtil::extractClassName ).collect( Collectors.toList() ) );
  }
  for( Dependency d : module.getDependencies() )
  {
    if( module == start || d.isExported() )
    {
      findClassFqns( dest, start, (ManModule)d.getModule() );
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:19,代码来源:ManShortNamesCache.java

示例4: annotate

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  final VirtualFile file = PsiUtilCore.getVirtualFile(element);
  if (file != null && file.getFileType() instanceof SPIFileType) {
    final String serviceProviderName = file.getName();
    final PsiClass psiClass =
      ClassUtil.findPsiClass(element.getManager(), serviceProviderName, null, true, element.getContainingFile().getResolveScope());
    if (element instanceof PsiFile) {
      if (psiClass == null) {
        holder.createErrorAnnotation(element, "No service provider \"" + serviceProviderName + "\' found").setFileLevelAnnotation(true);
      }
    } else if (element instanceof SPIClassProviderReferenceElement) {
      final PsiElement resolve = ((SPIClassProviderReferenceElement)element).resolve();
      if (resolve == null) {
        holder.createErrorAnnotation(element, "Cannot resolve symbol " + element.getText());
      } else if (resolve instanceof PsiClass && psiClass != null) {
        if (!((PsiClass)resolve).isInheritor(psiClass, true)) {
          holder.createErrorAnnotation(element, "Registered extension should implement " + serviceProviderName);
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:SPIAnnotator.java

示例5: getVariants

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@NotNull
@Override
public Object[] getVariants() {
  final String name = getContainingFile().getName();
  final PsiClass superProvider = JavaPsiFacade.getInstance(getProject()).findClass(name, getResolveScope());
  if (superProvider != null) {
    final List<Object> result = new ArrayList<Object>();
    ClassInheritorsSearch.search(superProvider).forEach(new Processor<PsiClass>() {
      @Override
      public boolean process(PsiClass psiClass) {
        if (!psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
          final String jvmClassName = ClassUtil.getJVMClassName(psiClass);
          if (jvmClassName != null) {
            result.add(LookupElementBuilder.create(psiClass, jvmClassName));
          }
        }
        return true;
      }
    });
    return ArrayUtil.toObjectArray(result);
  }
  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:SPIClassProviderReferenceElement.java

示例6: getFragmentClass

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
/**
 * Converts a (possibly ambiguous) class name like A.B.C.D into an Android-style class name
 * like A.B$C$D where package names are separated by dots and inner classes are separated by dollar
 * signs (similar to how the internal JVM format uses dollar signs for inner classes but slashes
 * as package separators)
 */
@NotNull
private static String getFragmentClass(@NotNull final Module module, @NotNull final String fqcn) {
  return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    @NotNull
    public String compute() {
      Project project = module.getProject();
      JavaPsiFacade finder = JavaPsiFacade.getInstance(project);
      PsiClass psiClass = finder.findClass(fqcn, module.getModuleScope());
      if (psiClass == null) {
        psiClass = finder.findClass(fqcn, GlobalSearchScope.allScope(project));
      }

      if (psiClass != null) {
        String jvmClassName = ClassUtil.getJVMClassName(psiClass);
        if (jvmClassName != null) {
          return jvmClassName.replace('/', '.');
        }
      }

      return fqcn;
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:HtmlLinkManager.java

示例7: fillTestObjects

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Override
public void fillTestObjects(Map<PsiClass, Map<PsiMethod, List<String>>> classes)
  throws CantRunException {
  final TestData data = myConfig.getPersistantData();
  //it's a class
  final PsiClass psiClass = ApplicationManager.getApplication().runReadAction(
    new Computable<PsiClass>() {
      @Nullable
      public PsiClass compute() {
        return ClassUtil.findPsiClass(PsiManager.getInstance(myConfig.getProject()), data.getMainClassName().replace('/', '.'), null, true, getSearchScope());
      }
    }
  );
  if (psiClass == null) {
    throw new CantRunException("No tests found in the class \"" + data.getMainClassName() + '\"');
  }
  if (null == ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Nullable
    public String compute() {
      return psiClass.getQualifiedName();
    }
  })) {
    throw new CantRunException("Cannot test anonymous or local class \"" + data.getMainClassName() + '\"');
  }
  calculateDependencies(null, classes, getSearchScope(), psiClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:TestNGTestClass.java

示例8: getPackageClassNodeFor

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
private TestProxy getPackageClassNodeFor(final TestResultMessage result) {
  TestProxy owner = treeBuilder.getRoot();
  final String packageName1 = StringUtil.getPackageName(result.getTestClass());
  String packageName = packageName1.length() == 0 ? NO_PACKAGE : packageName1;
  owner = getChildNodeNamed(owner, packageName);
  if (owner.getPsiElement() == null) {
    owner.setPsiElement(JavaPsiFacade.getInstance(project).findPackage(packageName));
  }
  owner = getChildNodeNamed(owner, StringUtil.getShortName(result.getTestClass()));
  //look up the psiclass now
  if (owner.getPsiElement() == null) {
    final TestProxy finalOwner = owner;
    ApplicationManager.getApplication().runReadAction(new Runnable() {
      public void run() {
        finalOwner.setPsiElement(ClassUtil.findPsiClass(PsiManager.getInstance(project), result.getTestClass()));
      }
    });
  }
  return owner;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:TestNGResults.java

示例9: ChangeFormComponentTypeFix

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
public ChangeFormComponentTypeFix(PsiPlainTextFile formFile, String fieldName, PsiType componentTypeToSet) {
  myFormFile = formFile;
  myFieldName = fieldName;
  if (componentTypeToSet instanceof PsiClassType) {
    PsiClass psiClass = ((PsiClassType)componentTypeToSet).resolve();
    if (psiClass != null) {
      myComponentTypeToSet = ClassUtil.getJVMClassName(psiClass);
    }
    else {
      myComponentTypeToSet = ((PsiClassType) componentTypeToSet).rawType().getCanonicalText();
    }
  }
  else {
    myComponentTypeToSet = componentTypeToSet.getCanonicalText();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ChangeFormComponentTypeFix.java

示例10: actionPerformed

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final PsiClass psiClass = getPsiClass(e);
  if (psiClass == null) return;

  final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
  final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
  if (module == null || virtualFile == null) return;

  final String className = ClassUtil.getJVMClassName(psiClass);

  final Project project = getEventProject(e);
  CompilerManager.getInstance(project).make(new FileSetCompileScope(Collections.singletonList(virtualFile), new Module[]{module}), new CompileStatusNotification() {
    @Override
    public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
      if (aborted || errors > 0) return;
      generateAndShowXml(module, className);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ShowSerializedXmlAction.java

示例11: visitReferenceElement

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Override
public void visitReferenceElement(
  PsiJavaCodeReferenceElement reference) {
  super.visitReferenceElement(reference);
  if (reference.isQualified()) {
    return;
  }
  final PsiElement element = reference.resolve();
  if (!(element instanceof PsiClass)) {
    return;
  }
  final PsiClass aClass = (PsiClass)element;
  final String qualifiedName = aClass.getQualifiedName();
  final String packageName =
    ClassUtil.extractPackageName(qualifiedName);
  if (!importedPackageName.equals(packageName)) {
    return;
  }
  importedClasses.add(aClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ReplaceOnDemandImportIntention.java

示例12: findTestCase

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private List<Location> findTestCase(Project project, String path) {
  String[] parts = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER, 2);
  if (parts.length < 2) {
    return ImmutableList.of();
  }
  String className = parts[0];
  String testName = parts[1];
  PsiClass testClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className);
  for (ScInfixExpr testCase : PsiTreeUtil.findChildrenOfType(testClass, ScInfixExpr.class)) {
    if (TestNodeProvider.isSpecs2TestExpr(testCase)
        && Objects.equal(Specs2Utils.getSpecs2ScopedTestName(testCase), testName)) {
      return ImmutableList.of(new PsiLocation<>(testCase));
    }
  }
  return ImmutableList.of();
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:18,代码来源:BlazeScalaTestLocator.java

示例13: extractSourceRoot

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
private String extractSourceRoot(PsiPackage selectedPackage) {
  PsiDirectory target;
  PsiDirectory[] directories = selectedPackage.getDirectories();

  if (directories.length == 1) {
    target = directories[0];
  } else {
    String[] arr = new String[directories.length];
    for (int i = 0; i < directories.length; i++) {
      arr[i] = directories[i].getVirtualFile().getPath();
    }

    int selectedIndex = ComboChooser.show(
        "Package found in multiple directories",
        "Select package source root:",
        arr);

    if (selectedIndex == -1) {
      return null;
    }

    target = directories[selectedIndex];
  }

  return ClassUtil.sourceRoot(target).getVirtualFile().getPath();
}
 
开发者ID:contentful-graveyard,项目名称:cf-generator-intellij,代码行数:27,代码来源:GeneratorDialog.java

示例14: getVariants

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@NotNull
@Override
public Object[] getVariants() {
  final String name = getContainingFile().getName();
  final PsiClass superProvider = JavaPsiFacade.getInstance(getProject()).findClass(name, getResolveScope());
  if (superProvider != null) {
    final List<Object> result = new ArrayList<Object>();
    ClassInheritorsSearch.search(superProvider).forEach(new Processor<PsiClass>() {
      @Override
      public boolean process(PsiClass psiClass) {
        final String jvmClassName = ClassUtil.getJVMClassName(psiClass);
        if (jvmClassName != null) {
          result.add(LookupElementBuilder.create(psiClass, jvmClassName));
        }
        return false;
      }
    });
    return ArrayUtil.toObjectArray(result);
  }
  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:SPIClassProviderReferenceElement.java

示例15: actionPerformed

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final PsiClass psiClass = getPsiClass(e);
  if (psiClass == null) return;

  final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
  final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
  if (module == null || virtualFile == null) return;

  final String className = ClassUtil.getJVMClassName(psiClass);

  final Project project = getEventProject(e);
  CompilerManager.getInstance(project).make(new FileSetCompileScope(Arrays.asList(virtualFile), new Module[]{module}), new CompileStatusNotification() {
    @Override
    public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
      if (aborted || errors > 0) return;
      generateAndShowXml(module, className);
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:ShowSerializedXmlAction.java


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