src/share/classes/com/sun/tools/apt/comp/Apt.java

Print this page




 479             } catch (Throwable t) {
 480                 throw new AnnotationProcessingError(t);
 481             }
 482 
 483             // Invoke listener callback mechanism
 484             trivAPE.roundComplete();
 485 
 486             FilerImpl filerimpl = (FilerImpl)trivAPE.getFiler();
 487             genSourceFileNames = filerimpl.getSourceFileNames();
 488             genClassFileNames = filerimpl.getClassFileNames();
 489             filerimpl.flush(); // Make sure new files are written out
 490         }
 491     }
 492 
 493     /**
 494      * Convert import-style string to regex matching that string.  If
 495      * the string is a valid import-style string, return a regex that
 496      * won't match anything.
 497      */
 498     Pattern importStringToPattern(String s) {
 499         if (s.equals("*")) {
 500             return allMatches;
 501         } else {
 502             String t = s;
 503             boolean star = false;
 504 
 505             /*
 506              * Validate string from factory is legal.  If the string
 507              * has more than one asterisks or the asterisks does not
 508              * appear as the last character (preceded by a period),
 509              * the string is not legal.
 510              */
 511 
 512             boolean valid = true;
 513             int index = t.indexOf('*');
 514             if (index != -1) {
 515                 // '*' must be last character...
 516                 if (index == t.length() -1) {
 517                      // ... and preceeding character must be '.'
 518                     if ( index-1 >= 0 ) {
 519                         valid = t.charAt(index-1) == '.';
 520                         // Strip off ".*$" for identifier checks
 521                         t = t.substring(0, t.length()-2);
 522                     }
 523                 } else
 524                     valid = false;
 525             }
 526 
 527             // Verify string is off the form (javaId \.)+ or javaId
 528             if (valid) {
 529                 String[] javaIds = t.split("\\.", t.length()+2);
 530                 for(String javaId: javaIds)
 531                     valid &= isJavaIdentifier(javaId);
 532             }
 533 
 534             if (!valid) {
 535                 Bark bark = Bark.instance(context);
 536                 bark.aptWarning("MalformedSupportedString", s);
 537                 return noMatches; // won't match any valid identifier
 538             }
 539 
 540             String s_prime = s.replaceAll("\\.", "\\\\.");
 541 
 542             if (s_prime.endsWith("*")) {
 543                 s_prime =  s_prime.substring(0, s_prime.length() - 1) + ".+";
 544             }
 545 
 546             return Pattern.compile(s_prime);
 547         }
 548     }
 549 
 550     private static final Pattern allMatches = Pattern.compile(".*");
 551     private static final Pattern noMatches  = Pattern.compile("(\\P{all})+");
 552 }


 479             } catch (Throwable t) {
 480                 throw new AnnotationProcessingError(t);
 481             }
 482 
 483             // Invoke listener callback mechanism
 484             trivAPE.roundComplete();
 485 
 486             FilerImpl filerimpl = (FilerImpl)trivAPE.getFiler();
 487             genSourceFileNames = filerimpl.getSourceFileNames();
 488             genClassFileNames = filerimpl.getClassFileNames();
 489             filerimpl.flush(); // Make sure new files are written out
 490         }
 491     }
 492 
 493     /**
 494      * Convert import-style string to regex matching that string.  If
 495      * the string is a valid import-style string, return a regex that
 496      * won't match anything.
 497      */
 498     Pattern importStringToPattern(String s) {
 499         if (com.sun.tools.javac.processing.JavacProcessingEnvironment.isValidImportString(s)) {
 500             return com.sun.tools.javac.processing.JavacProcessingEnvironment.validImportStringToPattern(s);
 501         } else {

































 502             Bark bark = Bark.instance(context);
 503             bark.aptWarning("MalformedSupportedString", s);
 504             return com.sun.tools.javac.processing.JavacProcessingEnvironment.noMatches;









 505         }
 506     }



 507 }