예제 #1
0
 public static String cleanRefIdForPsiElement(PsiElement element) {
   final Language language = element.getLanguage();
   if (language instanceof JavaLanguage) {
     if (element instanceof PsiModifierList) {
       PsiAnnotation[] annotations = ((PsiAnnotationOwner) element).getAnnotations();
       for (PsiAnnotation annotation : annotations) {
         if (AnnoRefConfigSettings.getInstance(element.getProject())
             .getAnnoRefState()
             .ANNOREF_ANNOTATION_FQN
             .equals(annotation.getQualifiedName())) {
           String refKey =
               SQLRefNamingUtil.cleanAnnoRefForName(annotation.getContainingFile(), annotation);
           if (refKey != null) {
             return refKey;
           }
         }
       }
     }
     if (element instanceof PsiAnnotation) {
       final PsiAnnotation psiAnnotation = (PsiAnnotation) element;
       if (AnnoRefConfigSettings.getInstance(element.getProject())
           .getAnnoRefState()
           .ANNOREF_ANNOTATION_FQN
           .equals(psiAnnotation.getQualifiedName())) {
         String cleanedAnnoRef =
             SQLRefNamingUtil.cleanAnnoRefForName(
                 psiAnnotation.getContainingFile(), psiAnnotation);
         if (cleanedAnnoRef != null) {
           return cleanedAnnoRef;
         }
       }
       if (element instanceof PsiJavaToken
           && ((PsiJavaToken) element).getTokenType() == JavaTokenType.STRING_LITERAL) {
         final String refKey = StringUtils.cleanQuote(element.getText());
         if (refKey != null) {
           return refKey;
         }
       }
     }
   }
   if (language instanceof XMLLanguage) {
     if (SQLRefNamingUtil.isPropitiousXmlFile(element.getContainingFile())) {
       final boolean isXmlTokenValid =
           new FilterElementProcessor(
                   new XmlTokenTypeFilter(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN))
               .execute(element);
       if (isXmlTokenValid) {
         final String refKey = getSqlRefKey(element);
         if (refKey != null) {
           return refKey;
         }
       }
     }
   }
   return null;
 }
예제 #2
0
 private static SQLRefReference getValidAnnoReference(
     final PsiAnnotation annotation, final Project project) {
   if (AnnoRefConfigSettings.getInstance(project)
       .getAnnoRefState()
       .ANNOREF_ANNOTATION_FQN
       .equals(annotation.getQualifiedName())) {
     String cleanedAnnoRef =
         SQLRefNamingUtil.cleanAnnoRefForName(annotation.getContainingFile(), annotation);
     if (cleanedAnnoRef != null) {
       SQLRefReference sqlRefReferenceForID =
           ServiceManager.getService(project, SQLRefRepository.class)
               .getSQLRefReferenceForID(cleanedAnnoRef);
       if (!sqlRefReferenceForID.getXmlQueryElements().isEmpty()) {
         return sqlRefReferenceForID;
       }
     }
   }
   return null;
 }
예제 #3
0
 public static SQLRefReference isValidAnnoRef(PsiElement psiElement) {
   final Language language = psiElement.getLanguage();
   final Project project = psiElement.getProject();
   if (language instanceof JavaLanguage) {
     if (psiElement instanceof PsiModifierList) {
       PsiAnnotation[] annotations = ((PsiAnnotationOwner) psiElement).getAnnotations();
       for (PsiAnnotation annotation : annotations) {
         return getValidAnnoReference(annotation, project);
       }
     }
     if (psiElement instanceof PsiAnnotation) {
       return getValidAnnoReference((PsiAnnotation) psiElement, project);
     }
     if (psiElement instanceof PsiJavaToken
         && ((PsiJavaToken) psiElement).getTokenType() == JavaTokenType.STRING_LITERAL) {
       return getValidAnnoReference(StringUtils.cleanQuote(psiElement.getText()), project);
     }
   }
   if (language instanceof XMLLanguage) {
     if (SQLRefNamingUtil.isPropitiousXmlFile(psiElement.getContainingFile())) {
       final boolean isXmlTokenValid =
           new FilterElementProcessor(
                   new XmlTokenTypeFilter(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN))
               .execute(psiElement);
       if (isXmlTokenValid) {
         final String sqlRefKey = getSqlRefKey(psiElement);
         if (sqlRefKey != null) {
           SQLRefReference sqlRefReferenceForID =
               ServiceManager.getService(psiElement.getProject(), SQLRefRepository.class)
                   .getSQLRefReferenceForID(sqlRefKey);
           if (sqlRefReferenceForID != null) {
             if (!sqlRefReferenceForID.getClassAnnoElements().isEmpty()) {
               return sqlRefReferenceForID;
             }
           }
         }
       }
     }
   }
   return null;
 }