Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
libcore
Commits
5af4cc5a
Commit
5af4cc5a
authored
11 years ago
by
Narayan Kamath
Committed by
Gerrit Code Review
11 years ago
Browse files
Options
Download
Plain Diff
Merge "Fix getGenericSuperclass."
parents
48132b98
f9f628bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
3 deletions
+66
-3
libdvm/src/main/java/java/lang/Class.java
libdvm/src/main/java/java/lang/Class.java
+13
-3
luni/src/test/java/libcore/java/lang/ClassTest.java
luni/src/test/java/libcore/java/lang/ClassTest.java
+53
-0
No files found.
libdvm/src/main/java/java/lang/Class.java
View file @
5af4cc5a
...
...
@@ -798,9 +798,19 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* class}.
*/
public
Type
getGenericSuperclass
()
{
GenericSignatureParser
parser
=
new
GenericSignatureParser
(
getClassLoader
());
parser
.
parseForClass
(
this
,
getSignatureAttribute
());
return
Types
.
getType
(
parser
.
superclassType
);
Type
superClass
=
getSuperclass
();
// This method is specified to return null for all cases where getSuperclass
// returns null, i.e, for primitives, interfaces, void and java.lang.Object.
if
(
superClass
==
null
)
{
return
null
;
}
String
signature
=
getSignatureAttribute
();
if
(
signature
!=
null
)
{
GenericSignatureParser
parser
=
new
GenericSignatureParser
(
getClassLoader
());
parser
.
parseForClass
(
this
,
getSignatureAttribute
());
superClass
=
parser
.
superclassType
;
}
return
Types
.
getType
(
superClass
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
luni/src/test/java/libcore/java/lang/ClassTest.java
0 → 100644
View file @
5af4cc5a
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
libcore.java.lang
;
import
junit.framework.TestCase
;
public
class
ClassTest
extends
TestCase
{
interface
Foo
{
public
void
foo
();
}
interface
ParameterizedFoo
<
T
>
{
public
void
foo
(
T
param
);
}
interface
ParameterizedBar
<
T
>
extends
ParameterizedFoo
<
T
>
{
public
void
bar
(
T
param
);
}
interface
ParameterizedBaz
extends
ParameterizedFoo
<
String
>
{
}
public
void
test_getGenericSuperclass_nullReturnCases
()
{
// Should always return null for interfaces.
assertNull
(
Foo
.
class
.
getGenericSuperclass
());
assertNull
(
ParameterizedFoo
.
class
.
getGenericSuperclass
());
assertNull
(
ParameterizedBar
.
class
.
getGenericSuperclass
());
assertNull
(
ParameterizedBaz
.
class
.
getGenericSuperclass
());
assertNull
(
Object
.
class
.
getGenericSuperclass
());
assertNull
(
void
.
class
.
getGenericSuperclass
());
assertNull
(
int
.
class
.
getGenericSuperclass
());
}
public
void
test_getGenericSuperclass_returnsObjectForArrays
()
{
assertSame
(
Object
.
class
,
(
new
Integer
[
0
]).
getClass
().
getGenericSuperclass
());
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment