类com.intellij.psi.PsiEnumConstant源码实例Demo

下面列出了怎么用com.intellij.psi.PsiEnumConstant的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dagger-reflect   文件: WrongRetentionDetector.java
@NotNull
private static String getQualifiedNameForValueJava(
    @NotNull JavaContext context, @Nullable UExpression annotationValue) {
  final Object evaluatedAnnotationValue = ConstantEvaluator.evaluate(context, annotationValue);
  if (evaluatedAnnotationValue instanceof PsiEnumConstant) {
    return UastLintUtils.getQualifiedName((PsiEnumConstant) evaluatedAnnotationValue);
  }
  throw new IllegalStateException("RetentionPolicy must not be null if @Retention is present");
}
 
/**
 * 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;
}
 
源代码3 项目: component-runtime   文件: SuggestionServiceImpl.java
private Stream<Suggestion> fromConfiguration(final String family, final String configurationName,
        final PsiClass configClazz) {
    return Stream
            .concat(of(configClazz.getAllFields())
                    .filter(field -> AnnotationUtil.findAnnotation(field, OPTION) != null)
                    .flatMap(field -> {
                        final PsiAnnotation fOption = AnnotationUtil.findAnnotation(field, OPTION);
                        final PsiAnnotationMemberValue fOptionValue = fOption.findAttributeValue("value");

                        String fieldName = removeQuotes(fOptionValue.getText());
                        if (fieldName.isEmpty()) {
                            fieldName = field.getName();
                        }

                        final Suggestion displayNameSuggestion =
                                new Suggestion(configurationName + "." + fieldName + "." + DISPLAY_NAME,
                                        Suggestion.Type.Configuration);
                        final PsiType type = field.getType();
                        if ("java.lang.String".equals(type.getCanonicalText())) {
                            return Stream
                                    .of(displayNameSuggestion,
                                            new Suggestion(configurationName + "." + fieldName + "." + PLACEHOLDER,
                                                    Suggestion.Type.Configuration));
                        }
                        final PsiClass clazz = findClass(type);
                        if (clazz != null && clazz.isEnum()) {
                            return Stream
                                    .concat(Stream.of(displayNameSuggestion),
                                            Stream
                                                    .of(clazz.getFields())
                                                    .filter(PsiEnumConstant.class::isInstance)
                                                    .map(f -> clazz
                                                            .getName()
                                                            .substring(clazz.getName().lastIndexOf('.') + 1) + '.'
                                                            + f.getName() + "._displayName")
                                                    .map(v -> new Suggestion(v, Suggestion.Type.Configuration)));
                        }
                        return Stream.of(displayNameSuggestion);
                    }), extractConfigTypes(family, configClazz));
}
 
 类所在包
 类方法
 同包方法