Compare commits

..

No commits in common. "035ff99edf6960a81fc0fa9b70fcd23dc383d326" and "111eecd929bdf77fa540b2259a5dbcc87d4127b0" have entirely different histories.

18 changed files with 58 additions and 159 deletions

View file

@ -1,11 +1,10 @@
package be.jeffcheasey88.peeratcode.parser.java;
import java.util.Map;
import java.util.function.Function;
import be.jeffcheasey88.peeratcode.parser.Token;
public class Annotation extends JavaElement{
public class Annotation{
public static interface Annotable{
@ -29,12 +28,4 @@ public class Annotation extends JavaElement{
return name;
}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
for(Value value : this.values.values()){
if(finder.apply(value)) return (E)value;
}
return null;
}
}

View file

@ -57,16 +57,5 @@ public class Class extends JavaElement implements Annotable, ClassContainer, Fun
this.elements.add(clazz);
}
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) return (E) annotation;
}
for(JavaElement element : this.elements){
if(finder.apply(element)) return (E) element;
}
return null;
}
}

View file

@ -65,18 +65,4 @@ public class Function extends JavaElement implements Annotable, VariableContaine
this.elements.add(operation);
}
@Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder) {
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) return (E) annotation;
}
for(Variable param : this.parameters){
if(finder.apply(param)) return (E) param;
}
for(JavaElement content : this.elements){
if(finder.apply(content)) return (E) content;
}
return null;
}
}

View file

@ -1,14 +1,9 @@
package be.jeffcheasey88.peeratcode.parser.java;
import be.jeffcheasey88.peeratcode.parser.Bag;
import java.util.function.Function;
public abstract class JavaElement{
Bag bag; //to remove
public abstract <E extends JavaElement> E find(Function<JavaElement, Boolean> finder);
public class JavaElement {
Bag bag;
}

View file

@ -2,7 +2,6 @@ package be.jeffcheasey88.peeratcode.parser.java;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import be.jeffcheasey88.peeratcode.parser.Bag;
import be.jeffcheasey88.peeratcode.parser.Token;
@ -42,13 +41,4 @@ public class JavaFile extends JavaElement implements ClassContainer{
if(mainClazz == null) this.mainClazz = clazz;
else subClazz.add(clazz);
}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
if(finder.apply(mainClazz)) return (E) mainClazz;
for(Class clazz : subClazz){
if(finder.apply(clazz)) return (E) clazz;
}
return null;
}
}

View file

