Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a5701c
commit 45e9554
Showing
10 changed files
with
363 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...org.codehaus.groovy24/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.sc; | ||
|
||
import org.codehaus.groovy.ast.ClassHelper; | ||
import org.codehaus.groovy.ast.ClassNode; | ||
import org.codehaus.groovy.ast.expr.Expression; | ||
import org.codehaus.groovy.ast.expr.VariableExpression; | ||
import org.codehaus.groovy.classgen.asm.StatementMetaTypeChooser; | ||
import org.codehaus.groovy.transform.stc.StaticTypesMarker; | ||
|
||
/** | ||
* A {@link org.codehaus.groovy.classgen.asm.TypeChooser} which reads type information from node metadata | ||
* generated by the {@link groovy.transform.CompileStatic} annotation. | ||
*/ | ||
public class StaticTypesTypeChooser extends StatementMetaTypeChooser { | ||
@Override | ||
public ClassNode resolveType(final Expression exp, final ClassNode current) { | ||
/* GRECLIPSE edit | ||
ASTNode target = exp instanceof VariableExpression ? getTarget((VariableExpression) exp) : exp; | ||
*/ | ||
Expression target = exp instanceof VariableExpression && !((VariableExpression) exp).isClosureSharedVariable() ? getTarget((VariableExpression) exp) : exp; | ||
// GRECLIPSE end | ||
ClassNode inferredType = target.getNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE); | ||
if (inferredType == null) { | ||
inferredType = target.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); | ||
/* GRECLIPSE edit | ||
if (inferredType == null && target instanceof VariableExpression && ((VariableExpression) target).getAccessedVariable() instanceof Parameter) { | ||
target = (Parameter) ((VariableExpression) target).getAccessedVariable(); | ||
inferredType = ((Parameter) target).getOriginType(); | ||
} | ||
*/ | ||
} | ||
if (inferredType != null) { | ||
if (ClassHelper.VOID_TYPE == inferredType) { | ||
// we are in a case of a type inference failure, probably because code was generated | ||
// it is better to avoid using this | ||
inferredType = super.resolveType(exp, current); | ||
} | ||
return inferredType; | ||
} | ||
if (target instanceof VariableExpression && ((VariableExpression) target).isThisExpression()) { | ||
// AsmClassGenerator may create "this" expressions that the type checker knows nothing about | ||
return current; | ||
} | ||
return super.resolveType(exp, current); | ||
} | ||
|
||
/** | ||
* The inferred type, in case of a variable expression, can be set on the accessed variable, so we take it instead | ||
* of the facade one. | ||
* | ||
* @param ve the variable expression for which to return the target expression | ||
* @return the target variable expression | ||
*/ | ||
private static VariableExpression getTarget(VariableExpression ve) { | ||
if (ve.getAccessedVariable() == null || ve.getAccessedVariable() == ve || (!(ve.getAccessedVariable() instanceof VariableExpression))) | ||
return ve; | ||
return getTarget((VariableExpression) ve.getAccessedVariable()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.sc; | ||
|
||
import org.codehaus.groovy.ast.ClassHelper; | ||
import org.codehaus.groovy.ast.ClassNode; | ||
import org.codehaus.groovy.ast.expr.Expression; | ||
import org.codehaus.groovy.ast.expr.VariableExpression; | ||
import org.codehaus.groovy.classgen.asm.StatementMetaTypeChooser; | ||
import org.codehaus.groovy.transform.stc.StaticTypesMarker; | ||
|
||
/** | ||
* A {@link org.codehaus.groovy.classgen.asm.TypeChooser} which reads type information from node metadata | ||
* generated by the {@link groovy.transform.CompileStatic} annotation. | ||
*/ | ||
public class StaticTypesTypeChooser extends StatementMetaTypeChooser { | ||
@Override | ||
public ClassNode resolveType(final Expression exp, final ClassNode current) { | ||
/* GRECLIPSE edit | ||
ASTNode target = exp instanceof VariableExpression ? getTarget((VariableExpression) exp) : exp; | ||
*/ | ||
Expression target = exp instanceof VariableExpression && !((VariableExpression) exp).isClosureSharedVariable() ? getTarget((VariableExpression) exp) : exp; | ||
// GRECLIPSE end | ||
ClassNode inferredType = target.getNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE); | ||
if (inferredType == null) { | ||
inferredType = target.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); | ||
/* GRECLIPSE edit | ||
if (inferredType == null && target instanceof VariableExpression && ((VariableExpression) target).getAccessedVariable() instanceof Parameter) { | ||
target = (Parameter) ((VariableExpression) target).getAccessedVariable(); | ||
inferredType = ((Parameter) target).getOriginType(); | ||
} | ||
*/ | ||
} | ||
if (inferredType != null) { | ||
if (ClassHelper.VOID_TYPE == inferredType) { | ||
// we are in a case of a type inference failure, probably because code was generated | ||
// it is better to avoid using this | ||
inferredType = super.resolveType(exp, current); | ||
} | ||
return inferredType; | ||
} | ||
if (target instanceof VariableExpression && ((VariableExpression) target).isThisExpression()) { | ||
// AsmClassGenerator may create "this" expressions that the type checker knows nothing about | ||
return current; | ||
} | ||
return super.resolveType(exp, current); | ||
} | ||
|
||
/** | ||
* The inferred type, in case of a variable expression, can be set on the accessed variable, so we take it instead | ||
* of the facade one. | ||
* | ||
* @param ve the variable expression for which to return the target expression | ||
* @return the target variable expression | ||
*/ | ||
private static VariableExpression getTarget(VariableExpression ve) { | ||
if (ve.getAccessedVariable() == null || ve.getAccessedVariable() == ve || (!(ve.getAccessedVariable() instanceof VariableExpression))) | ||
return ve; | ||
return getTarget((VariableExpression) ve.getAccessedVariable()); | ||
} | ||
} |
Oops, something went wrong.