ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amashen...@apache.org
Subject [ignite-3] branch gg-13618-asm updated: Minor.
Date Tue, 12 Jan 2021 13:05:39 GMT
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch gg-13618-asm
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/gg-13618-asm by this push:
     new 1acbbb6  Minor.
1acbbb6 is described below

commit 1acbbb6f88ddb25692b41f6bbc56880bbfb39929
Author: Andrew Mashenkov <andrey.mashenkov@gmail.com>
AuthorDate: Tue Jan 12 16:05:11 2021 +0300

    Minor.
---
 modules/commons/pom.xml                            | 15 +++++++++
 .../presto/bytecode/DumpBytecodeVisitor.java       |  8 +++--
 .../facebook/presto/bytecode/MethodDefinition.java |  2 +-
 .../expression/BytecodeExpressionAssertions.java   | 37 ++++++++++++++++++++--
 .../expression/TestArrayBytecodeExpressions.java   |  6 ++--
 5 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml
index 21fba2c..967420c 100644
--- a/modules/commons/pom.xml
+++ b/modules/commons/pom.xml
@@ -96,4 +96,19 @@
             <version>${javax.annotation.api.version}</version>
         </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>src/main/java/com/facebook/presto/bytecode/ClassInfo.java</exclude>
+                        <exclude>src/main/java/com/facebook/presto/bytecode/ClassInfoLoader.java</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>
diff --git a/modules/commons/src/main/java/com/facebook/presto/bytecode/DumpBytecodeVisitor.java
b/modules/commons/src/main/java/com/facebook/presto/bytecode/DumpBytecodeVisitor.java
index 7e07883..ab0417b 100644
--- a/modules/commons/src/main/java/com/facebook/presto/bytecode/DumpBytecodeVisitor.java
+++ b/modules/commons/src/main/java/com/facebook/presto/bytecode/DumpBytecodeVisitor.java
@@ -601,13 +601,17 @@ public class DumpBytecodeVisitor
 
         public void print()
         {
-            printLine(parts.stream().map(Object::toString).collect(Collectors.joining(separator)));
+            printLine(parts.stream().map(this::toCharSequence).collect(Collectors.joining(separator)));
+        }
+
+        private CharSequence toCharSequence(Object p) {
+            return p instanceof CharSequence ? (CharSequence)p : p.toString();
         }
 
         @Override
         public String toString()
         {
-            return parts.stream().map(Object::toString).collect(Collectors.joining(separator));
+            return parts.stream().map(this::toCharSequence).collect(Collectors.joining(separator));
         }
     }
 }
