本文整理汇总了Java中com.intellij.psi.PsiAnnotation.TargetType方法的典型用法代码示例。如果您正苦于以下问题:Java PsiAnnotation.TargetType方法的具体用法?Java PsiAnnotation.TargetType怎么用?Java PsiAnnotation.TargetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiAnnotation
的用法示例。
在下文中一共展示了PsiAnnotation.TargetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: targetTypesForDefault
import com.intellij.psi.PsiAnnotation; //导入方法依赖的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: findAnnotations
import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
static List<String> findAnnotations(PsiModifierListOwner element, boolean nullable) {
if (overridesSuper(element)) {
return Collections.emptyList();
}
List<String> annotations = new ArrayList<>();
Project project = element.getProject();
PsiModifierList modifierList = element.getModifierList();
List<String> nullabilityAnnotations = nullable
? NullableNotNullManager.getInstance(project).getNullables()
: NullableNotNullManager.getInstance(project).getNotNulls();
for (String notNullAnnotationFqn : nullabilityAnnotations) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + notNullAnnotationFqn, null);
PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(modifierList);
if (isNullabilityAnnotationForTypeQualifierDefault(annotation, nullable, targetTypes)) {
annotations.add(annotation.getQualifiedName());
}
}
return annotations;
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:22,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java
示例3: isNullabilityAnnotationForTypeQualifierDefault
import com.intellij.psi.PsiAnnotation; //导入方法依赖的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
示例4: removeRedundantAnnotations
import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
private void removeRedundantAnnotations(PsiModifierListOwner element,
List<String> redundantAnnotations,
Set<PsiAnnotation.TargetType> targetsForDefaultAnnotation) {
PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(element.getModifierList());
boolean isTargeted = targetsForDefaultAnnotation.isEmpty()
|| ContainerUtil.intersects(targetsForDefaultAnnotation, Arrays.asList(targetTypes));
if (isTargeted) {
removePhysicalAnnotations(element, ArrayUtil.toStringArray(redundantAnnotations));
}
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:11,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例5: removeRedundantAnnotationsInPackage
import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
private void removeRedundantAnnotationsInPackage(Project project, PsiFile[] files, PsiAnnotation annotation) {
if (!removeRedundantAnnotations)
{
return;
}
List<String> redundantAnnotations = nullable
? NullableNotNullManager.getInstance(project).getNullables()
: NullableNotNullManager.getInstance(project).getNotNulls();
Set<PsiAnnotation.TargetType> targetsForDefaultAnnotation = targetTypesForDefault(annotation);
if (targetsForDefaultAnnotation == null) {
return;
}
for (PsiFile file : files) {
if (file instanceof PsiJavaFile) {
JavaElementVisitor visitor = new JavaElementVisitor() {
@Override
public void visitMethod(@Nonnull PsiMethod method) {
removeRedundantAnnotations(method, redundantAnnotations, targetsForDefaultAnnotation);
}
@Override
public void visitParameter(@Nonnull PsiParameter parameter) {
removeRedundantAnnotations(parameter, redundantAnnotations, targetsForDefaultAnnotation);
}
@Override
public void visitField(@Nonnull PsiField field) {
removeRedundantAnnotations(field, redundantAnnotations, targetsForDefaultAnnotation);
}
@Override
public void visitLocalVariable(@Nonnull PsiLocalVariable variable) {
super.visitLocalVariable(variable);
}
};
PsiRecursiveElementWalkingVisitor recursiveVisitor = new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(@Nonnull PsiElement element) {
element.accept(visitor);
super.visitElement(element);
}
};
file.accept(recursiveVisitor);
JavaCodeStyleManager.getInstance(project).optimizeImports(file);
}
}
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:55,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java