@ -23,6 +23,7 @@ import be.jeffcheasey88.peeratcode.parser.TokenValidator;
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
import be.jeffcheasey88.peeratcode.parser.java.Function.FunctionContainer;
import be.jeffcheasey88.peeratcode.parser.java.Value.BiValue;
import be.jeffcheasey88.peeratcode.parser.java.Variable.VariableContainer;
import be.jeffcheasey88.peeratcode.parser.state.BuilderStateTree;
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
@ -70,25 +71,6 @@ public class JavaParser extends Parser<JavaElement> {
i = j-1;
}else if(Character.isWhitespace(c)) continue;
else{
if(c == '"'){
String value = "\"";
int j = i+1;
for(; j < line.length(); j++){
c = line.charAt(j);
if(c == '"'){
value+=c;
j++;
break;
}else if(c == '\\'){
value+=c+line.charAt(++j);
}else{
value+=c;
}
}
token = new Token(lineNumber, i+1, value, TokenType.STRING);
i = j-1;
System.out.println(token);
}else{
if(c == '/' && (i < line.length()-1 && line.charAt(i+1) == '/')) break;
if(c == '/' && (i < line.length()-1 && line.charAt(i+1) == '*')){
longCommentary = true;
@ -96,7 +78,6 @@ public class JavaParser extends Parser<JavaElement> {
}
token = new Token(lineNumber, i+1, ""+c, TokenType.DELIMITER);
}
}
getTokens().add(token);
}
}
@ -181,11 +162,6 @@ public class JavaParser extends Parser<JavaElement> {
type_generic_named_super.then(type_generic_end);
type_generic_named_super.then(type_generic_split);
StateTree<JavaElement> type_array_begin = type_.then((validator) -> validator.validate((token) -> token.getValue().equals("[")));
StateTree<JavaElement> type_array_end = type_array_begin.then((validator) -> validator.validate((token) -> token.getValue().equals("]")));
type_array_end.then(type_array_begin);
type_array_end.end();
type_.end();
type_generic_end.end();
@ -234,27 +210,6 @@ public class JavaParser extends Parser<JavaElement> {
value_list_element.then((validator) -> validator.validate((token) -> token.getValue().equals(",")))
.then(value_list_element);
value.then((validator) -> {
if(validator.validate((token) -> token.getValue().equals("'"))){
validator.validate((token) -> token.getValue().equals("\\"));
return
validator.validate((token) -> token.getValue().equals("'"))
||
(validator.validate((token) -> !token.getValue().equals("'"))
&& validator.validate((token) -> token.getValue().equals("'")));
}
return false;
}).end();
value.then((validator) -> validator.validate((token) -> {
System.out.println("string? "+token);
return token.getType().equals(TokenType.STRING);
})).end((parent,bag) -> {
bag.set(new Value(bag.<Token>get()));
return null;
});
StateTree<JavaElement> value_instance = value.then((validator) -> validator.validate((token) -> token.getValue().equals("new")));
StateTree<JavaElement> value_name = new StateTree<JavaElement>();
value.then(value_name);
@ -309,7 +264,6 @@ public class JavaParser extends Parser<JavaElement> {
if(count == null) count = 0;
global.set("arg"+count, local);
global.set("args", (count+1));
System.out.println("ah "+local);
}));
value_arg.then((validator) -> validator.validate((token) -> token.getValue().equals(",")))
.then(value_arg);
@ -344,10 +298,7 @@ public class JavaParser extends Parser<JavaElement> {
value_container.then((validator) -> validator.validate((token) -> token.getValue().equals("-"))).then(value_container);
value_container.then((validator) -> validator.validate((token) -> token.getValue().equals("+"))).then(value_container);
value_container.then((validator) -> validator.validate((token) -> token.getValue().equals("~"))).then(value_container);
StateTree<JavaElement> value_inside = value_container.then(new RedirectStateTree<>(value, (global, local) -> {
System.out.println("captured "+local);
global.set("left", local.get());
}));
StateTree<JavaElement> value_inside = value_container.then(new RedirectStateTree<>(value, (global, local) -> global.set("left", local.get())));
value_inside.then((validator) -> validator.validate((token) -> token.getValue().equals("[")))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals("]")))
@ -405,6 +356,41 @@ public class JavaParser extends Parser<JavaElement> {
value_instanceof.end(value_builder);
value_instanceof.then(value_left);
value.then((validator) -> {
if(validator.validate((token) -> token.getValue().equals("'"))){
validator.validate((token) -> token.getValue().equals("\\"));
return
validator.validate((token) -> token.getValue().equals("'"))
||
(validator.validate((token) -> !token.getValue().equals("'"))
&& validator.validate((token) -> token.getValue().equals("'")));
}
return false;
}).end();
value.then((validator) -> {
if(validator.validate((token) -> token.getValue().equals("\""))){
while(validator.validate(
(token) -> !token.getValue().equals("\""),
(bag, token) -> {
Token current = bag.get();
if(current == null) current = token;
else current = current.concat(token);
bag.set(current);
}));
return validator.validate((token) -> token.getValue().equals("\""), (bag, token) -> {
Token current = bag.get();
if(current == null) current = token;
else current = current.concat(token);
bag.set(current);
});
}
return false;
}).end((parent,bag) -> {
bag.set(new Value(bag.<Token>get()));
return null;
});
braces_container.then(clazz_container);
StateTree<JavaElement> braces_array = braces_container.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)));
braces_array.then((validator) -> validator.validate((token) -> token.getValue().equals(",")))
@ -1022,7 +1008,7 @@ public class JavaParser extends Parser<JavaElement> {
}
public static void main(String[] args) throws Exception{
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\dev\\peerat\\backend\\bonus\\extract\\RouteExtracter.java");
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\dev\\peerat\\backend\\Configuration.java");
BufferedReader reader = new BufferedReader(new FileReader(file));

View file

@ -1,7 +1,5 @@
package be.jeffcheasey88.peeratcode.parser.java;
import java.util.function.Function;
public class Operation extends JavaElement{
public static interface OperationContainer{
@ -12,9 +10,4 @@ public static interface OperationContainer{
public Operation(){}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
return null;
}
}

View file

@ -1,7 +1,5 @@
package be.jeffcheasey88.peeratcode.parser.java;
import java.util.function.Function;
import be.jeffcheasey88.peeratcode.parser.Token;
public class Value extends JavaElement{
@ -32,11 +30,6 @@ public class Value extends JavaElement{
return "Value[token="+token+", content="+content+"]";
}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
return content != null ? finder.apply(content) ? (E) content : null : null;
}
public static class BiValue extends Value{
private Value left;
@ -65,11 +58,6 @@ public class Value extends JavaElement{
public String toString(){
return left+" "+action+" "+right;
}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
return finder.apply(left) ? (E) left : finder.apply(right) ? (E) right : null;
}
}
public static class TriValue extends Value{
@ -92,10 +80,6 @@ public class Value extends JavaElement{
return fail;
}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
return finder.apply(check) ? (E) check : finder.apply(success) ? (E) success : finder.apply(fail) ? (E) fail : null;
}
}
}

