Skip to content

Commit e6dfebc

Browse files
committed
GROOVY-9955 (pt.2)
1 parent 4aaf8f7 commit e6dfebc

13 files changed

Lines changed: 3001 additions & 1 deletion

File tree

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,6 +5947,7 @@ public void testCompileStatic9955() {
59475947
"import p.Types.Public\n" +
59485948
"@groovy.transform.CompileStatic\n" +
59495949
"void test() {\n" +
5950+
" assert Public.answer == 42\n" +
59505951
" assert Public.CONST == 'XX'\n" +
59515952
" assert Public.VALUE == null\n" +
59525953
" Public.VALUE = 'YY'\n" +
@@ -5960,6 +5961,7 @@ public void testCompileStatic9955() {
59605961
"package p\n" +
59615962
"class Types {\n" +
59625963
" @groovy.transform.PackageScope static class PackagePrivate {\n" +
5964+
" public static Number getAnswer() { 42 }\n" +
59635965
" public static final String CONST = 'XX'\n" +
59645966
" public static String VALUE\n" +
59655967
" }\n" +

base/org.codehaus.groovy25/.checkstyle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<file-match-pattern match-pattern="groovy/classgen/asm/BytecodeHelper.java" include-pattern="false" />
4949
<file-match-pattern match-pattern="groovy/classgen/asm/CallSiteWriter.java" include-pattern="false" />
5050
<file-match-pattern match-pattern="groovy/classgen/asm/CompileStack.java" include-pattern="false" />
51+
<file-match-pattern match-pattern="groovy/classgen/asm/InvocationWriter.java" include-pattern="false" />
52+
<file-match-pattern match-pattern="groovy/classgen/asm/StatementMetaTypeChooser.java" include-pattern="false" />
5153
<file-match-pattern match-pattern="groovy/classgen/asm/(Optimizing)?StatementWriter.java" include-pattern="false" />
5254
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />
5355
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticPropertyAccessHelper.java" include-pattern="false" />

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/InvocationWriter.java

Lines changed: 970 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.codehaus.groovy.classgen.asm;
20+
21+
import org.codehaus.groovy.ast.ClassHelper;
22+
import org.codehaus.groovy.ast.ClassNode;
23+
import org.codehaus.groovy.ast.FieldNode;
24+
import org.codehaus.groovy.ast.Variable;
25+
import org.codehaus.groovy.ast.expr.ClassExpression;
26+
import org.codehaus.groovy.ast.expr.Expression;
27+
import org.codehaus.groovy.ast.expr.VariableExpression;
28+
29+
/**
30+
* A {@link TypeChooser} which is aware of statement metadata.
31+
*/
32+
public class StatementMetaTypeChooser implements TypeChooser {
33+
public ClassNode resolveType(final Expression exp, final ClassNode current) {
34+
if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
35+
OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
36+
ClassNode type = null;
37+
if (meta != null) type = meta.type;
38+
if (type != null) return type;
39+
if (exp instanceof VariableExpression) {
40+
VariableExpression ve = (VariableExpression) exp;
41+
if (ve.isClosureSharedVariable()) return ve.getType();
42+
type = ve.getOriginType();
43+
if (ve.getAccessedVariable() instanceof FieldNode) {
44+
FieldNode fn = (FieldNode) ve.getAccessedVariable();
45+
if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType();
46+
}
47+
} else if (exp instanceof Variable) {
48+
Variable v = (Variable) exp;
49+
type = v.getOriginType();
50+
} else {
51+
type = exp.getType();
52+
}
53+
// GRECLIPSE edit -- GROOVY-9955
54+
return type/*.redirect()*/;
55+
}
56+
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
import static org.apache.groovy.ast.tools.ClassNodeUtils.samePackageName;
7575
import static org.codehaus.groovy.ast.ClassHelper.CLOSURE_TYPE;
7676
import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
77-
import static org.codehaus.groovy.ast.ClassHelper.getWrapper;
7877
import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
7978
import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.PRIVATE_BRIDGE_METHODS;
8079
import static groovyjarjarasm.asm.Opcodes.ACONST_NULL;
@@ -761,7 +760,12 @@ public ClassNode getType() {
761760
if (target instanceof ExtensionMethodNode) {
762761
type = ((ExtensionMethodNode) target).getExtensionMethodNode().getDeclaringClass();
763762
} else {
763+
/* GRECLIPSE edit -- GROOVY-9955
764764
type = getWrapper(controller.getTypeChooser().resolveType(receiver, controller.getClassNode()));
765+
*/
766+
type = controller.getTypeChooser().resolveType(receiver, controller.getClassNode());
767+
if (ClassHelper.isPrimitiveType(type)) type = ClassHelper.getWrapper(type);
768+
// GRECLIPSE end
765769
ClassNode declaringClass = target.getDeclaringClass();
766770
if (type.getClass() != ClassNode.class
767771
&& type.getClass() != InnerClassNode.class

base/org.codehaus.groovy30/.checkstyle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
<file-match-pattern match-pattern="groovy/classgen/Verifier.java" include-pattern="false" />
4848
<file-match-pattern match-pattern="groovy/classgen/asm/CallSiteWriter.java" include-pattern="false" />
4949
<file-match-pattern match-pattern="groovy/classgen/asm/CompileStack.java" include-pattern="false" />
50+
<file-match-pattern match-pattern="groovy/classgen/asm/InvocationWriter.java" include-pattern="false" />
51+
<file-match-pattern match-pattern="groovy/classgen/asm/StatementMetaTypeChooser.java" include-pattern="false" />
5052
<file-match-pattern match-pattern="groovy/classgen/asm/StatementWriter.java" include-pattern="false" />
5153
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />
5254
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticPropertyAccessHelper.java" include-pattern="false" />

0 commit comments

Comments
 (0)