-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt at making the code more understandable and a few other things.
- Added examples on what visitor visits - Moved away from the line, columnStart and columnEnd variables for each visitor, instead we use the Value class. - Added a few more values we parse.
- Loading branch information
Showing
9 changed files
with
2,260 additions
and
1,719 deletions.
There are no files selected for viewing
1,719 changes: 0 additions & 1,719 deletions
1,719
.../java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java
This file was deleted.
Oops, something went wrong.
122 changes: 122 additions & 0 deletions
122
...he/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/ArrayParser.java
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,122 @@ | ||
package the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors; | ||
|
||
import com.github.javaparser.Range; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.body.CallableDeclaration; | ||
import com.github.javaparser.ast.expr.*; | ||
import the.bytecode.club.bytecodeviewer.resources.classcontainer.ClassFileContainer; | ||
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.Value; | ||
|
||
import static the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.*; | ||
|
||
/** | ||
* Created by Bl3nd. | ||
* Date: 10/1/2024 | ||
*/ | ||
class ArrayParser | ||
{ | ||
|
||
static void parseAccess(CompilationUnit compilationUnit, ArrayAccessExpr expr, ClassFileContainer container) | ||
{ | ||
Expression valueExp = expr.getName(); | ||
if (valueExp instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) valueExp; | ||
CallableDeclaration<?> method = findMethodForExpression(expr, compilationUnit); | ||
if (method == null) | ||
{ | ||
method = findConstructorForExpression(expr, compilationUnit); | ||
} | ||
|
||
if (method == null) | ||
{ | ||
System.err.println("ArrayAccess1 - Method not found"); | ||
return; | ||
} | ||
|
||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value nameValue = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, nameValue); | ||
} | ||
|
||
Expression indexExp = expr.getIndex(); | ||
if (indexExp instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) indexExp; | ||
CallableDeclaration<?> method = findMethodForExpression(expr, compilationUnit); | ||
if (method == null) | ||
method = findConstructorForExpression(expr, compilationUnit); | ||
|
||
if (method == null) | ||
{ | ||
System.err.println("ArrayAccess2 - Method not found"); | ||
return; | ||
} | ||
|
||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value indexValue = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, indexValue); | ||
} | ||
} | ||
|
||
static void parseCreation(CompilationUnit compilationUnit, ArrayCreationExpr expr, | ||
ClassFileContainer container) | ||
{ | ||
expr.getLevels().forEach(level -> { | ||
Expression dimensionExpr = level.getDimension().orElse(null); | ||
if (dimensionExpr instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) dimensionExpr; | ||
CallableDeclaration<?> method = findMethodForExpression(expr, compilationUnit); | ||
if (method == null) | ||
method = findConstructorForExpression(expr, compilationUnit); | ||
|
||
if (method == null) | ||
{ | ||
System.err.println("ArrayCreation - Method not found"); | ||
return; | ||
} | ||
|
||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value dimensionValue = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, dimensionValue); | ||
} | ||
}); | ||
} | ||
|
||
static void parseInitializer(CompilationUnit compilationUnit, ArrayInitializerExpr expr, | ||
ClassFileContainer container) | ||
{ | ||
expr.getValues().forEach(value -> { | ||
if (value instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) value; | ||
CallableDeclaration<?> method = findMethodForExpression(expr, compilationUnit); | ||
if (method == null) | ||
method = findConstructorForExpression(expr, compilationUnit); | ||
|
||
if (method == null) | ||
{ | ||
System.err.println("ArrayInitializer - Method not found"); | ||
return; | ||
} | ||
|
||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value valueValue = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, valueValue); | ||
} | ||
}); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...e/bytecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/AssignParser.java
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,100 @@ | ||
package the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors; | ||
|
||
import com.github.javaparser.Range; | ||
import com.github.javaparser.ast.body.CallableDeclaration; | ||
import com.github.javaparser.ast.expr.AssignExpr; | ||
import com.github.javaparser.ast.expr.NameExpr; | ||
import com.github.javaparser.ast.expr.SimpleName; | ||
import com.github.javaparser.resolution.UnsolvedSymbolException; | ||
import the.bytecode.club.bytecodeviewer.resources.classcontainer.ClassFileContainer; | ||
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.Value; | ||
|
||
import static the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.printException; | ||
import static the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.putResolvedValues; | ||
|
||
/** | ||
* Created by Bl3nd. | ||
* Date: 9/29/2024 | ||
*/ | ||
class AssignParser | ||
{ | ||
|
||
static void parse(ClassFileContainer container, AssignExpr expr, CallableDeclaration<?> method) | ||
{ | ||
if (expr.getValue() instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) expr.getValue(); | ||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value value = new Value(nameExpr.getName(), range); | ||
try | ||
{ | ||
putResolvedValues(container, "reference", method, nameExpr, value); | ||
} | ||
catch (UnsolvedSymbolException e) | ||
{ | ||
printException(expr, e); | ||
} | ||
} | ||
|
||
if (expr.getTarget() instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) expr.getTarget(); | ||
try | ||
{ | ||
SimpleName simpleName = nameExpr.getName(); | ||
Range range = simpleName.getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value target = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, target); | ||
} | ||
catch (UnsolvedSymbolException e) | ||
{ | ||
printException(expr, e); | ||
} | ||
} | ||
} | ||
|
||
static void parseStatic(ClassFileContainer container, AssignExpr expr) | ||
{ | ||
if (expr.getValue() instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) expr.getValue(); | ||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value value = new Value(nameExpr.getName(), range); | ||
try | ||
{ | ||
putResolvedValues(container, "reference", nameExpr, value); | ||
} | ||
catch (UnsolvedSymbolException e) | ||
{ | ||
printException(expr, e); | ||
} | ||
} | ||
|
||
if (expr.getTarget() instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) expr.getTarget(); | ||
try | ||
{ | ||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value target = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", nameExpr, target); | ||
} | ||
catch (UnsolvedSymbolException e) | ||
{ | ||
printException(expr, e); | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ecode/club/bytecodeviewer/resources/classcontainer/parser/visitors/ConditionalParser.java
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,54 @@ | ||
package the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors; | ||
|
||
import com.github.javaparser.Range; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.body.CallableDeclaration; | ||
import com.github.javaparser.ast.expr.ConditionalExpr; | ||
import com.github.javaparser.ast.expr.Expression; | ||
import com.github.javaparser.ast.expr.NameExpr; | ||
import the.bytecode.club.bytecodeviewer.resources.classcontainer.ClassFileContainer; | ||
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.Value; | ||
|
||
import static the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.ParserUtil.*; | ||
|
||
/** | ||
* Created by Bl3nd. | ||
* Date: 10/1/2024 | ||
*/ | ||
class ConditionalParser | ||
{ | ||
|
||
static void parse(CompilationUnit compilationUnit, ConditionalExpr expr, ClassFileContainer container) | ||
{ | ||
CallableDeclaration<?> method = findMethodForExpression(expr, compilationUnit); | ||
if (method == null) | ||
method = findConstructorForExpression(expr, compilationUnit); | ||
|
||
if (method == null) | ||
return; | ||
|
||
Expression elseExpr = expr.getElseExpr(); | ||
if (elseExpr instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) elseExpr; | ||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value elseValue = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, elseValue); | ||
} | ||
|
||
Expression thenExpr = expr.getThenExpr(); | ||
if (thenExpr instanceof NameExpr) | ||
{ | ||
NameExpr nameExpr = (NameExpr) thenExpr; | ||
Range range = nameExpr.getName().getRange().orElse(null); | ||
if (range == null) | ||
return; | ||
|
||
Value thenValue = new Value(nameExpr.getName(), range); | ||
putResolvedValues(container, "reference", method, nameExpr, thenValue); | ||
} | ||
} | ||
} |
Oops, something went wrong.