com.intellij.psi.PsiClass#getQualifiedName ( )源码实例Demo

下面列出了com.intellij.psi.PsiClass#getQualifiedName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void collectProperties(PsiModifierListOwner match, SearchContext context) {
	if (match instanceof PsiClass) {
		PsiClass type = (PsiClass) match;
		String className = type.getQualifiedName();
		String[] names = getTypeNames();
		for (String name : names) {
			if (name.equals(className)) {
				try {
					// Collect properties from the class name and stop the loop.
					processClass(type, className, context);
					break;
				} catch (Exception e) {
					LOGGER.error("Cannot compute MicroProfile properties for the Java class '" + className + "'.",
							e);
				}
			}
		}
	}
}
 
源代码2 项目: intellij   文件: ProducerUtils.java
/**
 * Based on {@link JUnitUtil#isTestClass}. We don't use that directly because it returns true for
 * all inner classes of a test class, regardless of whether they're also test classes.
 */
public static boolean isTestClass(PsiClass psiClass) {
  if (psiClass.getQualifiedName() == null) {
    return false;
  }
  if (JUnitUtil.isJUnit5(psiClass) && JUnitUtil.isJUnit5TestClass(psiClass, true)) {
    return true;
  }
  if (!PsiClassUtil.isRunnableClass(psiClass, true, true)) {
    return false;
  }
  if (isJUnit4Class(psiClass)) {
    return true;
  }
  if (isTestCaseInheritor(psiClass)) {
    return true;
  }
  return CachedValuesManager.getCachedValue(
      psiClass,
      () ->
          CachedValueProvider.Result.create(
              hasTestOrSuiteMethods(psiClass),
              PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT));
}
 
@Override
protected boolean doIsConfigFromContext(
    ApplicationConfiguration configuration, ConfigurationContext context) {
  PsiClass mainClass = configuration.getMainClass();
  if (mainClass == null || mainClass.getQualifiedName() == null) {
    return false;
  }
  if (configuration.getVMParameters() == null) {
    return false;
  }
  ScObject mainObject = getMainObject(context);
  if (mainObject == null) {
    return false;
  }
  TargetInfo target = findTarget(context.getProject(), mainObject);
  if (target == null) {
    return false;
  }

  return mainClass.getQualifiedName().equals(mainObject.qualifiedName())
      && configuration
          .getVMParameters()
          .endsWith(String.format("%s_deploy.jar", target.label.targetName()));
}
 
/**
 * Get or create the update hint from the given type.
 * 
 * @param collector
 * @param type      the type.
 * @return the hint name.
 */
protected String updateHint(IPropertiesCollector collector, PsiClass type) {
	if (type == null) {
		return null;
	}
	if (type.isEnum()) {
		// Register Enumeration in "hints" section
		//String hint = ClassUtil.getJVMClassName(type);
		String hint = type.getQualifiedName();
		if (!collector.hasItemHint(hint)) {
			ItemHint itemHint = collector.getItemHint(hint);
			itemHint.setSourceType(hint);
			if (type instanceof PsiClassImpl) {
				itemHint.setSource(Boolean.TRUE);
			}
			PsiElement[] children = type.getChildren();
			for (PsiElement c : children) {
				if (c instanceof PsiEnumConstant) {
					String enumName = ((PsiEnumConstant) c).getName();
					// TODO: extract Javadoc
					String description = null;
					ValueHint value = new ValueHint();
					value.setValue(enumName);
					itemHint.getValues().add(value);
				}
			}
		}
		return hint;
	}
	return null;
}
 
源代码5 项目: idea-android-studio-plugin   文件: JavaPsiUtil.java
public static boolean isInstanceOf(PsiClass instance, PsiClass interfaceExtendsClass) {

        String className = interfaceExtendsClass.getQualifiedName();
        if(className == null) {
            return true;
        }

        if(className.equals(instance.getQualifiedName())) {
            return true;
        }

        for(PsiClassType psiClassType: PsiClassImplUtil.getExtendsListTypes(instance)) {
            PsiClass resolve = psiClassType.resolve();
            if(resolve != null) {
                if(className.equals(resolve.getQualifiedName())) {
                    return true;
                }
            }
        }

        for(PsiClass psiInterface: PsiClassImplUtil.getInterfaces(instance)) {
            if(className.equals(psiInterface.getQualifiedName())) {
                return true;
            }
        }

        return false;
    }
 
