本文整理汇总了Java中com.intellij.psi.util.PsiUtil.isAnnotationMethod方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.isAnnotationMethod方法的具体用法?Java PsiUtil.isAnnotationMethod怎么用?Java PsiUtil.isAnnotationMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.isAnnotationMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAttributeValue
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
public static PsiAnnotationMemberValue findAttributeValue(@NotNull PsiAnnotation annotation, @Nullable @NonNls String attributeName) {
final PsiAnnotationMemberValue value = findDeclaredAttributeValue(annotation, attributeName);
if (value != null) return value;
if (attributeName == null) attributeName = "value";
final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (referenceElement != null) {
PsiElement resolved = referenceElement.resolve();
if (resolved != null) {
PsiMethod[] methods = ((PsiClass)resolved).findMethodsByName(attributeName, false);
for (PsiMethod method : methods) {
if (PsiUtil.isAnnotationMethod(method)) {
return ((PsiAnnotationMethod)method).getDefaultValue();
}
}
}
}
return null;
}
示例2: checkConstantExpression
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
static HighlightInfo checkConstantExpression(PsiExpression expression) {
final PsiElement parent = expression.getParent();
if (PsiUtil.isAnnotationMethod(parent) || parent instanceof PsiNameValuePair || parent instanceof PsiArrayInitializerMemberValue) {
if (!PsiUtil.isConstantExpression(expression)) {
String description = JavaErrorMessages.message("annotation.non.constant.attribute.value");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
}
}
return null;
}
示例3: findAnnotationMethod
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static PsiAnnotationMethod findAnnotationMethod(PsiFile file, int offset) {
PsiNameValuePair pair = ParameterInfoUtils.findParentOfType(file, offset, PsiNameValuePair.class);
if (pair == null) return null;
final PsiReference reference = pair.getReference();
final PsiElement resolved = reference != null ? reference.resolve():null;
return PsiUtil.isAnnotationMethod(resolved) ? (PsiAnnotationMethod)resolved : null;
}
示例4: shouldHaveAnnotationParameters
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
static boolean shouldHaveAnnotationParameters(PsiClass annoClass) {
for (PsiMethod m : annoClass.getMethods()) {
if (!PsiUtil.isAnnotationMethod(m)) continue;
if (((PsiAnnotationMethod)m).getDefaultValue() == null) return true;
}
return false;
}
示例5: findAnnotationMethod
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiAnnotationMethod findAnnotationMethod(@NotNull PsiFile file, @NotNull Editor editor) {
PsiNameValuePair pair = ParameterInfoUtils.findParentOfType(file, inferOffset(editor), PsiNameValuePair.class);
if (pair == null) return null;
final PsiReference reference = pair.getReference();
final PsiElement resolved = reference != null ? reference.resolve() : null;
return PsiUtil.isAnnotationMethod(resolved) ? (PsiAnnotationMethod)resolved : null;
}
示例6: checkMissingAttributes
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
static HighlightInfo checkMissingAttributes(PsiAnnotation annotation) {
PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
if (nameRef == null) return null;
PsiClass aClass = (PsiClass)nameRef.resolve();
if (aClass != null && aClass.isAnnotationType()) {
Set<String> names = new HashSet<String>();
PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
for (PsiNameValuePair attribute : attributes) {
final String name = attribute.getName();
if (name != null) {
names.add(name);
}
else {
names.add(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME);
}
}
PsiMethod[] annotationMethods = aClass.getMethods();
List<String> missed = new ArrayList<String>();
for (PsiMethod method : annotationMethods) {
if (PsiUtil.isAnnotationMethod(method)) {
PsiAnnotationMethod annotationMethod = (PsiAnnotationMethod)method;
if (annotationMethod.getDefaultValue() == null) {
if (!names.contains(annotationMethod.getName())) {
missed.add(annotationMethod.getName());
}
}
}
}
if (!missed.isEmpty()) {
StringBuffer buff = new StringBuffer("'" + missed.get(0) + "'");
for (int i = 1; i < missed.size(); i++) {
buff.append(", ");
buff.append("'").append(missed.get(i)).append("'");
}
String description = JavaErrorMessages.message("annotation.missing.attribute", buff);
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(nameRef).descriptionAndTooltip(description).create();
IntentionAction fix = QuickFixFactory.getInstance().createAddMissingRequiredAnnotationParametersFix(
annotation, annotationMethods, missed);
QuickFixAction.registerQuickFixAction(info, fix);
return info;
}
}
return null;
}