예제 #1
0
 private static UsageTarget[] getTargetsForSQLReference(
     PsiElement psiElement, SQLRefReference sqlRefReferenceForID) {
   final List<PsiElement> primaryElementList = Lists.newArrayList();
   final List<PsiElement> secondaryElementList = Lists.newArrayList();
   if (psiElement.getLanguage() instanceof JavaLanguage) {
     for (final SmartPsiElementPointer<PsiElement> elementPointer :
         sqlRefReferenceForID.getXmlSmartPointersElements()) {
       primaryElementList.add(elementPointer.getElement());
     }
   } else if (psiElement.getLanguage() instanceof XMLLanguage) {
     for (final SmartPsiElementPointer<PsiElement> elementPointer :
         sqlRefReferenceForID.getClassSmartPointersElements()) {
       primaryElementList.add(elementPointer.getElement());
     }
     for (final SmartPsiElementPointer<PsiElement> elementPointer :
         sqlRefReferenceForID.getUtilClassSmartPointersElements().values()) {
       secondaryElementList.add(elementPointer.getElement());
     }
   }
   PsiElement[] primeElements = new PsiElement[primaryElementList.size()];
   PsiElement[] secondaryElements = new PsiElement[secondaryElementList.size()];
   primaryElementList.toArray(primeElements);
   secondaryElementList.toArray(secondaryElements);
   //		return new UsageTarget[]{new PsiElement2UsageTargetAdapter(primeElements[0])};
   //		return new UsageTarget[new PsiElement2UsageTargetAdapter(primeElements[0],new
   // FindUsagesOptions(psiElement.getProject())};
   return new UsageTarget[] {
     new PsiElement2UsageTargetComposite(
         primeElements, secondaryElements, new FindUsagesOptions(psiElement.getProject()))
   };
 }
예제 #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;
 }