[AST] operation search
This commit is contained in:
parent
035ff99edf
commit
e405d8e380
15 changed files with 128 additions and 10 deletions
|
@ -1,10 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java;
|
package be.jeffcheasey88.peeratcode.parser.java;
|
||||||
|
|
||||||
import java.util.function.Function;
|
public abstract class Operation extends JavaElement{
|
||||||
|
|
||||||
public class Operation extends JavaElement{
|
public static interface OperationContainer{
|
||||||
|
|
||||||
public static interface OperationContainer{
|
|
||||||
|
|
||||||
void addOperation(Operation operation);
|
void addOperation(Operation operation);
|
||||||
|
|
||||||
|
@ -12,9 +10,4 @@ public static interface OperationContainer{
|
||||||
|
|
||||||
public Operation(){}
|
public Operation(){}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
|
@ -21,4 +24,9 @@ public class AssignOperation extends Operation{
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
return finder.apply(left) ? (E)left : finder.apply(right) ? (E)right : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
|
|
||||||
public class BreakOperation extends Operation{
|
public class BreakOperation extends Operation{
|
||||||
|
|
||||||
public BreakOperation(){}
|
public BreakOperation(){}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
|
|
||||||
public class ContinueOperation extends Operation{
|
public class ContinueOperation extends Operation{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable;
|
||||||
|
|
||||||
|
@ -40,4 +42,18 @@ public class ForOperation extends OperationBag{
|
||||||
return this.updates;
|
return this.updates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
for(Variable variable : this.init_vars){
|
||||||
|
if(finder.apply(variable)) return (E)variable;
|
||||||
|
}
|
||||||
|
for(Value value : this.init_values){
|
||||||
|
if(finder.apply(value)) return (E)value;
|
||||||
|
}
|
||||||
|
if(finder.apply(condition)) return (E)condition;
|
||||||
|
for(Value value : this.updates){
|
||||||
|
if(finder.apply(value)) return (E)value;
|
||||||
|
}
|
||||||
|
return super.find(finder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
public class ForeachOperation extends OperationBag{
|
public class ForeachOperation extends OperationBag{
|
||||||
|
@ -29,4 +32,9 @@ public class ForeachOperation extends OperationBag{
|
||||||
return this.iterator;
|
return this.iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
if(finder.apply(iterator)) return (E)iterator;
|
||||||
|
return super.find(finder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
public class IfOperation extends OperationBag{
|
public class IfOperation extends OperationBag{
|
||||||
|
@ -14,4 +17,9 @@ public class IfOperation extends OperationBag{
|
||||||
return this.condition;
|
return this.condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
if(finder.apply(condition)) return (E)condition;
|
||||||
|
return super.find(finder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
|
@ -36,4 +38,14 @@ public class MethodCallOperation extends Operation{
|
||||||
return this.parameters;
|
return this.parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||||
|
if(finder.apply(start)) return (E)start;
|
||||||
|
if(finder.apply(previous)) return (E) previous;
|
||||||
|
for(Value param : this.parameters){
|
||||||
|
if(finder.apply(param)) return (E)param;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
|
@ -27,4 +28,12 @@ public class OperationBag extends Operation implements VariableContainer, Operat
|
||||||
this.elements.add(operation);
|
this.elements.add(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
for(JavaElement element : this.elements){
|
||||||
|
if(finder.apply(element)) return (E)element;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
|
@ -15,4 +18,9 @@ public class ReturnOperation extends Operation{
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||||
|
return finder.apply(value) ? (E)value : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
|
|
||||||
public class SwitchOperation extends Operation{
|
public class SwitchOperation extends Operation{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
public class SynchronizedOperation extends OperationBag{
|
public class SynchronizedOperation extends OperationBag{
|
||||||
|
@ -15,4 +18,9 @@ public class SynchronizedOperation extends OperationBag{
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
if(finder.apply(value)) return (E)value;
|
||||||
|
return super.find(finder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
import be.jeffcheasey88.peeratcode.parser.java.Operation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
|
@ -15,4 +18,9 @@ public class ThrowOperation extends Operation{
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||||
|
return finder.apply(value) ? (E)value : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable;
|
||||||
|
|
||||||
public class TryOperation extends OperationBag{
|
public class TryOperation extends OperationBag{
|
||||||
|
@ -19,4 +22,9 @@ public class TryOperation extends OperationBag{
|
||||||
return this.resource;
|
return this.resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
if(finder.apply(resource)) return (E)resource;
|
||||||
|
return super.find(finder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
package be.jeffcheasey88.peeratcode.parser.java.operation;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Value;
|
||||||
|
|
||||||
public class WhileOperation extends OperationBag{
|
public class WhileOperation extends OperationBag{
|
||||||
|
@ -14,4 +17,9 @@ public class WhileOperation extends OperationBag{
|
||||||
return this.condition;
|
return this.condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||||
|
if(finder.apply(condition)) return (E)condition;
|
||||||
|
return super.find(finder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue