本文整理汇总了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() );
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例13: getName
import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Override
public String getName()
{
return ClassUtil.extractClassName( _fqn );
}
示例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);
}
示例15: ConflictingClassReferenceVisitor
import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
private ConflictingClassReferenceVisitor(String fullyQualifiedName) {
name = ClassUtil.extractClassName(fullyQualifiedName);
this.fullyQualifiedName = fullyQualifiedName;
}