Skip to content

Commit

Permalink
GROOVY-9955 (pt.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 6, 2021
1 parent 4aaf8f7 commit e6dfebc
Show file tree
Hide file tree
Showing 13 changed files with 3,001 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5947,6 +5947,7 @@ public void testCompileStatic9955() {
"import p.Types.Public\n" +
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" assert Public.answer == 42\n" +
" assert Public.CONST == 'XX'\n" +
" assert Public.VALUE == null\n" +
" Public.VALUE = 'YY'\n" +
Expand All @@ -5960,6 +5961,7 @@ public void testCompileStatic9955() {
"package p\n" +
"class Types {\n" +
" @groovy.transform.PackageScope static class PackagePrivate {\n" +
" public static Number getAnswer() { 42 }\n" +
" public static final String CONST = 'XX'\n" +
" public static String VALUE\n" +
" }\n" +
Expand Down
2 changes: 2 additions & 0 deletions base/org.codehaus.groovy25/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
<file-match-pattern match-pattern="groovy/classgen/asm/BytecodeHelper.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/CallSiteWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/CompileStack.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/InvocationWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/StatementMetaTypeChooser.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/(Optimizing)?StatementWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticPropertyAccessHelper.java" include-pattern="false" />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.codehaus.groovy.classgen.asm;

import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.ast.Variable;
import org.codehaus.groovy.ast.expr.ClassExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.VariableExpression;

/**
* A {@link TypeChooser} which is aware of statement metadata.
*/
public class StatementMetaTypeChooser implements TypeChooser {
public ClassNode resolveType(final Expression exp, final ClassNode current) {
if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
ClassNode type = null;
if (meta != null) type = meta.type;
if (type != null) return type;
if (exp instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) exp;
if (ve.isClosureSharedVariable()) return ve.getType();
type = ve.getOriginType();
if (ve.getAccessedVariable() instanceof FieldNode) {
FieldNode fn = (FieldNode) ve.getAccessedVariable();
if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType();
}
} else if (exp instanceof Variable) {
Variable v = (Variable) exp;
type = v.getOriginType();
} else {
type = exp.getType();
}
// GRECLIPSE edit -- GROOVY-9955
return type/*.redirect()*/;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import static org.apache.groovy.ast.tools.ClassNodeUtils.samePackageName;
import static org.codehaus.groovy.ast.ClassHelper.CLOSURE_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.getWrapper;
import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.PRIVATE_BRIDGE_METHODS;
import static groovyjarjarasm.asm.Opcodes.ACONST_NULL;
Expand Down Expand Up @@ -761,7 +760,12 @@ public ClassNode getType() {
if (target instanceof ExtensionMethodNode) {
type = ((ExtensionMethodNode) target).getExtensionMethodNode().getDeclaringClass();
} else {
/* GRECLIPSE edit -- GROOVY-9955
type = getWrapper(controller.getTypeChooser().resolveType(receiver, controller.getClassNode()));
*/
type = controller.getTypeChooser().resolveType(receiver, controller.getClassNode());
if (ClassHelper.isPrimitiveType(type)) type = ClassHelper.getWrapper(type);
// GRECLIPSE end
ClassNode declaringClass = target.getDeclaringClass();
if (type.getClass() != ClassNode.class
&& type.getClass() != InnerClassNode.class
Expand Down
2 changes: 2 additions & 0 deletions base/org.codehaus.groovy30/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<file-match-pattern match-pattern="groovy/classgen/Verifier.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/CallSiteWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/CompileStack.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/InvocationWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/StatementMetaTypeChooser.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/StatementWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticPropertyAccessHelper.java" include-pattern="false" />
Expand Down
Loading

0 comments on commit e6dfebc

Please sign in to comment.