• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClassUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getTextForElement

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Override
protected String getTextForElement(PsiElement element) {
  final PsiAnnotation annotation = (PsiAnnotation)element;
  final String qualifiedName = annotation.getQualifiedName();
  if (qualifiedName == null) {
    return null;
  }
  final String annotationName = ClassUtil.extractClassName(qualifiedName);
  final PsiElement grandParent = element.getParent().getParent();
  if (grandParent instanceof PsiMethod) {
    return IntentionPowerPackBundle.message(
      "annotate.overridden.methods.intention.method.name",
      annotationName);
  }
  else {
    return IntentionPowerPackBundle.message(
      "annotate.overridden.methods.intention.parameters.name",
      annotationName);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:AnnotateOverriddenMethodsIntention.java


示例17: chooseClass

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
public static String chooseClass(Project project, String initialValue)
{
   PsiManager psiManager = PsiManager.getInstance(project);

   TreeClassChooser chooser = new TreeJavaClassChooserDialog(
            "Select a Java class",
            project,
            GlobalSearchScope.allScope(project),
            null,
            ClassUtil.findPsiClass(psiManager, initialValue));
   chooser.showDialog();

   PsiClass psiClass = chooser.getSelected();

   return psiClass != null ? psiClass.getQualifiedName() : (initialValue.isEmpty() ? null : initialValue);
}
 
开发者ID:forge,项目名称:intellij-idea-plugin,代码行数:17,代码来源:IDEUtil.java


示例18: findPsiMethod

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
@Nullable
public static PsiMethod findPsiMethod(PsiManager manager, String externalName)
{
	final int spaceIdx = externalName.indexOf(' ');
	final String className = externalName.substring(0, spaceIdx);
	final PsiClass psiClass = ClassUtil.findPsiClass(manager, className);
	if(psiClass == null)
	{
		return null;
	}
	try
	{
		PsiElementFactory factory = JavaPsiFacade.getInstance(psiClass.getProject()).getElementFactory();
		String methodSignature = externalName.substring(spaceIdx + 1);
		PsiMethod patternMethod = factory.createMethodFromText(methodSignature, psiClass);
		return psiClass.findMethodBySignature(patternMethod, false);
	}
	catch(IncorrectOperationException e)
	{
		// Do nothing. Returning null is acceptable in this case.
		return null;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:RefMethodImpl.java


示例19: 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) {
    final String serviceProviderName = file.getName();
    final PsiClass psiClass =
      ClassUtil.findPsiClass(element.getManager(), serviceProviderName, null, true, element.getContainingFile().getResolveScope());
    if (element instanceof SPIFile) {
      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:consulo,项目名称:consulo-java,代码行数:24,代码来源:SPIAnnotator.java


示例20: hasDefaultImportConflict

import com.intellij.psi.util.ClassUtil; //导入依赖的package包/类
public static boolean hasDefaultImportConflict(String fqName, PsiJavaFile file) {
  final String shortName = ClassUtil.extractClassName(fqName);
  final String packageName = ClassUtil.extractPackageName(fqName);
  final String filePackageName = file.getPackageName();
  if (filePackageName.equals(packageName)) {
    return false;
  }
  final Project project = file.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiJavaPackage filePackage = psiFacade.findPackage(filePackageName);
  if (filePackage == null) {
    return false;
  }
  final PsiClass[] classes = filePackage.getClasses();
  for (PsiClass aClass : classes) {
    final String className = aClass.getName();
    if (shortName.equals(className)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:ImportUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AlignmentHorizontal类代码示例发布时间:2022-05-22
下一篇:
Java PolicyContextException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap