From 0111df23f5eb50b78429a0e07c3cc0399f97118f Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Wed, 10 May 2023 08:39:01 +0200 Subject: [PATCH] Fix new instance on parenthesis --- .../jeffcheasey88/peeratcode/parser/java/JavaParser.java | 7 +------ src/be/jeffcheasey88/peeratcode/parser/java/Variable.java | 6 ++++-- .../jeffcheasey88/peeratcode/parser/java/VariableTest.java | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 163e3f4..cec4554 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -30,12 +30,7 @@ public class JavaParser{ } public static void main(String[] args) throws Exception{ - String variable = "Collection collection = new ArrayList() {\r\n" - + " { add(\"1\");\r\n" - + " add(\"2\");\r\n" - + " add(\"3\");\r\n" - + " }\r\n" - + " };"; + String variable = "Future future = {new Runnable()};"; String clazz = "package test; public class Test{ "+variable+" }"; BufferedWriter writer = new BufferedWriter(new FileWriter(new File("/home/tmp.txt"))); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java index 4cadca6..20c0af2 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java @@ -93,8 +93,10 @@ public class Variable { private String generiqueTypes(String content, CleanerPool cleaner){ System.out.println("generic "+content); String unzip = cleaner.unzip(content, (value, pattern) -> { - return (pattern.equals("^GENERIC_FUNCTION")) ? null : value.replaceAll("\\s+", ""); - }); + if(pattern.equals("^GENERIC_FUNCTION")) return null; + if(pattern.equals("^GENERIC_PARENTHESIS")) return value.replace("\\s+", " "); + return value.replaceAll("\\s+", ""); + }); System.out.println("unzip "+unzip); unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}"); unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}"); diff --git a/test/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java b/test/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java index 53edfdb..8f69e92 100644 --- a/test/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java +++ b/test/be/jeffcheasey88/peeratcode/parser/java/VariableTest.java @@ -210,7 +210,7 @@ class VariableTest{ assertEquals(0, variable.getModifier()); assertEquals("java.util.function.Function", variable.getType()); assertEquals("j", variable.getName()); - assertEquals("((i)-> {return 4;})", ((Value)variable.getValue()).value()); + assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value()); }catch(Exception e){ fail(e); } @@ -263,13 +263,13 @@ class VariableTest{ assertEquals(JavaParser.getModifier("private"), variable.getModifier()); assertEquals("java.util.function.Function", variable.getType()); assertEquals("j", variable.getName()); - assertEquals("((i)-> {return 4;})", ((Value)variable.getValue()).value()); + assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value()); variable = vars.get(1); assertEquals(JavaParser.getModifier("private"), variable.getModifier()); assertEquals("java.util.function.Function", variable.getType()); assertEquals("k", variable.getName()); - assertEquals("((i)->4)", ((Value)variable.getValue()).value()); + assertEquals("((i) -> 4)", ((Value)variable.getValue()).value()); }catch(Exception e){ fail(e); }