Browse Source

Polishing

pull/1578/head
Juergen Hoeller 8 years ago
parent
commit
7e8c8f0b76
  1. 19
      spring-core/src/main/java/org/springframework/core/type/ClassMetadata.java
  2. 7
      spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java
  3. 5
      spring-core/src/main/java/org/springframework/core/type/classreading/ClassMetadataReadingVisitor.java

19
spring-core/src/main/java/org/springframework/core/type/ClassMetadata.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -63,19 +63,18 @@ public interface ClassMetadata {
boolean isFinal(); boolean isFinal();
/** /**
* Determine whether the underlying class is independent, * Determine whether the underlying class is independent, i.e. whether
* i.e. whether it is a top-level class or a nested class * it is a top-level class or a nested class (static inner class) that
* (static inner class) that can be constructed independent * can be constructed independently from an enclosing class.
* from an enclosing class.
*/ */
boolean isIndependent(); boolean isIndependent();
/** /**
* Return whether the underlying class has an enclosing class * Return whether the underlying class is declared within an enclosing
* (i.e. the underlying class is an inner/nested class or * class (i.e. the underlying class is an inner/nested class or a
* a local class within a method). * local class within a method).
* <p>If this method returns {@code false}, then the * <p>If this method returns {@code false}, then the underlying
* underlying class is a top-level class. * class is a top-level class.
*/ */
boolean hasEnclosingClass(); boolean hasEnclosingClass();

7
spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.util.LinkedHashSet;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* {@link ClassMetadata} implementation that uses standard reflection * {@link ClassMetadata} implementation that uses standard reflection
@ -124,11 +125,11 @@ public class StandardClassMetadata implements ClassMetadata {
@Override @Override
public String[] getMemberClassNames() { public String[] getMemberClassNames() {
LinkedHashSet<String> memberClassNames = new LinkedHashSet<>(); LinkedHashSet<String> memberClassNames = new LinkedHashSet<>(4);
for (Class<?> nestedClass : this.introspectedClass.getDeclaredClasses()) { for (Class<?> nestedClass : this.introspectedClass.getDeclaredClasses()) {
memberClassNames.add(nestedClass.getName()); memberClassNames.add(nestedClass.getName());
} }
return memberClassNames.toArray(new String[memberClassNames.size()]); return StringUtils.toStringArray(memberClassNames);
} }
} }

5
spring-core/src/main/java/org/springframework/core/type/classreading/ClassMetadataReadingVisitor.java

@ -29,6 +29,7 @@ import org.springframework.asm.SpringAsmInfo;
import org.springframework.core.type.ClassMetadata; import org.springframework.core.type.ClassMetadata;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/** /**
* ASM class visitor which looks only for the class name and implemented types, * ASM class visitor which looks only for the class name and implemented types,
@ -64,7 +65,7 @@ class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata
private String[] interfaces = new String[0]; private String[] interfaces = new String[0];
private Set<String> memberClassNames = new LinkedHashSet<>(); private Set<String> memberClassNames = new LinkedHashSet<>(4);
public ClassMetadataReadingVisitor() { public ClassMetadataReadingVisitor() {
@ -208,7 +209,7 @@ class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata
@Override @Override
public String[] getMemberClassNames() { public String[] getMemberClassNames() {
return this.memberClassNames.toArray(new String[this.memberClassNames.size()]); return StringUtils.toStringArray(this.memberClassNames);
} }

Loading…
Cancel
Save