private static boolean isThisTypeASubTypeOfTheSuperType(PsiClass thisType, PsiClass theSuperType) {
  if (!thisType.isValid()) return false;
  final String tcfqn = thisType.getQualifiedName();
  final String pscfqn = theSuperType.getQualifiedName();
  if (pscfqn.equals(tcfqn)) return false; // it's the same class in LHS & RHS
  final ArrayList<PsiClass> allSuperTypes = getSuperTypesAsList(thisType);
  for (PsiClass aSuperType : allSuperTypes) {
    if (pscfqn.equals(aSuperType.getQualifiedName())) {
      return true;
    }
  }
  return false;
}
 
源代码7 项目: data-mediator   文件: PsiUtils.java
public static String getNonGenericType(PsiType type) {
    if (type instanceof PsiClassType) {
        PsiClassType pct = (PsiClassType) type;
        final PsiClass psiClass = pct.resolve();

        return psiClass != null ? psiClass.getQualifiedName() : null;
    }

    return type.getCanonicalText();
}
 
源代码8 项目: intellij   文件: BlazeJUnitTestFilterFlags.java
/**
 * Builds the JUnit test filter corresponding to the given class and methods.<br>
 * Returns null if no class name can be found.
 */
@Nullable
private static String testFilterForClassAndMethods(
    PsiClass psiClass,
    JUnitVersion version,
    List<String> methodFilters,
    ParameterizedTestInfo parameterizedTestInfo) {
  String className = psiClass.getQualifiedName();
  if (className == null) {
    return null;
  }
  return testFilterForClassAndMethods(className, version, methodFilters, parameterizedTestInfo);
}
 
源代码9 项目: intellij   文件: JavaBinaryContextProvider.java
@Nullable
private static TargetIdeInfo getTarget(Project project, PsiClass mainClass) {
  File mainClassFile = RunUtil.getFileForClass(mainClass);
  if (mainClassFile == null) {
    return null;
  }
  Collection<TargetIdeInfo> javaBinaryTargets = findJavaBinaryTargets(project, mainClassFile);

  String qualifiedName = mainClass.getQualifiedName();
  String className = mainClass.getName();
  if (qualifiedName == null || className == null) {
    // out of date psi element; just take the first match
    return Iterables.getFirst(javaBinaryTargets, null);
  }

  // first look for a matching main_class
  TargetIdeInfo match =
      javaBinaryTargets.stream()
          .filter(
              target ->
                  target.getJavaIdeInfo() != null
                      && qualifiedName.equals(target.getJavaIdeInfo().getJavaBinaryMainClass()))
          .findFirst()
          .orElse(null);
  if (match != null) {
    return match;
  }

  match =
      javaBinaryTargets.stream()
          .filter(target -> className.equals(target.getKey().getLabel().targetName().toString()))
          .findFirst()
          .orElse(null);
  if (match != null) {
    return match;
  }
  return Iterables.getFirst(javaBinaryTargets, null);
}
 
源代码10 项目: intellij   文件: ClassPackagePathHeuristic.java
private static boolean doMatchesSource(PsiClassOwner source, String targetName) {
  for (PsiClass psiClass : source.getClasses()) {
    String qualifiedName = psiClass.getQualifiedName();
    if (qualifiedName == null) {
      continue;
    }
    String classPackagePath = psiClass.getQualifiedName().replace('.', '/');
    if (targetName.contains(classPackagePath)) {
      return true;
    }
  }
  return false;
}
 
源代码11 项目: aircon   文件: ConfigElementsUtils.java
private static String getEnumConfigImplClass(final PsiAnnotation annotation) {
	final PsiClass enumClass = getEnumClassAttribute(annotation);
	return enumClass.getQualifiedName();
}
 
源代码12 项目: aircon   文件: ElementUtils.java
public static String getQualifiedName(final PsiType type) {
	final PsiClass psiClass = PsiTypesUtil.getPsiClass(type);
	return psiClass != null ? psiClass.getQualifiedName() : JAVA_LANG_PACKAGE + type.getPresentableText();
}
 
