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


Java ClassUtil.extractPackageName方法代码示例

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


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

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

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

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

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

示例5: configure

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Override
public void configure(JUnitConfiguration jUnitConfiguration, PitestConfiguration configuration) {
    JUnitConfiguration.Data data = jUnitConfiguration.getPersistentData();
    String targetTests = data.getMainClassName();
    String targetClasses = null;
    if (StringUtils.endsWith(targetTests, "Test")) {
        targetClasses = targetTests.substring(0, targetTests.lastIndexOf("Test"));
    } 
    if (targetClasses == null || FileUtil.findFirstThatExist(targetClasses) == null) {
        targetClasses = ClassUtil.extractPackageName(targetTests) + ANY_IN_PACKAGE_PATTERN;
    }
    configure(configuration, targetTests, targetClasses);
}
 
开发者ID:artspb,项目名称:idea-pitest,代码行数:14,代码来源:ClassBasedConfigurator.java

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

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

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

示例9: getNamespace

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

示例10: actionPerformed

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public void actionPerformed(AnActionEvent event) {
    final Project project = ActionEventUtils.getTargetProject(event);
    final PsiFile selectedFile = ActionEventUtils.getTargetFile(event);
    final PsiClass selectedClass = PsiUtils.getSelectedClass(event)
            .orElseThrow(() -> new IllegalStateException("Cannot perform action without a selected class"));

    // Note that module may be null if the selected class is in a library rather than the source tree
    final Module module = event.getData(LangDataKeys.MODULE);

    final ConfigurationProperties configurationProperties = new ConfigurationProperties(project);

    // Guess what we are going to call the target matcher class and what its package will be
    String preferredClassName = configurationProperties.getMatcherClassNamePrefix() +
            selectedClass.getName() +
            configurationProperties.getMatcherClassNameSuffix();

    String preferredPackageName = ClassUtil.extractPackageName(selectedClass.getQualifiedName());

    // Get the list of available source roots
    List<VirtualFile> candidateSourceRoots = SourceRootUtils.getSourceAndTestSourceRoots(project);

    if (candidateSourceRoots.isEmpty()) {
        Messages.showErrorDialog(project, "No source roots have been configured. A source root is required as the target location for the generated class.", "No Source Root");
        return;
    }

    // Guess what the target source root might be
    VirtualFile preferredSourceRoot = SourceRootUtils.getPreferredSourceRootForTestClass(project, module, selectedFile.getVirtualFile())
            .orElseThrow(IllegalStateException::new);

    final MatcherGeneratorProperties generatorProperties = new MatcherGeneratorProperties()
            .setProject(project)
            .setClassName(preferredClassName)
            .setPackageName(preferredPackageName)
            .setSourceRoot(preferredSourceRoot)
            .setSourceClass(selectedClass)
            .setFactoryMethodSuffix(configurationProperties.getFactoryMethodSuffix())
            .setTemplateFactoryMethodSuffix(configurationProperties.getTemplateFactoryMethodSuffix())
            .setSetterPrefix(configurationProperties.getSetterPrefix())
            .setSetterSuffix(configurationProperties.getSetterSuffix())
            .setExtensible(configurationProperties.isMakeExtensible())
            .setBaseClassName(configurationProperties.getBaseClass())
            .setGenerateTemplateFactoryMethod(configurationProperties.isGenerateTemplateFactoryMethod())
            .setMakeMethodParametersFinal(configurationProperties.isMakeMethodParametersFinal())
            .setUseReflectingPropertyMatcher(configurationProperties.isUseReflectingPropertyMatcher());

    MatcherGeneratorOptionsDialog matcherGeneratorOptionsDialog = new MatcherGeneratorOptionsDialog(
            project, selectedClass, candidateSourceRoots, generatorProperties);

    matcherGeneratorOptionsDialog.show();

    if (matcherGeneratorOptionsDialog.isOK()) {
        new MatcherGenerator(generatorProperties).generate();
    }
}
 
开发者ID:mistraltechnologies,项目名称:smogen,代码行数:56,代码来源:GenerateMatcherAction.java

示例11: addImportIfNeeded

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public static void addImportIfNeeded(@NotNull PsiClass aClass, @NotNull PsiElement context) {
  final PsiFile file = context.getContainingFile();
  if (!(file instanceof PsiJavaFile)) {
    return;
  }
  final PsiJavaFile javaFile = (PsiJavaFile)file;
  final PsiClass outerClass = aClass.getContainingClass();
  if (outerClass == null) {
    if (PsiTreeUtil.isAncestor(javaFile, aClass, true)) {
      return;
    }
  }
  else {
    if (PsiTreeUtil.isAncestor(outerClass, context, true) &&
        !PsiTreeUtil.isAncestor(outerClass.getModifierList(), context, true)) {
      return;
    }
  }
  final String qualifiedName = aClass.getQualifiedName();
  if (qualifiedName == null) {
    return;
  }
  final PsiImportList importList = javaFile.getImportList();
  if (importList == null) {
    return;
  }
  final String containingPackageName = javaFile.getPackageName();
  @NonNls final String packageName = ClassUtil.extractPackageName(qualifiedName);
  if (containingPackageName.equals(packageName) || importList.findSingleClassImportStatement(qualifiedName) != null) {
    return;
  }
  if (importList.findOnDemandImportStatement(packageName) != null &&
      !hasDefaultImportConflict(qualifiedName, javaFile) && !hasOnDemandImportConflict(qualifiedName, javaFile)) {
    return;
  }
  final Project project = importList.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiElementFactory elementFactory = psiFacade.getElementFactory();
  final PsiImportStatement importStatement = elementFactory.createImportStatement(aClass);
  importList.add(importStatement);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:42,代码来源:ImportUtils.java

示例12: 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 PsiJavaPackage aPackage = (PsiJavaPackage)element;
    final PsiClass[] classes = aPackage.getClasses();
    for (final PsiClass aClass : classes) {
      final String className = aClass.getName();
      if (!shortName.equals(className)) {
        continue;
      }
      if (!strict) {
        return true;
      }
      final String qualifiedClassName = aClass.getQualifiedName();
      if (qualifiedClassName == null || fqName.equals(qualifiedClassName)) {
        continue;
      }
      return containsReferenceToConflictingClass(file, qualifiedClassName);
    }
  }
  return hasJavaLangImportConflict(fqName, file);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:50,代码来源:ImportUtils.java

示例13: 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 PsiJavaPackage)) {
      continue;
    }
    final PsiJavaPackage aPackage = (PsiJavaPackage)element;
    final PsiClass[] classes = aPackage.getClasses();
    for (final PsiClass aClass : classes) {
      final String className = aClass.getName();
      if (!shortName.equals(className)) {
        continue;
      }
      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:consulo,项目名称:consulo-java,代码行数:50,代码来源:ImportUtils.java


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