-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
671-add-support-for-exceptions-caught-be-a-method-to-java-plugin (#768)
* #671 added visitor to scan caught exceptions * #671 label thrown and caught types with "Throwable"
- Loading branch information
1 parent
0946ef6
commit 38d1f65
Showing
12 changed files
with
246 additions
and
49 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
24 changes: 24 additions & 0 deletions
24
...java/src/main/java/com/buschmais/jqassistant/plugin/java/api/model/CatchesDescriptor.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,24 @@ | ||
package com.buschmais.jqassistant.plugin.java.api.model; | ||
|
||
import com.buschmais.jqassistant.core.store.api.model.Descriptor; | ||
import com.buschmais.xo.neo4j.api.annotation.Relation; | ||
import com.buschmais.xo.neo4j.api.annotation.Relation.Incoming; | ||
import com.buschmais.xo.neo4j.api.annotation.Relation.Outgoing; | ||
|
||
@Relation("CATCHES") | ||
public interface CatchesDescriptor extends Descriptor { | ||
|
||
@Outgoing | ||
MethodDescriptor getMethod(); | ||
|
||
@Incoming | ||
TypeDescriptor getExceptionType(); | ||
|
||
Integer getFirstLineNumber(); | ||
|
||
void setFirstLineNumber(Integer firstLineNumber); | ||
|
||
Integer getLastLineNumber(); | ||
|
||
void setLastLineNumber(Integer lastLineNumber); | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...va/src/main/java/com/buschmais/jqassistant/plugin/java/api/model/ThrowableDescriptor.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,10 @@ | ||
package com.buschmais.jqassistant.plugin.java.api.model; | ||
|
||
import com.buschmais.xo.neo4j.api.annotation.Label; | ||
|
||
/** | ||
* Represents a {@link Throwable}. | ||
*/ | ||
@Label("Throwable") | ||
public interface ThrowableDescriptor extends TypeDescriptor { | ||
} |
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
83 changes: 83 additions & 0 deletions
83
...java/com/buschmais/jqassistant/plugin/java/impl/scanner/visitor/MethodCatchesVisitor.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,83 @@ | ||
package com.buschmais.jqassistant.plugin.java.impl.scanner.visitor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.buschmais.jqassistant.plugin.java.api.model.CatchesDescriptor; | ||
import com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor; | ||
import com.buschmais.jqassistant.plugin.java.api.model.ThrowableDescriptor; | ||
import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor; | ||
import com.buschmais.jqassistant.plugin.java.api.scanner.SignatureHelper; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.MethodVisitor; | ||
|
||
/** | ||
* Visitor for methods catching exceptions. | ||
*/ | ||
class MethodCatchesVisitor extends MethodVisitor { | ||
|
||
private final MethodDescriptor methodDescriptor; | ||
|
||
private final VisitorHelper visitorHelper; | ||
|
||
private List<TryCatchBlock> tryCatchBlocks = new ArrayList<>(); | ||
|
||
private Map<Label, Integer> lineNumbers = new HashMap<>(); | ||
|
||
public MethodCatchesVisitor(MethodDescriptor methodDescriptor, VisitorHelper visitorHelper) { | ||
super(VisitorHelper.ASM_OPCODES); | ||
this.methodDescriptor = methodDescriptor; | ||
this.visitorHelper = visitorHelper; | ||
} | ||
|
||
@Override | ||
public void visitLineNumber(int line, Label start) { | ||
this.lineNumbers.put(start, line); | ||
} | ||
|
||
@Override | ||
public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { | ||
if (type != null) { | ||
tryCatchBlocks.add(new TryCatchBlock(type, start, end, handler)); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitEnd() { | ||
for (TryCatchBlock tryCatchBlock : tryCatchBlocks) { | ||
String throwableType = SignatureHelper.getObjectType(tryCatchBlock.getType()); | ||
TypeDescriptor typeDescriptor = visitorHelper.resolveType(throwableType) | ||
.getTypeDescriptor(); | ||
visitorHelper.getStore() | ||
.addDescriptorType(typeDescriptor, ThrowableDescriptor.class); | ||
CatchesDescriptor catchesDescriptor = visitorHelper.getStore() | ||
.create(methodDescriptor, CatchesDescriptor.class, typeDescriptor); | ||
catchesDescriptor.setFirstLineNumber(lineNumbers.get(tryCatchBlock.getStart())); | ||
catchesDescriptor.setLastLineNumber(lineNumbers.get(tryCatchBlock.getEnd())); | ||
} | ||
} | ||
|
||
/** | ||
* Represents a try-block | ||
*/ | ||
@Getter | ||
@RequiredArgsConstructor | ||
@ToString | ||
private static final class TryCatchBlock { | ||
|
||
private final String type; | ||
|
||
private final Label start; | ||
|
||
private final Label end; | ||
|
||
private final Label handler; | ||
} | ||
} | ||
|
Oops, something went wrong.