Пример #1
0
 public static String isValidMethodExpression(PsiElement psiElement) {
   if (psiElement instanceof PsiMethodCallExpression) {
     final PsiReferenceExpression methodExpression =
         ((PsiMethodCallExpression) psiElement).getMethodExpression();
     if (methodExpression != null
         && methodExpression.getQualifierExpression() != null
         && methodExpression.getQualifierExpression().getType() != null) {
       final PsiType type = methodExpression.getQualifierExpression().getType();
       if (type instanceof PsiClassReferenceType) {
         final PsiClassReferenceType classReferenceType = (PsiClassReferenceType) type;
         if (classReferenceType.getReference() != null) {
           final Project project = psiElement.getProject();
           if (AnnoRefConfigSettings.getInstance(project)
               .getAnnoRefState()
               .ANNOREF_UTIL_CLASS_FQN
               .equals(classReferenceType.getReference().getQualifiedName())) {
             if (((PsiCall) psiElement).getArgumentList().getExpressions().length == 1) {
               final PsiExpression psiExpression =
                   ((PsiCall) psiElement).getArgumentList().getExpressions()[0];
               return String.valueOf(((PsiLiteral) psiExpression).getValue());
             }
           }
         }
       }
     }
   }
   return null;
 }
Пример #2
0
 public static SQLRefReference getAnnoRefIdFromMethodCallExpressionElement(PsiElement psiElement) {
   if (psiElement instanceof PsiMethodCallExpression) {
     final PsiReferenceExpression methodExpression =
         ((PsiMethodCallExpression) psiElement).getMethodExpression();
     if (methodExpression != null
         && methodExpression.getQualifierExpression() != null
         && methodExpression.getQualifierExpression().getType() != null) {
       final PsiType type = methodExpression.getQualifierExpression().getType();
       final PsiClassReferenceType classReferenceType = (PsiClassReferenceType) type;
       if (type instanceof PsiClassReferenceType && classReferenceType.getReference() != null) {
         final Project project = psiElement.getProject();
         if (AnnoRefConfigSettings.getInstance(project)
             .getAnnoRefState()
             .ANNOREF_UTIL_CLASS_FQN
             .equals(classReferenceType.getReference().getQualifiedName())) {
           if (((PsiCall) psiElement).getArgumentList().getExpressions().length == 1) {
             final PsiExpression psiExpression =
                 ((PsiCall) psiElement).getArgumentList().getExpressions()[0];
             final String refId = String.valueOf(((PsiLiteral) psiExpression).getValue());
             final SQLRefReference refReference =
                 ServiceManager.getService(project, SQLRefRepository.class)
                     .getSQLRefReferenceForID(refId);
             return refReference;
           } else {
             throw new IllegalArgumentException(
                 String.format(
                     "Argument %s for parameter of %s.%s must not be null",
                     new Object[] {
                       "0",
                       classReferenceType.getReference().getQualifiedName(),
                       methodExpression.getQualifiedName()
                     }));
           }
         } else {
           log.warn(
               "getAnnoRefIdFromMethodCallExpressionElement(): PsiElement ClassReferenceType FQA="
                   + classReferenceType.getReference().getQualifiedName()
                   + " different"
                   + " from ANNOREF_UTIL_CLASS_FQN="
                   + AnnoRefConfigSettings.getInstance(project)
                       .getAnnoRefState()
                       .ANNOREF_UTIL_CLASS_FQN);
         }
       } else {
         log.warn(
             "getAnnoRefIdFromMethodCallExpressionElement(): PsiElement ReferenceType="
                 + classReferenceType);
       }
     } else {
       log.warn(
           "getAnnoRefIdFromMethodCallExpressionElement(): PsiElement is of type="
               + psiElement.getClass());
     }
   }
   return null;
 }