diff --git a/modules/commons/src/main/java/com/facebook/presto/bytecode/MethodDefinition.java
b/modules/commons/src/main/java/com/facebook/presto/bytecode/MethodDefinition.java
index c5eae33..0297d9b 100644
--- a/modules/commons/src/main/java/com/facebook/presto/bytecode/MethodDefinition.java
+++ b/modules/commons/src/main/java/com/facebook/presto/bytecode/MethodDefinition.java
@@ -228,7 +228,7 @@ public class MethodDefinition {
 
     public String toSourceString() {
         StringBuilder sb = new StringBuilder();
-        sb.append(access.stream().map(Access::toString).collect(Collectors.joining(", ")))
+        sb.append(access.stream().map(Access::toString).collect(Collectors.joining(" ")))
             .append(' ');
         sb.append(returnType.getJavaClassName()).append(' ');
         sb.append(name).append('(');
diff --git a/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/BytecodeExpressionAssertions.java
b/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/BytecodeExpressionAssertions.java
index 4b45edc..8aa0b03 100644
--- a/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/BytecodeExpressionAssertions.java
+++ b/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/BytecodeExpressionAssertions.java
@@ -18,6 +18,8 @@ import com.facebook.presto.bytecode.ClassDefinition;
 import com.facebook.presto.bytecode.MethodDefinition;
 import com.facebook.presto.bytecode.ParameterizedType;
 import com.facebook.presto.bytecode.Scope;
+import java.lang.reflect.Array;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Function;
@@ -31,6 +33,7 @@ import static com.facebook.presto.bytecode.BytecodeUtils.makeClassName;
 import static com.facebook.presto.bytecode.ClassGenerator.classGenerator;
 import static com.facebook.presto.bytecode.ParameterizedType.type;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
 
 public final class BytecodeExpressionAssertions {
     private BytecodeExpressionAssertions() {
@@ -76,7 +79,7 @@ public final class BytecodeExpressionAssertions {
     public static void assertBytecodeNode(BytecodeNode node, ParameterizedType returnType,
Object expected,
         Optional<ClassLoader> parentClassLoader)
         throws Exception {
-        assertEquals(execute(context -> node, returnType, parentClassLoader), expected);
+        assertValueEquals(execute(context -> node, returnType, parentClassLoader), expected);
     }
 
     public static void assertBytecodeNode(Function<Scope, BytecodeNode> nodeGenerator,
ParameterizedType returnType,
@@ -88,7 +91,7 @@ public final class BytecodeExpressionAssertions {
     public static void assertBytecodeNode(Function<Scope, BytecodeNode> nodeGenerator,
ParameterizedType returnType,
         Object expected, Optional<ClassLoader> parentClassLoader)
         throws Exception {
-        assertEquals(execute(nodeGenerator, returnType, parentClassLoader), expected);
+        assertValueEquals(execute(nodeGenerator, returnType, parentClassLoader), expected);
     }
 
     public static Object execute(Function<Scope, BytecodeNode> nodeGenerator, ParameterizedType
returnType,
@@ -115,4 +118,34 @@ public final class BytecodeExpressionAssertions {
             .getMethod("test")
             .invoke(null);
     }
+
+    /**
+     * returns not equal reason or null if equal
+     **/
+    private static void assertValueEquals(Object actual, Object expected) {
+        if (expected == null || !expected.getClass().isArray()) {
+            assertEquals(actual, expected);
+
+            return;
+        }
+
+        if (null == expected)
+            fail("expected a null array, but not null found");
+
+        if (null == actual) {
+            fail("expected not null array, but null found");
+        }
+
+        int expectedLength = Array.getLength(expected);
+        if (expectedLength != Array.getLength(actual)) {
+            fail("array lengths are not the same");
+        }
+        for (int i = 0; i < expectedLength; i++) {
+            Object _actual = Array.get(actual, i);
+            Object _expected = Array.get(expected, i);
+
+            if (!Objects.equals(_expected, _actual))
+                fail("(values at index " + i + " are not the same)");
+        }
+    }
 }
diff --git a/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/TestArrayBytecodeExpressions.java
b/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/TestArrayBytecodeExpressions.java
index 93631f7..d469dde 100644
--- a/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/TestArrayBytecodeExpressions.java
+++ b/modules/commons/src/test/java/com/facebook/presto/bytecode/expression/TestArrayBytecodeExpressions.java
@@ -44,12 +44,12 @@ import static com.facebook.presto.bytecode.expression.BytecodeExpressions.invoke
 import static com.facebook.presto.bytecode.expression.BytecodeExpressions.newArray;
 
 public class TestArrayBytecodeExpressions {
-    private final DynamicClassLoader classLoader = new DynamicClassLoader(TestArrayBytecodeExpressions.class.getClassLoader());
+    private static final DynamicClassLoader classLoader = new DynamicClassLoader(TestArrayBytecodeExpressions.class.getClassLoader());
     private static final ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC,
FINAL), "DummyClass", type(Object.class));
-    private final Map<Class<?>, MethodDefinition> typeMethodMap = new HashMap<>();
+    private static final Map<Class<?>, MethodDefinition> typeMethodMap = new
HashMap<>();
 
     @BeforeAll
-    public void setUp() {
+    public static void setUp() {
         for (Class<?> aClass : List.of(boolean[].class, char[].class, float[].class,
double[].class, byte[].class, short[].class, int[].class, long[].class, String[].class)) {
             MethodDefinition methodDefinition = defineSetAndGetMethod(aClass);
             typeMethodMap.put(aClass, methodDefinition);


Mime
View raw message