下面列出了com.intellij.psi.PsiModifierList#hasModifierProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override public boolean visitField(UField field) {
PsiModifierList modifierList = field.getModifierList();
if (modifierList == null || modifierList.hasModifierProperty(PsiModifier.TRANSIENT)) {
return false;
}
if (!isInJob(field)) {
return false;
}
if (hasAnnotation(modifierList, JAVAX_INJECT)) {
context.report(ISSUE, context.getLocation(field), LINT_ERROR_MESSAGE);
}
return super.visitField(field);
}
@Override
public void visitClass(JavaContext context, UClass declaration) {
PsiModifierList classModifiers = declaration.getModifierList();
if (classModifiers == null || !classModifiers.hasModifierProperty("abstract")) {
// check for static build method
boolean hasBuildMethod = false;
for (PsiMethod method : declaration.getMethods()) {
if ("build".equals(method.getName()) && method.getModifierList()
.hasModifierProperty("static")) {
hasBuildMethod = true;
break;
}
}
if (!hasBuildMethod){
context.report(BUILD_OVERWRITE, context.getLocation(declaration.getExtendsList()),
BUILD_OVERWRITE_MESSAGE);
}
// check for public static String TAG
boolean hasTag = false;
for (UField field : declaration.getFields()) {
PsiModifierList modifiers = field.getModifierList();
if ("TAG".equals(field.getName()) && LintUtils.isString(field.getType()) &&
modifiers != null && modifiers.hasModifierProperty("public") &&
modifiers.hasModifierProperty("static")) {
hasTag = true;
break;
}
}
if (!hasTag) {
context.report(TAG, context.getLocation(declaration.getExtendsList()), TAG_MESSAGE);
}
}
}
@Override
public void visitClass(JavaContext context, UClass declaration) {
PsiModifierList classModifiers = declaration.getModifierList();
if (classModifiers == null || !classModifiers.hasModifierProperty("abstract")) {
// check for static build method
boolean hasBuildMethod = false;
for (PsiMethod method : declaration.getMethods()) {
if ("build".equals(method.getName()) && method.getModifierList()
.hasModifierProperty("static")) {
hasBuildMethod = true;
break;
}
}
if (!hasBuildMethod){
context.report(BUILD_OVERWRITE, context.getLocation(declaration.getExtendsList()),
BUILD_OVERWRITE_MESSAGE);
}
// check for public static String TAG
boolean hasTag = false;
for (UField field : declaration.getFields()) {
PsiModifierList modifiers = field.getModifierList();
if ("TAG".equals(field.getName()) && LintUtils.isString(field.getType()) &&
modifiers != null && modifiers.hasModifierProperty("public") &&
modifiers.hasModifierProperty("static")) {
hasTag = true;
break;
}
}
if (!hasTag) {
context.report(TAG, context.getLocation(declaration.getExtendsList()), TAG_MESSAGE);
}
}
}
/**
* Validates whether the variable has {@code @Service} annotation declared correctly.
*
* @param variable variable to check.
* @return Look at {@link ServiceAnnotationDeclarationValidationResult}.
* @since 0.1
*/
@NotNull
public static ServiceAnnotationDeclarationValidationResult isValidServiceAnnotationDeclaration(
@NotNull PsiVariable variable )
{
PsiAnnotation serviceAnnotation = getServiceAnnotation( variable );
if( serviceAnnotation == null )
{
return invalidServiceAnnotationNotDeclared;
}
PsiModifierList modifierList = variable.getModifierList();
if( modifierList != null )
{
if( modifierList.hasModifierProperty( STATIC ) )
{
return invalidDeclaredOnStaticVariable;
}
}
// Can't be type that is injected by @Structure
if( isInjecteableByStructureAnnotation( variable ) )
{
return invalidTypeIsInjectedViaStructureAnnotation;
}
return valid;
}
@Override
public final ProblemDescriptor[] checkField( @NotNull PsiField field,
@NotNull InspectionManager manager,
boolean isOnTheFly )
{
PsiAnnotation annotationToCheck = getAnnotationToCheck( field );
if( annotationToCheck == null )
{
return null;
}
PsiModifierList modifierList = field.getModifierList();
if( modifierList != null )
{
if( modifierList.hasModifierProperty( com.intellij.psi.PsiModifier.STATIC ) )
{
String message = getInjectionAnnotationValidDeclarationMessage();
AbstractFix removeAnnotationFix = createRemoveAnnotationFix( annotationToCheck );
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(
annotationToCheck, message, removeAnnotationFix, com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING
);
return new ProblemDescriptor[]{ problemDescriptor };
}
}
return verifyAnnotationDeclaredCorrectly( field, annotationToCheck, manager );
}
@NotNull
Collection<PsiField> filterFields(@NotNull PsiClass psiClass, PsiAnnotation psiAnnotation) {
final Collection<PsiField> psiFields = new ArrayList<>();
final boolean onlyExplicitlyIncluded = PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, "onlyExplicitlyIncluded", false);
for (PsiField psiField : PsiClassUtil.collectClassFieldsIntern(psiClass)) {
boolean useField = true;
PsiModifierList modifierList = psiField.getModifierList();
if (null != modifierList) {
//Skip static fields.
useField = !modifierList.hasModifierProperty(PsiModifier.STATIC);
//Skip transient fields
useField &= !modifierList.hasModifierProperty(PsiModifier.TRANSIENT);
}
//Skip fields that start with $
useField &= !psiField.getName().startsWith(LombokUtils.LOMBOK_INTERN_FIELD_MARKER);
//Skip fields annotated with @FieldNameConstants.Exclude
useField &= !PsiAnnotationSearchUtil.isAnnotatedWith(psiField, FIELD_NAME_CONSTANTS_EXCLUDE);
if (onlyExplicitlyIncluded) {
//Only use fields annotated with @FieldNameConstants.Include, Include annotation overrides other rules
useField = PsiAnnotationSearchUtil.isAnnotatedWith(psiField, FIELD_NAME_CONSTANTS_INCLUDE);
}
if (useField) {
psiFields.add(psiField);
}
}
return psiFields;
}
private static boolean isStatic(PsiModifierList modifierList) {
return modifierList != null && modifierList.hasModifierProperty(PsiModifier.STATIC);
}
/**
* Returns true if the given field can generate a Quarkus property and false
* otherwise.
*
* @param field
* @return true if the given field can generate a Quarkus property and false
* otherwise.
*/
private static boolean canProcess(PsiField field) {
PsiModifierList flags = field.getModifierList();
return !flags.hasModifierProperty(PsiModifier.STATIC) && !flags.hasModifierProperty(PsiModifier.PRIVATE);
}