Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs2-19wi
project01
Commits
e087afcd
Commit
e087afcd
authored
6 years ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Updates reflection library
parent
bfdca2fe
Pipeline
#3884
canceled with stage
in 48 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/edu/caltech/cs2/helpers/Reflection.java
+26
-14
tests/edu/caltech/cs2/helpers/Reflection.java
with
26 additions
and
14 deletions
+26
-14
tests/edu/caltech/cs2/helpers/Reflection.java
View file @
e087afcd
...
...
@@ -61,7 +61,13 @@ public class Reflection {
try
{
result
=
(
T
)
m
.
invoke
(
args
[
0
],
Arrays
.
copyOfRange
(
args
,
1
,
args
.
length
));
}
catch
(
IllegalAccessException
|
InvocationTargetException
e
)
{
fail
(
e
.
getCause
());
Throwable
cause
=
e
.
getCause
();
if
(
cause
instanceof
RuntimeException
)
{
throw
(
RuntimeException
)
e
.
getCause
();
}
else
{
fail
(
cause
);
}
}
return
result
;
}
...
...
@@ -72,7 +78,13 @@ public class Reflection {
try
{
result
=
(
T
)
m
.
invoke
(
null
,
args
);
}
catch
(
IllegalAccessException
|
InvocationTargetException
e
)
{
fail
(
e
.
getCause
());
Throwable
cause
=
e
.
getCause
();
if
(
cause
instanceof
RuntimeException
)
{
throw
(
RuntimeException
)
e
.
getCause
();
}
else
{
fail
(
cause
);
}
}
return
result
;
}
...
...
@@ -98,16 +110,16 @@ public class Reflection {
}
private
static
int
stringToIntModifier
(
String
modifier
)
{
switch
(
modifier
.
toLowerCase
())
{
case
"private"
:
return
Modifier
.
PRIVATE
;
case
"public"
:
return
Modifier
.
PUBLIC
;
case
"protected"
:
return
Modifier
.
PROTECTED
;
case
"static"
:
return
Modifier
.
STATIC
;
case
"final"
:
return
Modifier
.
FINAL
;
default
:
fail
(
"Unknown modifier test."
);
}
/* Should never reach here... */
return
-
1
;
switch
(
modifier
.
toLowerCase
())
{
case
"private"
:
return
Modifier
.
PRIVATE
;
case
"public"
:
return
Modifier
.
PUBLIC
;
case
"protected"
:
return
Modifier
.
PROTECTED
;
case
"static"
:
return
Modifier
.
STATIC
;
case
"final"
:
return
Modifier
.
FINAL
;
default
:
fail
(
"Unknown modifier test."
);
}
/* Should never reach here... */
return
-
1
;
}
public
static
Predicate
<
Member
>
hasModifier
(
String
modifier
)
{
...
...
@@ -184,7 +196,7 @@ public class Reflection {
}
public
static
void
assertFieldsEqualTo
(
Class
clazz
,
Class
FieldType
,
int
x
)
{
public
static
void
assertFieldsEqualTo
(
Class
clazz
,
Class
FieldType
,
int
x
)
{
assertFieldsEqualTo
(
clazz
,
null
,
FieldType
,
x
);
}
public
static
void
assertFieldsEqualTo
(
Class
clazz
,
String
modifier
,
int
x
)
{
...
...
@@ -338,4 +350,4 @@ public class Reflection {
fail
(
"You should be overriding the "
+
method
+
"method, but your signature wasn't correct."
);
}
}
}
}
\ No newline at end of file
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
Menu
Projects
Groups
Snippets
Help