private void populateConfigObject(PsiClass configPropertiesType, String prefixStr, String extensionName,
								  Set<PsiClass> typesAlreadyProcessed, PsiAnnotation configPropertiesAnnotation,
								  ConfigPropertiesContext configPropertiesContext, IPropertiesCollector collector) {
	if (typesAlreadyProcessed.contains(configPropertiesType)) {
		return;
	}
	typesAlreadyProcessed.add(configPropertiesType);
	PsiElement[] elements = configPropertiesType.getChildren();
	// Loop for each fields.
	for (PsiElement child : elements) {
		if (child instanceof PsiField) {
			// The following code is an adaptation for JDT of
			// Quarkus arc code:
			// https://github.com/quarkusio/quarkus/blob/e8606513e1bd14f0b1aaab7f9969899bd27c55a3/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ClassConfigPropertiesUtil.java#L211
			PsiField field = (PsiField) child;
			boolean useFieldAccess = false;
			String setterName = JavaBeanUtil.getSetterName(field.getName());
			String configClassInfo = configPropertiesType.getQualifiedName();
			PsiMethod setter = findMethod(configPropertiesType, setterName, field.getType());
			if (setter == null) {
				if (!field.getModifierList().hasModifierProperty(PsiModifier.PUBLIC) || field.getModifierList().hasModifierProperty(PsiModifier.FINAL)) {
					LOGGER.info("Configuration properties class " + configClassInfo
									+ " does not have a setter for field " + field
									+ " nor is the field a public non-final field");
					continue;
				}
				useFieldAccess = true;
			}
			if (!useFieldAccess && !setter.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) {
				LOGGER.info("Setter " + setterName + " of class " + configClassInfo + " must be public");
				continue;
			}

			String name = field.getName();
			// The default value is managed with assign like : 'public String suffix = "!"';
			// Getting "!" value is possible but it requires to re-parse the Java file to
			// build a DOM CompilationUnit to extract assigned value.
			final String defaultValue = null;
			String propertyName = prefixStr + "." + convertName(name, field, configPropertiesAnnotation, configPropertiesContext);

			String fieldTypeName = PsiTypeUtils.getResolvedTypeName(field);
			PsiClass fieldClass = PsiTypeUtils.findType(field.getManager(), fieldTypeName);
			if (PsiTypeUtils.isSimpleFieldType(fieldClass, fieldTypeName)) {

				// Class type
				String type = PsiTypeUtils.getPropertyType(fieldClass, fieldTypeName);

				// Javadoc
				String description = null;

				// field and class source
				String sourceType = PsiTypeUtils.getSourceType(field);
				String sourceField = PsiTypeUtils.getSourceField(field);

				// Enumerations
				super.updateHint(collector, fieldClass);

				ItemMetadata metadata = super.addItemMetadata(collector, propertyName, type, description, sourceType, sourceField, null,
						defaultValue, extensionName, PsiTypeUtils.isBinary(field));
				PsiQuarkusUtils.updateConverterKinds(metadata, field, fieldClass);
			} else {
				populateConfigObject(fieldClass, propertyName, extensionName, typesAlreadyProcessed, configPropertiesAnnotation, configPropertiesContext, collector);
			}
		}
	}
}
 
private void collectProperties(IPropertiesCollector collector, AnnotationInfo info, PsiMember annotatedClassOrMethod,
		PsiAnnotation mpftAnnotation, MicroProfileFaultToleranceContext mpftContext) {
	String annotationName = info.getSimpleName();
	String className = null;
	String methodName = null;
	boolean binary = false;
	String sourceType = null;
	String sourceMethod = null;
	if (annotatedClassOrMethod != null) {
		binary = PsiTypeUtils.isBinary(annotatedClassOrMethod);
		if (annotatedClassOrMethod instanceof PsiClass) {
			PsiClass annotatedClass = (PsiClass) annotatedClassOrMethod;
			className = annotatedClass.getQualifiedName();
			// Check if properties has been generated for the <classname><annotation>:
			if (isProcessed(className, annotationName, mpftContext)) {
				return;
			}
			sourceType = getPropertyType(annotatedClass, className);
		} else if (annotatedClassOrMethod instanceof PsiMethod) {
			PsiMethod annotatedMethod = (PsiMethod) annotatedClassOrMethod;
			className = annotatedMethod.getContainingClass().getQualifiedName();
			methodName = annotatedMethod.getName();
			sourceType = getSourceType(annotatedMethod);
			sourceMethod = getSourceMethod(annotatedMethod);
		}
	} else {
		// Check if properties has been generated for the <annotation>:
		if (isProcessed(null, annotationName, mpftContext)) {
			return;
		}
	}

	String prefix = createPrefix(className, methodName, annotationName);

	// parameter
	List<AnnotationParameter> parameters = info.getParameters();
	for (AnnotationParameter parameter : parameters) {
		String propertyName = new StringBuilder(prefix).append('/').append(parameter.getName()).toString();
		String parameterType = parameter.getType();
		String description = parameter.getDescription();
		String defaultValue = getParameterDefaultValue(parameter, mpftAnnotation);
		String extensionName = null;
		if (annotatedClassOrMethod == null) {
			sourceType = parameter.getSourceType();
			sourceMethod = parameter.getSourceMethod();
		}
		// Enumerations
		PsiClass jdtType = parameter.getJDTType();
		super.updateHint(collector, jdtType);

		super.addItemMetadata(collector, propertyName, parameterType, description, sourceType, null, sourceMethod,
				defaultValue, extensionName, binary);
	}
}
 
源代码15 项目: lombok-intellij-plugin   文件: PsiTypeUtil.java
@Nullable
public static String getQualifiedName(@NotNull PsiType psiType) {
  final PsiClass psiFieldClass = PsiUtil.resolveClassInType(psiType);
  return psiFieldClass != null ? psiFieldClass.getQualifiedName() : null;
}
 
源代码16 项目: intellij-reference-diagram   文件: ClassFQN.java
public static ClassFQN create(PsiClass psiClass) {
    String className = psiClass.getQualifiedName();
    return new ClassFQN(className);
}
 
源代码17 项目: intellij-quarkus   文件: PsiTypeUtils.java
public static String getPropertyType(PsiClass psiClass, String typeName) {
    return psiClass != null ? psiClass.getQualifiedName() : typeName;
}
 
源代码18 项目: intellij   文件: ScalaTestContextProvider.java
private static String getTestFilter(PsiClass testClass) {
  // TODO: may need to append '#' if implementation changes.
  // https://github.com/bazelbuild/rules_scala/pull/216
  return testClass.getQualifiedName();
}
 
源代码19 项目: litho   文件: ReplacingConsumerTest.java
TestLookupElement(PsiClass cls) {
  name = cls.getQualifiedName();
  mock = cls;
}
 
@Override
public final ProblemDescriptor[] checkClass( @NotNull PsiClass psiClass,
                                             @NotNull InspectionManager manager,
                                             boolean isOnTheFly )
{
    // If psiClass is not an interface, ignore
    if( !psiClass.isInterface() )
    {
        return null;
    }

    // If @Mixins annotation is empty, ignore
    List<PsiAnnotationMemberValue> mixinAnnotationValues = getMixinsAnnotationValue( psiClass );
    if( mixinAnnotationValues.isEmpty() )
    {
        return null;
    }

    // Get all valid mixin type
    Set<PsiClass> validMixinsType = getAllValidMixinTypes( psiClass );
    if( validMixinsType.isEmpty() )
    {
        return null;
    }

    // For each mixin
    List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
    for( PsiAnnotationMemberValue mixinAnnotationValue : mixinAnnotationValues )
    {
        PsiJavaCodeReferenceElement mixinClassReference = getMixinClassReference( mixinAnnotationValue );

        // If it's not a class reference, ignore
        if( mixinClassReference == null )
        {
            continue;
        }

        // If class reference can't be resolved, ignore
        PsiClass mixinClass = (PsiClass) mixinClassReference.resolve();
        if( mixinClass == null )
        {
            continue;
        }

        String mixinQualifiedName = mixinClass.getQualifiedName();

        boolean isMixinsDeclarationValid = false;
        String message = "";
        if( mixinClass.isInterface() )
        {
            // Mixin can't be an interface
            message = message( "mixin.implements.mixin.type.error.mixin.is.an.interface", mixinQualifiedName );
        }
        else if( isAConcern( mixinClass ) )
        {
            // Mixin can't be a concern
            message = message( "mixin.implements.mixin.type.error.mixin.is.a.concern", mixinQualifiedName );
        }
        else if( isASideEffect( mixinClass ) )
        {
            // Mixin can't be a side effect
            message = message( "mixin.implements.mixin.type.error.mixin.is.a.side.effect", mixinQualifiedName );
        }
        else
        {
            // If doesn't implement any mixin type, it's a problem
            if( !isImplementValidMixinType( mixinClass, validMixinsType ) )
            {
                message = message(
                    "mixin.implements.mixin.type.error.does.not.implement.any.mixin.type",
                    mixinQualifiedName,
                    psiClass.getQualifiedName()
                );
            }
            else
            {
                isMixinsDeclarationValid = true;
            }
        }

        if( !isMixinsDeclarationValid )
        {
            ProblemDescriptor problemDescriptor = createProblemDescriptor(
                manager, mixinAnnotationValue, mixinClassReference, message );
            problems.add( problemDescriptor );
        }
    }

    return problems.toArray( new ProblemDescriptor[problems.size()] );
}