@@ -185,8 +185,7 @@ protected final void parse(Class<?> clazz, String beanName) throws IOException {
185185
186186
187187 protected void processConfigurationClass (ConfigurationClass configClass ) throws IOException {
188-
189- if (conditionEvaluator .shouldSkip (configClass .getMetadata (), ConfigurationPhase .PARSE_CONFIGURATION )) {
188+ if (this .conditionEvaluator .shouldSkip (configClass .getMetadata (), ConfigurationPhase .PARSE_CONFIGURATION )) {
190189 return ;
191190 }
192191
@@ -219,9 +218,7 @@ protected void processConfigurationClass(ConfigurationClass configClass) throws
219218 * @param sourceClass a source class
220219 * @return the superclass, {@code null} if none found or previously processed
221220 */
222- protected final SourceClass doProcessConfigurationClass (
223- ConfigurationClass configClass , SourceClass sourceClass ) throws IOException {
224-
221+ protected final SourceClass doProcessConfigurationClass (ConfigurationClass configClass , SourceClass sourceClass ) throws IOException {
225222 // recursively process any member (nested) classes first
226223 processMemberClasses (configClass , sourceClass );
227224
@@ -350,18 +347,15 @@ private Set<SourceClass> getImports(SourceClass sourceClass) throws IOException
350347 * meta-annotations it is valid to have several {@code @Import}s declared with
351348 * different values, the usual process or returning values from the first
352349 * meta-annotation on a class is not sufficient.
353- * <p>
354- * For example, it is common for a {@code @Configuration} class to declare direct
350+ * <p>For example, it is common for a {@code @Configuration} class to declare direct
355351 * {@code @Import}s in addition to meta-imports originating from an {@code @Enable}
356352 * annotation.
357- *
358353 * @param sourceClass the class to search
359354 * @param imports the imports collected so far
360355 * @param visited used to track visited classes to prevent infinite recursion
361356 * @throws IOException if there is any problem reading metadata from the named class
362357 */
363- private void collectImports (SourceClass sourceClass , Set <SourceClass > imports ,
364- Set <SourceClass > visited ) throws IOException {
358+ private void collectImports (SourceClass sourceClass , Set <SourceClass > imports , Set <SourceClass > visited ) throws IOException {
365359 try {
366360 if (visited .add (sourceClass )) {
367361 for (SourceClass annotation : sourceClass .getAnnotations ()) {
@@ -392,9 +386,9 @@ private void processDeferredImportSelectors() {
392386 this .deferredImportSelectors .clear ();
393387 }
394388
395- private void processImports (ConfigurationClass configClass ,
396- Collection <SourceClass > sourceClasses , boolean checkForCircularImports )
389+ private void processImports (ConfigurationClass configClass , Collection <SourceClass > sourceClasses , boolean checkForCircularImports )
397390 throws IOException {
391+
398392 if (sourceClasses .isEmpty ()) {
399393 return ;
400394 }
@@ -494,8 +488,7 @@ ImportRegistry getImportRegistry() {
494488 /**
495489 * Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
496490 */
497- public SourceClass asSourceClass (ConfigurationClass configurationClass )
498- throws IOException {
491+ public SourceClass asSourceClass (ConfigurationClass configurationClass ) throws IOException {
499492 try {
500493 AnnotationMetadata metadata = configurationClass .getMetadata ();
501494 if (metadata instanceof StandardAnnotationMetadata ) {
@@ -511,8 +504,7 @@ public SourceClass asSourceClass(ConfigurationClass configurationClass)
511504 /**
512505 * Factory method to obtain a {@link SourceClass} from a {@link Class}.
513506 */
514- public SourceClass asSourceClass (Class <?> classType )
515- throws ClassNotFoundException , IOException {
507+ public SourceClass asSourceClass (Class <?> classType ) throws IOException , ClassNotFoundException {
516508 try {
517509 // Sanity test that we can read annotations, if not fall back to ASM
518510 classType .getAnnotations ();
@@ -526,10 +518,9 @@ public SourceClass asSourceClass(Class<?> classType)
526518 /**
527519 * Factory method to obtain {@link SourceClass}s from class names.
528520 */
529- public Collection <SourceClass > asSourceClasses (String [] classNamess )
530- throws ClassNotFoundException , IOException {
521+ public Collection <SourceClass > asSourceClasses (String [] classNames ) throws IOException , ClassNotFoundException {
531522 List <SourceClass > annotatedClasses = new ArrayList <SourceClass >();
532- for (String className : classNamess ) {
523+ for (String className : classNames ) {
533524 annotatedClasses .add (asSourceClass (className ));
534525 }
535526 return annotatedClasses ;
@@ -538,12 +529,10 @@ public Collection<SourceClass> asSourceClasses(String[] classNamess)
538529 /**
539530 * Factory method to obtain a {@link SourceClass} from a class name.
540531 */
541- public SourceClass asSourceClass (String className )
542- throws ClassNotFoundException , IOException {
532+ public SourceClass asSourceClass (String className ) throws IOException , ClassNotFoundException {
543533 if (className .startsWith ("java" )) {
544534 // Never use ASM for core java types
545- return new SourceClass (this .resourceLoader .getClassLoader ().loadClass (
546- className ));
535+ return new SourceClass (this .resourceLoader .getClassLoader ().loadClass ( className ));
547536 }
548537 return new SourceClass (this .metadataReaderFactory .getMetadataReader (className ));
549538 }
@@ -642,8 +631,7 @@ private class SourceClass {
642631
643632 private final AnnotationMetadata metadata ;
644633
645-
646- private SourceClass (Object source ) {
634+ public SourceClass (Object source ) {
647635 this .source = source ;
648636 if (source instanceof Class <?>) {
649637 this .metadata = new StandardAnnotationMetadata ((Class <?>) source , true );
@@ -653,40 +641,42 @@ private SourceClass(Object source) {
653641 }
654642 }
655643
644+ public final AnnotationMetadata getMetadata () {
645+ return this .metadata ;
646+ }
656647
657648 public Class <?> loadClass () throws ClassNotFoundException {
658- if ( source instanceof Class <?>) {
659- return (Class <?>) source ;
649+ if ( this . source instanceof Class <?>) {
650+ return (Class <?>) this . source ;
660651 }
661652 String className = ((MetadataReader ) source ).getClassMetadata ().getClassName ();
662653 return resourceLoader .getClassLoader ().loadClass (className );
663654 }
664655
665656 public boolean isAssignable (Class <?> clazz ) throws IOException {
666- if (source instanceof Class ) {
667- return clazz .isAssignableFrom ((Class ) source );
657+ if (this . source instanceof Class ) {
658+ return clazz .isAssignableFrom ((Class ) this . source );
668659 }
669- return new AssignableTypeFilter (clazz ).match ((MetadataReader ) source ,
670- metadataReaderFactory );
660+ return new AssignableTypeFilter (clazz ).match ((MetadataReader ) this .source , metadataReaderFactory );
671661 }
672662
673- public ConfigurationClass asConfigClass (ConfigurationClass importedBy )
674- throws IOException {
663+ public ConfigurationClass asConfigClass (ConfigurationClass importedBy ) throws IOException {
675664 if (this .source instanceof Class <?>) {
676665 return new ConfigurationClass ((Class <?>) this .source , importedBy );
677666 }
678- return new ConfigurationClass ((MetadataReader ) source , importedBy );
667+ return new ConfigurationClass ((MetadataReader ) this . source , importedBy );
679668 }
680669
681670 public Collection <SourceClass > getMemberClasses () throws IOException {
682671 List <SourceClass > members = new ArrayList <SourceClass >();
683- if (source instanceof Class <?>) {
684- Class <?> sourceClass = (Class <?>) source ;
672+ if (this . source instanceof Class <?>) {
673+ Class <?> sourceClass = (Class <?>) this . source ;
685674 for (Class <?> declaredClass : sourceClass .getDeclaredClasses ()) {
686675 try {
687676 members .add (asSourceClass (declaredClass ));
688677 }
689- catch (ClassNotFoundException e ) {
678+ catch (ClassNotFoundException ex ) {
679+ // ignore
690680 }
691681 }
692682 }
@@ -696,34 +686,34 @@ public Collection<SourceClass> getMemberClasses() throws IOException {
696686 try {
697687 members .add (asSourceClass (memberClassName ));
698688 }
699- catch (ClassNotFoundException e ) {
689+ catch (ClassNotFoundException ex ) {
690+ // ignore
700691 }
701692 }
702693 }
703694 return members ;
704695 }
705696
706- public SourceClass getSuperClass () throws ClassNotFoundException , IOException {
707- if (source instanceof Class <?>) {
708- return asSourceClass (((Class <?>) source ).getSuperclass ());
697+ public SourceClass getSuperClass () throws IOException , ClassNotFoundException {
698+ if (this . source instanceof Class <?>) {
699+ return asSourceClass (((Class <?>) this . source ).getSuperclass ());
709700 }
710- return asSourceClass (((MetadataReader ) source ).getClassMetadata ().getSuperClassName ());
701+ return asSourceClass (((MetadataReader ) this . source ).getClassMetadata ().getSuperClassName ());
711702 }
712703
713- public Set <SourceClass > getAnnotations () throws ClassNotFoundException , IOException {
704+ public Set <SourceClass > getAnnotations () throws IOException , ClassNotFoundException {
714705 Set <SourceClass > annotations = new LinkedHashSet <SourceClass >();
715- for (String annotation : getMetadata () .getAnnotationTypes ()) {
706+ for (String annotation : this . metadata .getAnnotationTypes ()) {
716707 annotations .add (getRelated (annotation ));
717708 }
718709 return annotations ;
719710 }
720711
721- public Collection <SourceClass > getAnnotationAttributes (String annotationType ,
722- String attribute ) throws ClassNotFoundException , IOException {
723- Map <String , Object > annotationAttributes = getMetadata ().getAnnotationAttributes (
724- annotationType , true );
725- if (annotationAttributes == null
726- || !annotationAttributes .containsKey (attribute )) {
712+ public Collection <SourceClass > getAnnotationAttributes (String annotationType , String attribute )
713+ throws IOException , ClassNotFoundException {
714+
715+ Map <String , Object > annotationAttributes = this .metadata .getAnnotationAttributes (annotationType , true );
716+ if (annotationAttributes == null || !annotationAttributes .containsKey (attribute )) {
727717 return Collections .emptySet ();
728718 }
729719 String [] classNames = (String []) annotationAttributes .get (attribute );
@@ -734,45 +724,33 @@ public Collection<SourceClass> getAnnotationAttributes(String annotationType,
734724 return rtn ;
735725 }
736726
737- private SourceClass getRelated (String className ) throws IOException ,
738- ClassNotFoundException {
739- if (source instanceof Class <?>) {
727+ private SourceClass getRelated (String className ) throws IOException , ClassNotFoundException {
728+ if (this .source instanceof Class <?>) {
740729 try {
741730 Class <?> clazz = resourceLoader .getClassLoader ().loadClass (className );
742731 return asSourceClass (clazz );
743732 }
744733 catch (ClassNotFoundException ex ) {
734+ // ignore
745735 }
746736 }
747737 return asSourceClass (className );
748738 }
749739
750- public AnnotationMetadata getMetadata () {
751- return this .metadata ;
752- }
753-
754740 @ Override
755- public int hashCode () {
756- return toString ().hashCode ();
741+ public boolean equals (Object other ) {
742+ return (this == other || (other instanceof SourceClass &&
743+ this .metadata .getClassName ().equals (((SourceClass ) other ).metadata .getClassName ())));
757744 }
758745
759746 @ Override
760- public boolean equals (Object obj ) {
761- if (obj == this ) {
762- return true ;
763- }
764- if (obj == null ) {
765- return false ;
766- }
767- if (obj instanceof SourceClass ) {
768- return toString ().equals (obj .toString ());
769- }
770- return false ;
747+ public int hashCode () {
748+ return this .metadata .getClassName ().hashCode ();
771749 }
772750
773751 @ Override
774752 public String toString () {
775- return getMetadata () .getClassName ();
753+ return this . metadata .getClassName ();
776754 }
777755 }
778756
0 commit comments