-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of checkcast with classes
- Loading branch information
1 parent
c84bd29
commit ff0e682
Showing
7 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package samples.javacore.cast.trivial; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.HashMap; | ||
|
||
public class TrivialCast { | ||
public static void main(String[] args) { | ||
Object o = new HashMap<Integer, Integer>(); | ||
var abstractMap = (AbstractMap<Integer, Integer>) o; | ||
|
||
int result = 1337; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::method_area::method_area::with_method_area; | ||
|
||
pub(crate) struct InstanceChecker {} | ||
|
||
impl InstanceChecker { | ||
pub(crate) fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl InstanceChecker { | ||
pub fn checkcast( | ||
&self, | ||
class_cast_from: &str, | ||
class_cast_to: &str, | ||
) -> crate::error::Result<bool> { | ||
if let Some(base_of) = Self::is_base_of(class_cast_to, class_cast_from) { | ||
return Ok(base_of); | ||
} | ||
|
||
Ok(false) | ||
} | ||
|
||
fn is_base_of(base: &str, child: &str) -> Option<bool> { | ||
if base == child { | ||
return Some(true); | ||
} | ||
|
||
let class = with_method_area(|method_area| method_area.get(child)).ok()?; | ||
let class_name = class.parent().clone()?; | ||
|
||
Self::is_base_of(base, &class_name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod attributes_helper; | ||
mod cpool_helper; | ||
pub(crate) mod field; | ||
pub(crate) mod instance_checker; | ||
pub(crate) mod java_class; | ||
pub(crate) mod java_method; | ||
pub(crate) mod method_area; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters