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


Java ClassUtil.extractClassName方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: hasJavaLangImportConflict

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

示例5: hasJavaLangImportConflict

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

示例6: extractClassName

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@NotNull
private static String extractClassName(@NotNull PsiJavaFile file, @NotNull String fullyQualifiedName) {
  for (PsiClass aClass : file.getClasses()) {
    String outerClassName = aClass.getQualifiedName();
    if (outerClassName != null && fullyQualifiedName.startsWith(outerClassName)) {
      return fullyQualifiedName.substring(outerClassName.lastIndexOf('.') + 1);
    }
  }

  return ClassUtil.extractClassName(fullyQualifiedName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ImportHelper.java

示例7: hasOnDemandImportConflict

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
/**
 * @param strict if strict is true this method checks if the conflicting
 *               class which is imported is actually used in the file. If it isn't the
 *               on demand import can be overridden with an exact import for the fqName
 *               without breaking stuff.
 */
private static boolean hasOnDemandImportConflict(@NotNull String fqName, @NotNull PsiJavaFile file, boolean strict) {
  final PsiImportList imports = file.getImportList();
  if (imports == null) {
    return false;
  }
  final PsiImportStatement[] importStatements = imports.getImportStatements();
  final String shortName = ClassUtil.extractClassName(fqName);
  final String packageName = ClassUtil.extractPackageName(fqName);
  for (final PsiImportStatement importStatement : importStatements) {
    if (!importStatement.isOnDemand()) {
      continue;
    }
    final PsiJavaCodeReferenceElement importReference = importStatement.getImportReference();
    if (importReference == null) {
      continue;
    }
    final String packageText = importReference.getText();
    if (packageText.equals(packageName)) {
      continue;
    }
    final PsiElement element = importReference.resolve();
    if (element == null || !(element instanceof PsiPackage)) {
      continue;
    }
    final PsiPackage aPackage = (PsiPackage)element;
    final PsiClass[] classes = aPackage.findClassByShortName(shortName, file.getResolveScope());
    for (final PsiClass aClass : classes) {
      if (!strict) {
        return true;
      }
      final String qualifiedClassName = aClass.getQualifiedName();
      if (qualifiedClassName == null || fqName.equals(qualifiedClassName)) {
        continue;
      }
      return containsConflictingReference(file, qualifiedClassName);
    }
  }
  return hasJavaLangImportConflict(fqName, file);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:46,代码来源:ImportUtils.java

示例8: 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 PsiPackage filePackage = psiFacade.findPackage(filePackageName);
  if (filePackage == null) {
    return false;
  }
  return filePackage.containsClassNamed(shortName);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:ImportUtils.java

示例9: hasJavaLangImportConflict

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public static boolean hasJavaLangImportConflict(String fqName, PsiJavaFile file) {
  final String shortName = ClassUtil.extractClassName(fqName);
  final String packageName = ClassUtil.extractPackageName(fqName);
  if (HardcodedMethodConstants.JAVA_LANG.equals(packageName)) {
    return false;
  }
  final Project project = file.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiPackage javaLangPackage = psiFacade.findPackage(HardcodedMethodConstants.JAVA_LANG);
  if (javaLangPackage == null) {
    return false;
  }
  return javaLangPackage.containsClassNamed(shortName);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:ImportUtils.java

示例10: containsConflictingInnerClass

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
/**
 * ImportUtils currently checks all inner classes, even those that are
 * contained in inner classes themselves, because it doesn't know the
 * location of the original fully qualified reference. It should really only
 * check if the containing class of the fully qualified reference has any
 * conflicting inner classes.
 */
private static boolean containsConflictingInnerClass(String fqName, PsiClass aClass) {
  final String shortName = ClassUtil.extractClassName(fqName);
  if (shortName.equals(aClass.getName()) && !fqName.equals(aClass.getQualifiedName())) {
    return true;
  }
  final PsiClass[] classes = aClass.getInnerClasses();
  for (PsiClass innerClass : classes) {
    if (containsConflictingInnerClass(fqName, innerClass)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:ImportUtils.java

示例11: isAlreadyImported

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public static boolean isAlreadyImported(@NotNull PsiJavaFile file, @NotNull String fullyQualifiedName)
{
	String className = ClassUtil.extractClassName(fullyQualifiedName);
	Project project = file.getProject();
	PsiResolveHelper resolveHelper = PsiResolveHelper.SERVICE.getInstance(project);

	PsiClass psiClass = resolveHelper.resolveReferencedClass(className, file);
	return psiClass != null && fullyQualifiedName.equals(psiClass.getQualifiedName());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:ImportHelper.java

示例12: doCreate

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
private PsiFile doCreate( PsiDirectory dir, String className, String fqnExtended ) throws IncorrectOperationException
{
  Project project = dir.getProject();

  String fileName = className + ".java";
  VirtualFile srcRoot = ProjectRootManager.getInstance( project ).getFileIndex().getSourceRootForFile( dir.getVirtualFile() );
  dir = getPsiDirectoryForExtensionClass( dir, fqnExtended, srcRoot );

  final PsiPackage pkg = JavaDirectoryService.getInstance().getPackage( dir );
  if( pkg == null )
  {
    throw new IncorrectOperationException( ManBundle.message( "error.new.artifact.nopackage" ) );
  }

  String text =
    "package " + pkg.getQualifiedName() + ";\n" +
    "\n" +
    "import manifold.ext.api.Extension;\n" +
    "import manifold.ext.api.This;\n" +
    "import " + fqnExtended + ";\n" +
    "\n" +
    "@Extension\n" +
    "public class " + className + " {\n" +
    "  public static " + processTypeVars( dir, fqnExtended, StubBuilder::makeTypeVar ) + "void helloWorld(@This " + ClassUtil.extractClassName( fqnExtended ) + processTypeVars( dir, fqnExtended, PsiNamedElement::getName ) + " thiz) {\n" +
    "    System.out.println(\"hello world!\");\n" +
    "  }\n" +
    "}";

  dir.checkCreateFile( fileName );

  final PsiFile file = dir.createFile( fileName );

  try
  {
    new CharSink()
    {
      public Writer openStream() throws IOException
      {
        return new OutputStreamWriter( file.getVirtualFile().getOutputStream( null ) );
      }
    }.write( text );
  }
  catch( IOException e )
  {
    throw new IncorrectOperationException( e.getMessage(), (Throwable)e );
  }

  return file;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:50,代码来源:CreateExtensionMethodsClassAction.java

示例13: getName

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Override
public String getName()
{
  return ClassUtil.extractClassName( _fqn );
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:6,代码来源:ManifoldPsiClass.java

示例14: nameCanBeImported

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public static boolean nameCanBeImported(@NotNull String fqName, @NotNull PsiElement context) {
  final PsiClass containingClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
  if (containingClass != null) {
    if (fqName.equals(containingClass.getQualifiedName())) {
      return true;
    }
    final String shortName = ClassUtil.extractClassName(fqName);
    final PsiClass[] innerClasses = containingClass.getAllInnerClasses();
    for (PsiClass innerClass : innerClasses) {
      if (innerClass.hasModifierProperty(PsiModifier.PRIVATE)) {
        continue;
      }
      if (innerClass.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
        if (!ClassUtils.inSamePackage(innerClass, containingClass)) {
          continue;
        }
      }
      final String className = innerClass.getName();
      if (shortName.equals(className)) {
        return false;
      }
    }
    PsiField field = containingClass.findFieldByName(shortName, false);
    if (field != null) {
      return false;
    }
    field = containingClass.findFieldByName(shortName, true);
    if (field != null && PsiUtil.isAccessible(field, containingClass, null)) {
      return false;
    }
  }
  final PsiJavaFile file = PsiTreeUtil.getParentOfType(context, PsiJavaFile.class);
  if (file == null) {
    return false;
  }
  if (hasExactImportConflict(fqName, file)) {
    return false;
  }
  if (hasOnDemandImportConflict(fqName, file, true)) {
    return false;
  }
  if (containsConflictingReference(file, fqName)) {
    return false;
  }
  if (containsConflictingClass(fqName, file)) {
    return false;
  }
  return !containsConflictingClassName(fqName, file);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:50,代码来源:ImportUtils.java

示例15: ConflictingClassReferenceVisitor

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
private ConflictingClassReferenceVisitor(String fullyQualifiedName) {
  name = ClassUtil.extractClassName(fullyQualifiedName);
  this.fullyQualifiedName = fullyQualifiedName;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:5,代码来源:ImportUtils.java


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