本文整理汇总了Java中com.intellij.codeInsight.AnnotationUtil.findAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtil.findAnnotation方法的具体用法?Java AnnotationUtil.findAnnotation怎么用?Java AnnotationUtil.findAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.AnnotationUtil
的用法示例。
在下文中一共展示了AnnotationUtil.findAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: targetTypesForDefault
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Nullable
private static Set<PsiAnnotation.TargetType> targetTypesForDefault(PsiAnnotation annotation) {
PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
PsiElement declaration = element == null ? null : element.resolve();
if (!(declaration instanceof PsiClass)) {
return Collections.emptySet();
}
PsiClass classDeclaration = (PsiClass) declaration;
PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);
if (tqDefault == null) {
return Collections.emptySet();
}
return extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例2: isNullabilityAnnotationForTypeQualifierDefault
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static boolean isNullabilityAnnotationForTypeQualifierDefault(PsiAnnotation annotation,
boolean nullable,
PsiAnnotation.TargetType[] targetTypes) {
PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
PsiElement declaration = element == null ? null : element.resolve();
if (!(declaration instanceof PsiClass)) {
return false;
}
String fqn = nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL;
PsiClass classDeclaration = (PsiClass) declaration;
if (!AnnotationUtil.isAnnotated(classDeclaration, fqn, false, true)) {
return false;
}
PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);
if (tqDefault == null) {
return false;
}
Set<PsiAnnotation.TargetType> required = extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
return required != null
&& (required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(targetTypes)));
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:25,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java
示例3: checkMethod
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Nullable
@Override
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
final String dataProviderFqn = DataProvider.class.getName();
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, dataProviderFqn);
if (annotation != null) {
final PsiType returnType = method.getReturnType();
if (returnType != null && !isSuitableReturnType(returnType)) {
final PsiTypeElement returnTypeElement = method.getReturnTypeElement();
LOG.assertTrue(returnTypeElement != null);
//noinspection DialogTitleCapitalization
return new ProblemDescriptor[]{manager.createProblemDescriptor(returnTypeElement,
"Data provider must return Object[][] or Iterator<Object[]>",
true,
createFixes(method),
ProblemHighlightType.ERROR)};
}
}
return null;
}
示例4: annotateOnOverrideImplement
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static void annotateOnOverrideImplement(PsiMethod method, PsiClass targetClass, PsiMethod overridden, boolean insertOverride) {
if (insertOverride && canInsertOverride(overridden, targetClass)) {
final String overrideAnnotationName = Override.class.getName();
if (!AnnotationUtil.isAnnotated(method, overrideAnnotationName, false, true)) {
AddAnnotationPsiFix.addPhysicalAnnotation(overrideAnnotationName, PsiNameValuePair.EMPTY_ARRAY, method.getModifierList());
}
}
final Module module = ModuleUtilCore.findModuleForPsiElement(targetClass);
final GlobalSearchScope moduleScope = module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : null;
final Project project = targetClass.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
for (OverrideImplementsAnnotationsHandler each : Extensions.getExtensions(OverrideImplementsAnnotationsHandler.EP_NAME)) {
for (String annotation : each.getAnnotations(project)) {
if (moduleScope != null && facade.findClass(annotation, moduleScope) == null) continue;
if (AnnotationUtil.isAnnotated(overridden, annotation, false, false) && !AnnotationUtil.isAnnotated(method, annotation, false, false)) {
PsiAnnotation psiAnnotation = AnnotationUtil.findAnnotation(overridden, annotation);
if (psiAnnotation != null && AnnotationUtil.isInferredAnnotation(psiAnnotation)) {
continue;
}
AddAnnotationPsiFix.removePhysicalAnnotations(method, each.annotationsToRemove(project, annotation));
AddAnnotationPsiFix.addPhysicalAnnotation(annotation, PsiNameValuePair.EMPTY_ARRAY, method.getModifierList());
}
}
}
}
示例5: getAnnotationMemberSuppressedIn
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
static PsiElement getAnnotationMemberSuppressedIn(@NotNull PsiModifierListOwner owner, @NotNull String inspectionToolID) {
final PsiAnnotation generatedAnnotation = AnnotationUtil.findAnnotation(owner, Generated.class.getName());
if (generatedAnnotation != null) return generatedAnnotation;
PsiModifierList modifierList = owner.getModifierList();
Collection<String> suppressedIds = getInspectionIdsSuppressedInAnnotation(modifierList);
for (String ids : suppressedIds) {
if (SuppressionUtil.isInspectionToolIdMentioned(ids, inspectionToolID)) {
return modifierList != null ? AnnotationUtil.findAnnotation(owner, SUPPRESS_INSPECTIONS_ANNOTATION_NAME) : null;
}
}
return null;
}
示例6: isAvailable
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
PsiModifierListOwner element = getElement(editor, file);
if (element == null ||
(!ApplicationManager.getApplication().isUnitTestMode() && element.getManager().isInProject(element)) ||
AnnotationUtil.findAnnotation(element, Nls.class.getName()) != null) return false;
return true;
}
示例7: calcSubstituted
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Nullable
private Object calcSubstituted(final PsiModifierListOwner owner) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(owner, myConfiguration.getAdvancedConfiguration().getSubstAnnotationPair().second);
if (annotation != null) {
return AnnotationUtilEx.calcAnnotationValue(annotation, "value");
}
return null;
}
示例8: visitMethod
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, "org.testng.annotations.Test");
if (annotation == null) {
return;
}
final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue("expectedExceptions");
if (!(value instanceof PsiClassObjectAccessExpression)) {
return;
}
final PsiCodeBlock body = method.getBody();
if (body == null) {
return;
}
final PsiClassObjectAccessExpression classObjectAccessExpression = (PsiClassObjectAccessExpression)value;
final PsiTypeElement operand = classObjectAccessExpression.getOperand();
final PsiType type = operand.getType();
if (!(type instanceof PsiClassType)) {
return;
}
final PsiClassType classType = (PsiClassType)type;
final PsiClass aClass = classType.resolve();
if (InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
return;
}
final List<PsiClassType> exceptionsThrown = ExceptionUtil.getThrownExceptions(body);
for (PsiClassType psiClassType : exceptionsThrown) {
if (psiClassType.isAssignableFrom(classType)) {
return;
}
}
myProblemsHolder.registerProblem(operand, "Expected <code>#ref</code> never thrown in body of '" + method.getName() + "()' #loc");
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:ExpectedExceptionNeverThrownTestNGInspection.java
示例9: deleteOverrideAnnotationIfFound
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static void deleteOverrideAnnotationIfFound(PsiMethod oMethod) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(oMethod, CommonClassNames.JAVA_LANG_OVERRIDE);
if (annotation != null) {
PsiElement prev = annotation.getPrevSibling();
PsiElement next = annotation.getNextSibling();
if ((prev == null || org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isLineFeed(prev)) &&
org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isLineFeed(next)) {
next.delete();
}
annotation.delete();
}
}
示例10: checkNotNullFieldsInitialized
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static void checkNotNullFieldsInitialized(PsiField field,
Annotated annotated,
NullableNotNullManager manager, @NotNull ProblemsHolder holder) {
if (annotated.isDeclaredNotNull && !HighlightControlFlowUtil.isFieldInitializedAfterObjectConstruction(field)) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(field, manager.getNotNulls());
if (annotation != null) {
holder.registerProblem(annotation.isPhysical() ? annotation : field.getNameIdentifier(),
"Not-null fields must be initialized",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
}
示例11: createChangeDefaultNotNullFix
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static LocalQuickFix createChangeDefaultNotNullFix(NullableNotNullManager nullableManager, PsiModifierListOwner modifierListOwner) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(modifierListOwner, nullableManager.getNotNulls());
if (annotation != null) {
final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (referenceElement != null && referenceElement.resolve() != null) {
return new ChangeNullableDefaultsFix(annotation.getQualifiedName(), null, nullableManager);
}
}
return null;
}
示例12: isImmutable
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static boolean isImmutable(PsiClass aClass) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, IMMUTABLE);
if (annotation != null) {
return true;
}
PsiDocComment comment = aClass.getDocComment();
return comment != null && comment.findTagByName("@Immutable") != null;
}
示例13: extractDataPointsHolder
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static Pair<PsiMember, PsiAnnotation> extractDataPointsHolder(@NotNull final PsiElement element) {
if (!(element instanceof PsiIdentifier)) {
return null;
}
final PsiElement maybeHolder = element.getParent();
if (maybeHolder == null || !(maybeHolder instanceof PsiMethod || maybeHolder instanceof PsiField)) {
return null;
}
final PsiMember holder = (PsiMember)maybeHolder;
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(holder, DATA_POINT_FQN, DATA_POINTS_FQN);
return annotation == null ? null : Pair.create(holder, annotation);
}
示例14: isParameterized
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
public boolean isParameterized(PsiClass clazz) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(clazz, JUnitUtil.RUN_WITH);
if (annotation != null) {
final PsiAnnotationMemberValue value = annotation.findAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME);
if (value instanceof PsiClassObjectAccessExpression) {
final PsiTypeElement operand = ((PsiClassObjectAccessExpression)value).getOperand();
final PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(operand.getType());
return psiClass != null && "org.junit.runners.Parameterized".equals(psiClass.getQualifiedName());
}
}
return false;
}
示例15: removePhysicalAnnotations
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static void removePhysicalAnnotations(PsiModifierListOwner owner, String... fqns) {
for (String fqn : fqns) {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(owner, fqn);
if (annotation != null && !AnnotationUtil.isInferredAnnotation(annotation)) {
annotation.delete();
}
}
}