View file

@ -2,7 +2,6 @@ package be.jeffcheasey88.peeratcode.parser.java;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import be.jeffcheasey88.peeratcode.parser.Token;
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
@ -49,12 +48,4 @@ public class Variable extends JavaElement implements Annotable{
public void addAnnotation(Annotation annotation){
this.annotations.add(annotation);
}
@Override
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
for(Annotation annotation : this.annotations){
if(finder.apply(annotation)) return (E) annotation;
}
return value != null ? finder.apply(value) ? (E)value : null : null;
}
}

View file

@ -60,7 +60,7 @@ public class ForCase {
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
parser.parse(value, null);
parser.parse(value, new JavaElement());
assertEquals(TokenValidator.TOKENS, TokenValidator.MAX_VALIDATE);
}

View file

@ -90,7 +90,7 @@ public class AnnotationTests {
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);

View file

@ -80,7 +80,7 @@ public class ClassTests{
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);

View file

@ -136,7 +136,7 @@ public class FunctionTests {
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);

View file

@ -113,7 +113,7 @@ public class ModifierTests{
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);

View file

@ -340,7 +340,7 @@ public class OperationTests {
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);

View file

@ -62,11 +62,6 @@ public class TypeTests{
type_generic_named_super.then(type_generic_end);
type_generic_named_super.then(type_generic_split);
StateTree<JavaElement> type_array_begin = type_.then((validator) -> validator.validate((token) -> token.getValue().equals("[")));
StateTree<JavaElement> type_array_end = type_array_begin.then((validator) -> validator.validate((token) -> token.getValue().equals("]")));
type_array_end.then(type_array_begin);
type_array_end.end();
type_.end();
type_generic_end.end();
}
@ -92,7 +87,7 @@ public class TypeTests{
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);

View file

@ -254,7 +254,7 @@ public class ValueTests {
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = null;
JavaElement result = new JavaElement();
parser.parse(value, result);
@ -265,6 +265,6 @@ public class ValueTests {
@Test
void doubleInDouble() throws Exception{
JavaElement result = testCase("(jeffcheasey88 == goefra) || (yuzzu == yugs) || (test == \"Content-Disposition: form-data; name=\\\"?\\\"\")");
JavaElement result = testCase("(jeffcheasey88 == goefra) || (yuzzu == yugs)");
}
}

View file

@ -50,7 +50,6 @@ public class VariableTests{
bag.set("last", token);
map.put(token, null);
}));
variable_name.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end(variable_builder);
StateTree<JavaElement> variable_split = variable_name.then((validator) -> validator.validate((token) -> token.getValue().equals(",")));
@ -79,7 +78,7 @@ public class VariableTests{
TokenValidator.TOKENS = 0;
TokenValidator.MAX_VALIDATE = 0;
JavaElement result = new Class(new Token(0, 0, "Test", TokenType.NAME));
JavaElement result = new JavaElement();
parser.parse(value, result);
@ -90,6 +89,6 @@ public class VariableTests{
@Test
void hashMap() throws Exception{
JavaElement result = testCase("private static final Map<Map<List<String[]>>> map = new HashMap<>();");
JavaElement result = testCase("private static final Map<Map<List<String>>> map = new HashMap<>();");
}
}