diff --git a/community/codegen/src/main/java/org/neo4j/codegen/ByteCodeUtils.java b/community/codegen/src/main/java/org/neo4j/codegen/ByteCodeUtils.java index edaaab850067c..ad79509877db6 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/ByteCodeUtils.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/ByteCodeUtils.java @@ -39,7 +39,7 @@ public static String byteCodeName( TypeReference reference ) { builder.append( reference.declaringClassName() ).append( '$' ); } - builder.append( reference.simpleName() ); + builder.append( reference.name() ); return builder.toString(); } @@ -155,15 +155,10 @@ private static String internalSignature( TypeReference reference ) private static StringBuilder internalType( StringBuilder builder, TypeReference reference, boolean showErasure ) { - String name; + String name = reference.name(); if ( reference.isArray() ) { builder.append( "[" ); - name = reference.simpleName().substring( 0, reference.simpleName().length() - 2 ); - } - else - { - name = reference.simpleName(); } switch ( name ) diff --git a/community/codegen/src/main/java/org/neo4j/codegen/ClassHandle.java b/community/codegen/src/main/java/org/neo4j/codegen/ClassHandle.java index 0560a4ca3b091..28fb24e6b5315 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/ClassHandle.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/ClassHandle.java @@ -54,7 +54,7 @@ public Object newInstance() throws CompilationFailureException, IllegalAccessExc public Class loadClass() throws CompilationFailureException { - return generator.loadClass( name(), generation ); + return generator.loadClass( fullName(), generation ); } public TypeReference parent() diff --git a/community/codegen/src/main/java/org/neo4j/codegen/Expression.java b/community/codegen/src/main/java/org/neo4j/codegen/Expression.java index 2c3daee917695..6ab2c0f44072a 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/Expression.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/Expression.java @@ -511,35 +511,38 @@ public void accept( ExpressionVisitor visitor ) /** box expression */ public static Expression box( final Expression expression ) { - TypeReference type; - switch ( expression.type.simpleName() ) - { - case "byte": - type = TypeReference.typeReference( Byte.class ); - break; - case "short": - type = TypeReference.typeReference( Short.class ); - break; - case "int": - type = TypeReference.typeReference( Integer.class ); - break; - case "long": - type = TypeReference.typeReference( Long.class ); - break; - case "char": - type = TypeReference.typeReference( Character.class ); - break; - case "boolean": - type = TypeReference.typeReference( Boolean.class ); - break; - case "float": - type = TypeReference.typeReference( Float.class ); - break; - case "double": - type = TypeReference.typeReference( Double.class ); - break; - default: - type = expression.type(); + TypeReference type = expression.type; + if ( type.isPrimitive() ) + { + switch ( type.name() ) + { + case "byte": + type = TypeReference.typeReference( Byte.class ); + break; + case "short": + type = TypeReference.typeReference( Short.class ); + break; + case "int": + type = TypeReference.typeReference( Integer.class ); + break; + case "long": + type = TypeReference.typeReference( Long.class ); + break; + case "char": + type = TypeReference.typeReference( Character.class ); + break; + case "boolean": + type = TypeReference.typeReference( Boolean.class ); + break; + case "float": + type = TypeReference.typeReference( Float.class ); + break; + case "double": + type = TypeReference.typeReference( Double.class ); + break; + default: + break; + } } return new Expression( type ) { @@ -555,7 +558,7 @@ public void accept( ExpressionVisitor visitor ) public static Expression unbox( final Expression expression ) { TypeReference type; - switch ( expression.type.name() ) + switch ( expression.type.fullName() ) { case "java.lang.Byte": type = TypeReference.typeReference( byte.class ); @@ -582,7 +585,7 @@ public static Expression unbox( final Expression expression ) type = TypeReference.typeReference( double.class ); break; default: - throw new IllegalStateException( "Cannot unbox " + expression.type.name() ); + throw new IllegalStateException( "Cannot unbox " + expression.type.fullName() ); } return new Expression( type ) { diff --git a/community/codegen/src/main/java/org/neo4j/codegen/MethodDeclaration.java b/community/codegen/src/main/java/org/neo4j/codegen/MethodDeclaration.java index d69fd84ddbfe2..6f0bffca1c42a 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/MethodDeclaration.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/MethodDeclaration.java @@ -241,7 +241,7 @@ public MethodDeclaration erased() private TypeReference erase( TypeReference reference, Map table ) { - TypeReference erasedReference = table.get( reference.name() ); + TypeReference erasedReference = table.get( reference.fullName() ); return erasedReference != null ? erasedReference : reference; } diff --git a/community/codegen/src/main/java/org/neo4j/codegen/TypeReference.java b/community/codegen/src/main/java/org/neo4j/codegen/TypeReference.java index 62365e985bb2b..d17286b1bd3e8 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/TypeReference.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/TypeReference.java @@ -61,44 +61,43 @@ public static TypeReference typeReference( Class type ) { return OBJECT; } - String packageName = "", simpleName, declaringClassName = ""; - if ( type.isArray() ) - { - simpleName = type.getComponentType().getCanonicalName() + "[]"; - } - else if (type.isPrimitive()) + String packageName = "", name, declaringClassName = ""; + + Class innerType = type.isArray() ? type.getComponentType() : type; + + if (innerType.isPrimitive()) { - simpleName = type.getName(); - switch ( simpleName ) + name = innerType.getName(); + switch ( name ) { case "boolean": - return BOOLEAN; + return type.isArray() ? BOOLEAN_ARRAY : BOOLEAN; case "int": - return INT; + return type.isArray() ? INT_ARRAY : INT; case "long": - return LONG; + return type.isArray() ? LONG_ARRAY : LONG; case "double": - return DOUBLE; + return type.isArray() ? DOUBLE_ARRAY : DOUBLE; default: // continue through the normal path } } else { - packageName = type.getPackage().getName(); - String canonicalName = type.getCanonicalName(); - Class declaringClass = type.getDeclaringClass(); + packageName = innerType.getPackage().getName(); + String canonicalName = innerType.getCanonicalName(); + Class declaringClass = innerType.getDeclaringClass(); if ( declaringClass != null) { declaringClassName = declaringClass.getSimpleName(); - simpleName = canonicalName.substring( packageName.length() + declaringClassName.length() + 2 ); + name = canonicalName.substring( packageName.length() + declaringClassName.length() + 2 ); } else { - simpleName = canonicalName.substring( packageName.length() + 1 ); + name = canonicalName.substring( packageName.length() + 1 ); } } - return new TypeReference( packageName, simpleName, type.isPrimitive(), type.isArray(), false, + return new TypeReference( packageName, name, type.isPrimitive(), type.isArray(), false, declaringClassName, type.getModifiers() ); } @@ -109,7 +108,7 @@ public static TypeReference typeParameter( String name ) public static TypeReference arrayOf( TypeReference type ) { - return new TypeReference( type.packageName, type.simpleName + "[]", false, true, false, type.declaringClassName, type.modifiers ); + return new TypeReference( type.packageName, type.name, false, true, false, type.declaringClassName, type.modifiers ); } public static TypeReference parameterizedType( Class base, Class... parameters ) @@ -124,7 +123,7 @@ public static TypeReference parameterizedType( Class base, TypeReference... p public static TypeReference parameterizedType( TypeReference base, TypeReference... parameters ) { - return new TypeReference( base.packageName, base.simpleName, false, base.isArray(), false, + return new TypeReference( base.packageName, base.name, false, base.isArray(), false, base.declaringClassName, base.modifiers, parameters ); } @@ -151,7 +150,7 @@ public static TypeReference[] typeReferences( Class[] types ) } private final String packageName; - private final String simpleName; + private final String name; private final TypeReference[] parameters; private final boolean isPrimitive; private final boolean isArray; @@ -165,13 +164,17 @@ public static TypeReference[] typeReferences( Class[] types ) public static final TypeReference INT = new TypeReference( "", "int", true, false, false, "", int.class.getModifiers() ); public static final TypeReference LONG = new TypeReference( "", "long", true, false, false, "", long.class.getModifiers() ); public static final TypeReference DOUBLE = new TypeReference( "", "double", true, false, false, "", double.class.getModifiers() ); + public static final TypeReference BOOLEAN_ARRAY = new TypeReference( "", "boolean", false, true, false, "", boolean.class.getModifiers() ); + public static final TypeReference INT_ARRAY = new TypeReference( "", "int", false, true, false, "", int.class.getModifiers() ); + public static final TypeReference LONG_ARRAY = new TypeReference( "", "long", false, true, false, "", long.class.getModifiers() ); + public static final TypeReference DOUBLE_ARRAY = new TypeReference( "", "double", false, true, false, "", double.class.getModifiers() ); static final TypeReference[] NO_TYPES = new TypeReference[0]; - TypeReference( String packageName, String simpleName, boolean isPrimitive, boolean isArray, + TypeReference( String packageName, String name, boolean isPrimitive, boolean isArray, boolean isTypeParameter, String declaringClassName, int modifiers, TypeReference... parameters ) { this.packageName = packageName; - this.simpleName = simpleName; + this.name = name; this.isPrimitive = isPrimitive; this.isArray = isArray; this.isTypeParameter = isTypeParameter; @@ -185,9 +188,14 @@ public String packageName() return packageName; } + public String name() + { + return name; + } + public String simpleName() { - return simpleName; + return isArray ? name + "[]" : name; } public boolean isPrimitive() @@ -210,7 +218,7 @@ public List parameters() return unmodifiableList( asList( parameters ) ); } - public String name() + public String fullName() { return writeTo( new StringBuilder() ).toString(); } @@ -260,7 +268,7 @@ public boolean equals( Object o ) { return false; } if ( packageName != null ? !packageName.equals( reference.packageName ) : reference.packageName != null ) { return false; } - if ( simpleName != null ? !simpleName.equals( reference.simpleName ) : reference.simpleName != null ) + if ( name != null ? !name.equals( reference.name ) : reference.name != null ) { return false; } // Probably incorrect - comparing Object[] arrays with Arrays.equals if ( !Arrays.equals( parameters, reference.parameters ) ) @@ -274,7 +282,7 @@ public boolean equals( Object o ) public int hashCode() { int result = packageName != null ? packageName.hashCode() : 0; - result = 31 * result + (simpleName != null ? simpleName.hashCode() : 0); + result = 31 * result + (name != null ? name.hashCode() : 0); result = 31 * result + Arrays.hashCode( parameters ); result = 31 * result + (isPrimitive ? 1 : 0); result = 31 * result + (isArray ? 1 : 0); @@ -300,7 +308,11 @@ StringBuilder writeTo( StringBuilder result ) { result.append( declaringClassName ).append( '.' ); } - result.append( simpleName ); + result.append( name ); + if ( isArray ) + { + result.append( "[]" ); + } if ( !(parameters == null || parameters.length == 0) ) { result.append( '<' ); diff --git a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ByteCodeExpressionVisitor.java b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ByteCodeExpressionVisitor.java index d6e244e8ed146..afebd61f992f3 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ByteCodeExpressionVisitor.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ByteCodeExpressionVisitor.java @@ -164,25 +164,32 @@ public void invoke( MethodReference method, Expression[] arguments ) @Override public void load( LocalVariable variable ) { - switch ( variable.type().simpleName() ) + if ( variable.type().isPrimitive() ) + { + switch ( variable.type().name() ) + { + case "int": + case "byte": + case "short": + case "char": + case "boolean": + methodVisitor.visitVarInsn( ILOAD, variable.index() ); + break; + case "long": + methodVisitor.visitVarInsn( LLOAD, variable.index() ); + break; + case "float": + methodVisitor.visitVarInsn( FLOAD, variable.index() ); + break; + case "double": + methodVisitor.visitVarInsn( DLOAD, variable.index() ); + break; + default: + methodVisitor.visitVarInsn( ALOAD, variable.index() ); + } + } + else { - case "int": - case "byte": - case "short": - case "char": - case "boolean": - methodVisitor.visitVarInsn( ILOAD, variable.index() ); - break; - case "long": - methodVisitor.visitVarInsn( LLOAD, variable.index() ); - break; - case "float": - methodVisitor.visitVarInsn( FLOAD, variable.index() ); - break; - case "double": - methodVisitor.visitVarInsn( DLOAD, variable.index() ); - break; - default: methodVisitor.visitVarInsn( ALOAD, variable.index() ); } } @@ -319,25 +326,32 @@ public void notEqual( Expression lhs, Expression rhs ) private void equal( Expression lhs, Expression rhs, boolean equal ) { assertSameType( lhs, rhs, "compare" ); - switch ( lhs.type().simpleName() ) + if ( lhs.type().isPrimitive() ) + { + switch ( lhs.type().name() ) + { + case "int": + case "byte": + case "short": + case "char": + case "boolean": + compareIntOrReferenceType( lhs, rhs, equal ? IF_ICMPNE : IF_ICMPEQ ); + break; + case "long": + compareLongOrFloatType( lhs, rhs, LCMP, equal ? IFNE : IFEQ ); + break; + case "float": + compareLongOrFloatType( lhs, rhs, FCMPL, equal ? IFNE : IFEQ ); + break; + case "double": + compareLongOrFloatType( lhs, rhs, DCMPL, equal ? IFNE : IFEQ ); + break; + default: + compareIntOrReferenceType( lhs, rhs, equal ? IF_ACMPNE : IF_ACMPEQ ); + } + } + else { - case "int": - case "byte": - case "short": - case "char": - case "boolean": - compareIntOrReferenceType( lhs, rhs, equal ? IF_ICMPNE : IF_ICMPEQ ); - break; - case "long": - compareLongOrFloatType( lhs, rhs, LCMP, equal ? IFNE : IFEQ ); - break; - case "float": - compareLongOrFloatType( lhs, rhs, FCMPL, equal ? IFNE : IFEQ ); - break; - case "double": - compareLongOrFloatType( lhs, rhs, DCMPL, equal ? IFNE : IFEQ ); - break; - default: compareIntOrReferenceType( lhs, rhs, equal ? IF_ACMPNE : IF_ACMPEQ ); } } @@ -546,8 +560,10 @@ public void pop( Expression expression ) public void box( Expression expression ) { expression.accept( this ); - switch ( expression.type().simpleName() ) + if ( expression.type().isPrimitive() ) { + switch ( expression.type().name() ) + { case "byte": methodVisitor.visitMethodInsn( INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false ); break; @@ -574,6 +590,7 @@ public void box( Expression expression ) break; default: //do nothing, expression is already boxed + } } } @@ -581,7 +598,7 @@ public void box( Expression expression ) public void unbox( Expression expression ) { expression.accept( this ); - switch ( expression.type().name() ) + switch ( expression.type().fullName() ) { case "java.lang.Byte": methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false); @@ -608,7 +625,7 @@ public void unbox( Expression expression ) methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false); break; default: - throw new IllegalStateException( "Cannot unbox " + expression.type().name() ); + throw new IllegalStateException( "Cannot unbox " + expression.type().fullName() ); } } @@ -689,75 +706,93 @@ else if ( integer == 1L ) private void createArray( TypeReference reference ) { - switch ( reference.name() ) + if ( reference.isPrimitive() ) + { + switch ( reference.name() ) + { + case "int": + methodVisitor.visitIntInsn( NEWARRAY, T_INT ); + break; + case "long": + methodVisitor.visitIntInsn( NEWARRAY, T_LONG ); + break; + case "byte": + methodVisitor.visitIntInsn( NEWARRAY, T_BYTE ); + break; + case "short": + methodVisitor.visitIntInsn( NEWARRAY, T_SHORT ); + break; + case "char": + methodVisitor.visitIntInsn( NEWARRAY, T_CHAR ); + break; + case "float": + methodVisitor.visitIntInsn( NEWARRAY, T_FLOAT ); + break; + case "double": + methodVisitor.visitIntInsn( NEWARRAY, T_DOUBLE ); + break; + case "boolean": + methodVisitor.visitIntInsn( NEWARRAY, T_BOOLEAN ); + break; + default: + methodVisitor.visitTypeInsn( ANEWARRAY, byteCodeName( reference ) ); + } + } + else { - case "int": - methodVisitor.visitIntInsn( NEWARRAY, T_INT ); - break; - case "long": - methodVisitor.visitIntInsn( NEWARRAY, T_LONG ); - break; - case "byte": - methodVisitor.visitIntInsn( NEWARRAY, T_BYTE ); - break; - case "short": - methodVisitor.visitIntInsn( NEWARRAY, T_SHORT ); - break; - case "char": - methodVisitor.visitIntInsn( NEWARRAY, T_CHAR ); - break; - case "float": - methodVisitor.visitIntInsn( NEWARRAY, T_FLOAT ); - break; - case "double": - methodVisitor.visitIntInsn( NEWARRAY, T_DOUBLE ); - break; - case "boolean": - methodVisitor.visitIntInsn( NEWARRAY, T_BOOLEAN ); - break; - default: methodVisitor.visitTypeInsn( ANEWARRAY, byteCodeName( reference ) ); } } private void arrayStore( TypeReference reference ) { - switch ( reference.name() ) + if ( reference.isPrimitive() ) + { + switch ( reference.name() ) + { + case "int": + methodVisitor.visitInsn( IASTORE ); + break; + case "long": + methodVisitor.visitInsn( LASTORE ); + break; + case "byte": + methodVisitor.visitInsn( BASTORE ); + break; + case "short": + methodVisitor.visitInsn( SASTORE ); + break; + case "char": + methodVisitor.visitInsn( CASTORE ); + break; + case "float": + methodVisitor.visitInsn( FASTORE ); + break; + case "double": + methodVisitor.visitInsn( DASTORE ); + break; + case "boolean": + methodVisitor.visitInsn( BASTORE ); + break; + default: + methodVisitor.visitInsn( AASTORE ); + } + } + else { - case "int": - methodVisitor.visitInsn( IASTORE ); - break; - case "long": - methodVisitor.visitInsn( LASTORE ); - break; - case "byte": - methodVisitor.visitInsn( BASTORE ); - break; - case "short": - methodVisitor.visitInsn( SASTORE ); - break; - case "char": - methodVisitor.visitInsn( CASTORE ); - break; - case "float": - methodVisitor.visitInsn( FASTORE ); - break; - case "double": - methodVisitor.visitInsn( DASTORE ); - break; - case "boolean": - methodVisitor.visitInsn( BASTORE ); - break; - default: methodVisitor.visitInsn( AASTORE ); - } } private void numberOperation( TypeReference type, Runnable onInt, Runnable onLong, Runnable onFloat, Runnable onDouble ) { - switch ( type.simpleName() ) + if ( !type.isPrimitive() ) + { + throw new IllegalStateException( "Cannot compare reference types" ); + } + + switch ( type.name() ) { case "int": case "byte": diff --git a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ClassByteCodeWriter.java b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ClassByteCodeWriter.java index 9a9f29e7f760a..4d409dfd9413a 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ClassByteCodeWriter.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/ClassByteCodeWriter.java @@ -123,7 +123,7 @@ public ByteCodes toByteCodes() @Override public String name() { - return type.name(); + return type.fullName(); } @Override diff --git a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java index 1e73bfb959af1..a3ec1387d531d 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java @@ -74,7 +74,7 @@ public MethodByteCodeEmitter( ClassWriter classWriter, MethodDeclaration declara for ( Parameter parameter : declaration.parameters() ) { TypeReference type = parameter.type(); - if ( type.isInnerClass() ) + if ( type.isInnerClass() && !type.isArray() ) { classWriter.visitInnerClass( byteCodeName( type ), outerName( type ), type.simpleName(), type.modifiers() ); @@ -118,25 +118,32 @@ public void returns() public void returns( Expression value ) { value.accept( expressionVisitor ); - switch ( declaration.returnType().simpleName() ) + if ( declaration.returnType().isPrimitive() ) + { + switch ( declaration.returnType().name() ) + { + case "int": + case "byte": + case "short": + case "char": + case "boolean": + methodVisitor.visitInsn( IRETURN ); + break; + case "long": + methodVisitor.visitInsn( LRETURN ); + break; + case "float": + methodVisitor.visitInsn( FRETURN ); + break; + case "double": + methodVisitor.visitInsn( DRETURN ); + break; + default: + methodVisitor.visitInsn( ARETURN ); + } + } + else { - case "int": - case "byte": - case "short": - case "char": - case "boolean": - methodVisitor.visitInsn( IRETURN ); - break; - case "long": - methodVisitor.visitInsn( LRETURN ); - break; - case "float": - methodVisitor.visitInsn( FRETURN ); - break; - case "double": - methodVisitor.visitInsn( DRETURN ); - break; - default: methodVisitor.visitInsn( ARETURN ); } } @@ -145,25 +152,32 @@ public void returns( Expression value ) public void assign( LocalVariable variable, Expression value ) { value.accept( expressionVisitor ); - switch ( variable.type().simpleName() ) + if ( variable.type().isPrimitive() ) + { + switch ( variable.type().name() ) + { + case "int": + case "byte": + case "short": + case "char": + case "boolean": + methodVisitor.visitVarInsn( ISTORE, variable.index() ); + break; + case "long": + methodVisitor.visitVarInsn( LSTORE, variable.index() ); + break; + case "float": + methodVisitor.visitVarInsn( FSTORE, variable.index() ); + break; + case "double": + methodVisitor.visitVarInsn( DSTORE, variable.index() ); + break; + default: + methodVisitor.visitVarInsn( ASTORE, variable.index() ); + } + } + else { - case "int": - case "byte": - case "short": - case "char": - case "boolean": - methodVisitor.visitVarInsn( ISTORE, variable.index() ); - break; - case "long": - methodVisitor.visitVarInsn( LSTORE, variable.index() ); - break; - case "float": - methodVisitor.visitVarInsn( FSTORE, variable.index() ); - break; - case "double": - methodVisitor.visitVarInsn( DSTORE, variable.index() ); - break; - default: methodVisitor.visitVarInsn( ASTORE, variable.index() ); } } diff --git a/community/codegen/src/main/java/org/neo4j/codegen/source/ClassSourceWriter.java b/community/codegen/src/main/java/org/neo4j/codegen/source/ClassSourceWriter.java index f3902a482b5f2..c2bbf0c8db440 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/source/ClassSourceWriter.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/source/ClassSourceWriter.java @@ -53,12 +53,12 @@ void javadoc( String javadoc ) void publicClass( TypeReference type ) { - append( "public class " ).append( type.simpleName() ); + append( "public class " ).append( type.name() ); } void extendClass( TypeReference base ) { - append( " extends " ).append( base.name() ).append( "\n" ); + append( " extends " ).append( base.fullName() ).append( "\n" ); } void implement( TypeReference[] interfaces ) @@ -66,7 +66,7 @@ void implement( TypeReference[] interfaces ) String prefix = " implements "; for ( TypeReference iFace : interfaces ) { - append( prefix ).append( iFace.name() ); + append( prefix ).append( iFace.fullName() ); prefix = ", "; } if ( prefix.length() == 2 ) @@ -95,20 +95,20 @@ public MethodEmitter method( MethodDeclaration signature ) { target.append( " " ).append( Modifier.toString( signature.modifiers() ) ).append( " " ); typeParameters( target, signature ); - target.append( signature.declaringClass().simpleName() ); + target.append( signature.declaringClass().name() ); } } else { target.append( " " ).append( Modifier.toString( signature.modifiers() ) ).append( " " ); typeParameters( target, signature ); - target.append( signature.returnType().name() ).append( " " ).append( signature.name() ); + target.append( signature.returnType().fullName() ).append( " " ).append( signature.name() ); } target.append( "(" ); String prefix = " "; for ( Parameter parameter : signature.parameters() ) { - target.append( prefix ).append( parameter.type().name() ).append( " " ).append( parameter.name() ); + target.append( prefix ).append( parameter.type().fullName() ).append( " " ).append( parameter.name() ); prefix = ", "; } if ( prefix.length() > 1 ) @@ -119,7 +119,7 @@ public MethodEmitter method( MethodDeclaration signature ) String sep = " throws "; for ( TypeReference thrown : signature.throwsList() ) { - target.append( sep ).append( thrown.name() ); + target.append( sep ).append( thrown.fullName() ); sep = ", "; } target.append( "\n {\n" ); @@ -139,11 +139,11 @@ private static void typeParameters( StringBuilder target, MethodDeclaration meth TypeReference ext = parameter.extendsBound(), sup = parameter.superBound(); if ( ext != null ) { - target.append( " extends " ).append( ext.name() ); + target.append( " extends " ).append( ext.fullName() ); } else if ( sup != null ) { - target.append( " super " ).append( sup.name() ); + target.append( " super " ).append( sup.fullName() ); } sep = ", "; } @@ -166,7 +166,7 @@ public void field( FieldReference field, Expression value ) { append( " " ); } - append( field.type().name() ).append( ' ' ).append( field.name() ); + append( field.type().fullName() ).append( ' ' ).append( field.name() ); if ( value != null ) { append( " = " ); diff --git a/community/codegen/src/main/java/org/neo4j/codegen/source/MethodSourceWriter.java b/community/codegen/src/main/java/org/neo4j/codegen/source/MethodSourceWriter.java index 7c6c3ddbc326d..d010c371b9193 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/source/MethodSourceWriter.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/source/MethodSourceWriter.java @@ -113,7 +113,7 @@ public void returns( Expression value ) @Override public void declare( LocalVariable local ) { - indent().append( local.type().name() ).append( ' ' ).append( local.name() ).append( ";\n" ); + indent().append( local.type().fullName() ).append( ' ' ).append( local.name() ).append( ";\n" ); } @Override @@ -127,7 +127,7 @@ public void assignVariableInScope( LocalVariable local, Expression value ) @Override public void assign( LocalVariable variable, Expression value ) { - indent().append( variable.type().name() ).append( ' ' ).append( variable.name() ).append( " = " ); + indent().append( variable.type().fullName() ).append( ' ' ).append( variable.name() ).append( " = " ); value.accept( this ); append( ";\n" ); } @@ -170,7 +170,7 @@ public void tryCatchBlock( Consumer body, Consumer handler, LocalVaria level.pop(); indent().append( "}\n" ); indent().append( "catch ( " ) - .append( exception.type().name() ).append( " " ) + .append( exception.type().fullName() ).append( " " ) .append( exception.name() ) .append( " )\n" ); indent().append( "{\n" ); @@ -210,7 +210,7 @@ public void invoke( Expression target, MethodReference method, Expression[] argu @Override public void invoke( MethodReference method, Expression[] arguments ) { - append( method.owner().name() ).append( '.' ).append( method.name() ); + append( method.owner().fullName() ).append( '.' ).append( method.name() ); arglist( arguments ); } @@ -280,7 +280,7 @@ else if ( value instanceof Boolean ) @Override public void getStatic( FieldReference field ) { - append( field.owner().name() ).append( "." ).append( field.name() ); + append( field.owner().fullName() ).append( "." ).append( field.name() ); } @Override @@ -292,7 +292,7 @@ public void loadThis( String sourceName ) @Override public void newInstance( TypeReference type ) { - append( "new " ).append( type.name() ); + append( "new " ).append( type.fullName() ); } @Override @@ -421,7 +421,7 @@ private void div( Expression lhs, Expression rhs ) public void cast( TypeReference type, Expression expression ) { append( "(" ); - append( "(" ).append( type.name() ).append( ") " ); + append( "(" ).append( type.fullName() ).append( ") " ); expression.accept( this ); append( ")" ); } @@ -429,7 +429,7 @@ public void cast( TypeReference type, Expression expression ) @Override public void newArray( TypeReference type, Expression... constants ) { - append( "new " ).append( type.name() ).append( "[]{" ); + append( "new " ).append( type.fullName() ).append( "[]{" ); String sep = ""; for ( Expression constant : constants ) { diff --git a/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCode.java b/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCode.java index 8601e8a8ba025..2a81aa838a1ff 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCode.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCode.java @@ -69,7 +69,7 @@ protected String name() @Override protected void visitSource( TypeReference reference, CharSequence sourceCode ) { - System.out.println( "=== Generated class " + reference.name() + " ===\n" + sourceCode ); + System.out.println( "=== Generated class " + reference.fullName() + " ===\n" + sourceCode ); } @Override @@ -174,7 +174,7 @@ protected void visitSource( TypeReference reference, CharSequence sourceCode ) private Path path( TypeReference reference ) { - return path.resolve( reference.packageName().replace( '.', '/' ) + "/" + reference.simpleName() + ".java" ); + return path.resolve( reference.packageName().replace( '.', '/' ) + "/" + reference.name() + ".java" ); } } diff --git a/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCodeGenerator.java b/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCodeGenerator.java index f0fed6d5d3731..916076d2fbf57 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCodeGenerator.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/source/SourceCodeGenerator.java @@ -81,7 +81,7 @@ private synchronized List sourceFiles() StringBuilder source = entry.getValue(); configuration.visit( reference, source ); sourceFiles.add( new JavaSourceFile( configuration.sourceBase().uri( - reference.packageName(), reference.simpleName(), JavaFileObject.Kind.SOURCE ), source ) ); + reference.packageName(), reference.name(), JavaFileObject.Kind.SOURCE ), source ) ); } return sourceFiles; } diff --git a/community/codegen/src/test/java/org/neo4j/codegen/CodeGenerationTest.java b/community/codegen/src/test/java/org/neo4j/codegen/CodeGenerationTest.java index 49b281250d1e7..4534612e88cb6 100644 --- a/community/codegen/src/test/java/org/neo4j/codegen/CodeGenerationTest.java +++ b/community/codegen/src/test/java/org/neo4j/codegen/CodeGenerationTest.java @@ -25,8 +25,10 @@ import java.lang.reflect.Field; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.function.BiFunction; import java.util.function.Function; @@ -223,6 +225,13 @@ public void shouldGenerateMethodReturningFieldValue() throws Throwable assertMethodReturningField( double.class, 42D ); assertMethodReturningField( String.class, "42" ); assertMethodReturningField( int[].class, new int[]{42} ); + assertMethodReturningField( Map.Entry[].class, Collections.singletonMap( 42, "42" ).entrySet().toArray( new Map.Entry[0] ) ); + } + + @Test + public void temp() throws Throwable + { + assertMethodReturningField( Map.Entry[].class, Collections.singletonMap( 42, "42" ).entrySet().toArray( new Map.Entry[0] ) ); } @Test diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/codegen/GeneratedQueryStructure.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/codegen/GeneratedQueryStructure.scala index d46a42b09b9ab..5493b544e9707 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/codegen/GeneratedQueryStructure.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/codegen/GeneratedQueryStructure.scala @@ -57,7 +57,7 @@ object GeneratedQueryStructure extends CodeStructure[GeneratedQuery] { val option = if(conf.saveSource) { if(mode == SOURCECODE) new SourceVisitor { override protected def visitSource(reference: TypeReference, sourceCode: CharSequence): Unit = - source(reference.name(), sourceCode.toString) + source(reference.fullName(), sourceCode.toString) } else new DisassemblyVisitor { override protected def visitDisassembly(className: String, disassembly: CharSequence): Unit = source(className, disassembly.toString)