org.extendj.ast.ConstructorReference Maven / Gradle / Ivy
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.0 */
package org.extendj.ast;
import java.util.ArrayList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.util.Set;
import beaver.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.LinkedHashSet;
import java.util.*;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import java.util.zip.*;
import java.io.*;
import org.jastadd.util.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
/**
* @ast node
* @declaredat /home/jesper/git/extendj/java8/grammar/ConstructorReference.ast:1
* @astdecl ConstructorReference : Expr ::= TypeAccess:Access;
* @production ConstructorReference : {@link Expr} ::= TypeAccess:{@link Access};
*/
public abstract class ConstructorReference extends Expr implements Cloneable {
/**
* @aspect PrettyPrintUtil8
* @declaredat /home/jesper/git/extendj/java8/frontend/PrettyPrintUtil.jadd:83
*/
@Override public String toString() {
return String.format("%s::new", getTypeAccessNoTransform().toString());
}
/**
* @aspect Java8CreateBCode
* @declaredat /home/jesper/git/extendj/java8/backend/CreateBCode.jrag:42
*/
public void createBCode(CodeGeneration gen) {
toClass().createBCode(gen);
}
/**
* @declaredat ASTNode:1
*/
public ConstructorReference() {
super();
}
/**
* Initializes the child array to the correct size.
* Initializes List and Opt nta children.
* @apilevel internal
* @ast method
* @declaredat ASTNode:10
*/
public void init$Children() {
children = new ASTNode[1];
}
/**
* @declaredat ASTNode:13
*/
@ASTNodeAnnotation.Constructor(
name = {"TypeAccess"},
type = {"Access"},
kind = {"Child"}
)
public ConstructorReference(Access p0) {
setChild(p0, 0);
}
/** @apilevel low-level
* @declaredat ASTNode:22
*/
protected int numChildren() {
return 1;
}
/**
* @apilevel internal
* @declaredat ASTNode:28
*/
public boolean mayHaveRewrite() {
return false;
}
/** @apilevel internal
* @declaredat ASTNode:32
*/
public void flushAttrCache() {
super.flushAttrCache();
isPolyExpression_reset();
assignConversionTo_TypeDecl_reset();
targetInterface_reset();
compatibleStrictContext_TypeDecl_reset();
compatibleLooseContext_TypeDecl_reset();
pertinentToApplicability_Expr_BodyDecl_int_reset();
moreSpecificThan_TypeDecl_TypeDecl_reset();
potentiallyCompatible_TypeDecl_BodyDecl_reset();
type_reset();
toClass_reset();
toParameterList_reset();
}
/** @apilevel internal
* @declaredat ASTNode:47
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:51
*/
public ConstructorReference clone() throws CloneNotSupportedException {
ConstructorReference node = (ConstructorReference) super.clone();
return node;
}
/**
* Create a deep copy of the AST subtree at this node.
* The copy is dangling, i.e. has no parent.
* @return dangling copy of the subtree at this node
* @apilevel low-level
* @deprecated Please use treeCopy or treeCopyNoTransform instead
* @declaredat ASTNode:62
*/
@Deprecated
public abstract ConstructorReference fullCopy();
/**
* Create a deep copy of the AST subtree at this node.
* The copy is dangling, i.e. has no parent.
* @return dangling copy of the subtree at this node
* @apilevel low-level
* @declaredat ASTNode:70
*/
public abstract ConstructorReference treeCopyNoTransform();
/**
* Create a deep copy of the AST subtree at this node.
* The subtree of this node is traversed to trigger rewrites before copy.
* The copy is dangling, i.e. has no parent.
* @return dangling copy of the subtree at this node
* @apilevel low-level
* @declaredat ASTNode:78
*/
public abstract ConstructorReference treeCopy();
/**
* Replaces the TypeAccess child.
* @param node The new node to replace the TypeAccess child.
* @apilevel high-level
*/
public void setTypeAccess(Access node) {
setChild(node, 0);
}
/**
* Retrieves the TypeAccess child.
* @return The current node used as the TypeAccess child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="TypeAccess")
public Access getTypeAccess() {
return (Access) getChild(0);
}
/**
* Retrieves the TypeAccess child.
* This method does not invoke AST transformations.
* @return The current node used as the TypeAccess child.
* @apilevel low-level
*/
public Access getTypeAccessNoTransform() {
return (Access) getChildNoTransform(0);
}
/**
* @attribute syn
* @aspect ConstructorReference
* @declaredat /home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:72
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="ConstructorReference", declaredAt="/home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:72")
public abstract boolean congruentTo(FunctionDescriptor fd);
/**
* @attribute syn
* @aspect ConstructorReference
* @declaredat /home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:153
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="ConstructorReference", declaredAt="/home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:153")
public abstract boolean isExact();
/**
* @attribute syn
* @aspect ConstructorReferenceToClass
* @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:97
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="ConstructorReferenceToClass", declaredAt="/home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:97")
public abstract Block toBlock();
/** @apilevel internal */
private void isPolyExpression_reset() {
isPolyExpression_computed = null;
}
/** @apilevel internal */
protected ASTState.Cycle isPolyExpression_computed = null;
/** @apilevel internal */
protected boolean isPolyExpression_value;
/**
* @attribute syn
* @aspect PolyExpressions
* @declaredat /home/jesper/git/extendj/java8/frontend/PolyExpressions.jrag:86
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="PolyExpressions", declaredAt="/home/jesper/git/extendj/java8/frontend/PolyExpressions.jrag:86")
public boolean isPolyExpression() {
ASTState state = state();
if (isPolyExpression_computed == ASTState.NON_CYCLE || isPolyExpression_computed == state().cycle()) {
return isPolyExpression_value;
}
isPolyExpression_value = true;
if (state().inCircle()) {
isPolyExpression_computed = state().cycle();
} else {
isPolyExpression_computed = ASTState.NON_CYCLE;
}
return isPolyExpression_value;
}
/** @apilevel internal */
private void assignConversionTo_TypeDecl_reset() {
assignConversionTo_TypeDecl_computed = null;
assignConversionTo_TypeDecl_values = null;
}
/** @apilevel internal */
protected java.util.Map assignConversionTo_TypeDecl_values;
/** @apilevel internal */
protected java.util.Map assignConversionTo_TypeDecl_computed;
/**
* @attribute syn
* @aspect PolyExpressions
* @declaredat /home/jesper/git/extendj/java8/frontend/PolyExpressions.jrag:149
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="PolyExpressions", declaredAt="/home/jesper/git/extendj/java8/frontend/PolyExpressions.jrag:149")
public boolean assignConversionTo(TypeDecl type) {
Object _parameters = type;
if (assignConversionTo_TypeDecl_computed == null) assignConversionTo_TypeDecl_computed = new java.util.HashMap(4);
if (assignConversionTo_TypeDecl_values == null) assignConversionTo_TypeDecl_values = new java.util.HashMap(4);
ASTState state = state();
if (assignConversionTo_TypeDecl_values.containsKey(_parameters)
&& assignConversionTo_TypeDecl_computed.containsKey(_parameters)
&& (assignConversionTo_TypeDecl_computed.get(_parameters) == ASTState.NON_CYCLE || assignConversionTo_TypeDecl_computed.get(_parameters) == state().cycle())) {
return (Boolean) assignConversionTo_TypeDecl_values.get(_parameters);
}
boolean assignConversionTo_TypeDecl_value = assignConversionTo_compute(type);
if (state().inCircle()) {
assignConversionTo_TypeDecl_values.put(_parameters, assignConversionTo_TypeDecl_value);
assignConversionTo_TypeDecl_computed.put(_parameters, state().cycle());
} else {
assignConversionTo_TypeDecl_values.put(_parameters, assignConversionTo_TypeDecl_value);
assignConversionTo_TypeDecl_computed.put(_parameters, ASTState.NON_CYCLE);
}
return assignConversionTo_TypeDecl_value;
}
/** @apilevel internal */
private boolean assignConversionTo_compute(TypeDecl type) {
if (!type.isFunctionalInterface()) {
return false;
}
FunctionDescriptor f = ((InterfaceDecl) type).functionDescriptor();
return congruentTo(f);
}
/** @apilevel internal */
private void targetInterface_reset() {
targetInterface_computed = null;
targetInterface_value = null;
}
/** @apilevel internal */
protected ASTState.Cycle targetInterface_computed = null;
/** @apilevel internal */
protected InterfaceDecl targetInterface_value;
/**
* @attribute syn
* @aspect TargetType
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:168
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TargetType", declaredAt="/home/jesper/git/extendj/java8/frontend/TargetType.jrag:168")
public InterfaceDecl targetInterface() {
ASTState state = state();
if (targetInterface_computed == ASTState.NON_CYCLE || targetInterface_computed == state().cycle()) {
return targetInterface_value;
}
targetInterface_value = targetInterface_compute();
if (state().inCircle()) {
targetInterface_computed = state().cycle();
} else {
targetInterface_computed = ASTState.NON_CYCLE;
}
return targetInterface_value;
}
/** @apilevel internal */
private InterfaceDecl targetInterface_compute() {
if (targetType().isNull()) {
return null;
} else if (!(targetType() instanceof InterfaceDecl)) {
return null;
} else {
return (InterfaceDecl) targetType();
}
}
/** @apilevel internal */
private void compatibleStrictContext_TypeDecl_reset() {
compatibleStrictContext_TypeDecl_computed = null;
compatibleStrictContext_TypeDecl_values = null;
}
/** @apilevel internal */
protected java.util.Map compatibleStrictContext_TypeDecl_values;
/** @apilevel internal */
protected java.util.Map compatibleStrictContext_TypeDecl_computed;
/** Used to compute compatibility during phase 1 of overload resolution.
* @attribute syn
* @aspect MethodSignature18
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:58
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodSignature18", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:58")
public boolean compatibleStrictContext(TypeDecl type) {
Object _parameters = type;
if (compatibleStrictContext_TypeDecl_computed == null) compatibleStrictContext_TypeDecl_computed = new java.util.HashMap(4);
if (compatibleStrictContext_TypeDecl_values == null) compatibleStrictContext_TypeDecl_values = new java.util.HashMap(4);
ASTState state = state();
if (compatibleStrictContext_TypeDecl_values.containsKey(_parameters)
&& compatibleStrictContext_TypeDecl_computed.containsKey(_parameters)
&& (compatibleStrictContext_TypeDecl_computed.get(_parameters) == ASTState.NON_CYCLE || compatibleStrictContext_TypeDecl_computed.get(_parameters) == state().cycle())) {
return (Boolean) compatibleStrictContext_TypeDecl_values.get(_parameters);
}
boolean compatibleStrictContext_TypeDecl_value = compatibleStrictContext_compute(type);
if (state().inCircle()) {
compatibleStrictContext_TypeDecl_values.put(_parameters, compatibleStrictContext_TypeDecl_value);
compatibleStrictContext_TypeDecl_computed.put(_parameters, state().cycle());
} else {
compatibleStrictContext_TypeDecl_values.put(_parameters, compatibleStrictContext_TypeDecl_value);
compatibleStrictContext_TypeDecl_computed.put(_parameters, ASTState.NON_CYCLE);
}
return compatibleStrictContext_TypeDecl_value;
}
/** @apilevel internal */
private boolean compatibleStrictContext_compute(TypeDecl type) {
if (!type.isFunctionalInterface()) {
return false;
}
InterfaceDecl iDecl = (InterfaceDecl) type;
return congruentTo(iDecl.functionDescriptor());
}
/** @apilevel internal */
private void compatibleLooseContext_TypeDecl_reset() {
compatibleLooseContext_TypeDecl_computed = null;
compatibleLooseContext_TypeDecl_values = null;
}
/** @apilevel internal */
protected java.util.Map compatibleLooseContext_TypeDecl_values;
/** @apilevel internal */
protected java.util.Map compatibleLooseContext_TypeDecl_computed;
/**
* @attribute syn
* @aspect MethodSignature18
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:102
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodSignature18", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:102")
public boolean compatibleLooseContext(TypeDecl type) {
Object _parameters = type;
if (compatibleLooseContext_TypeDecl_computed == null) compatibleLooseContext_TypeDecl_computed = new java.util.HashMap(4);
if (compatibleLooseContext_TypeDecl_values == null) compatibleLooseContext_TypeDecl_values = new java.util.HashMap(4);
ASTState state = state();
if (compatibleLooseContext_TypeDecl_values.containsKey(_parameters)
&& compatibleLooseContext_TypeDecl_computed.containsKey(_parameters)
&& (compatibleLooseContext_TypeDecl_computed.get(_parameters) == ASTState.NON_CYCLE || compatibleLooseContext_TypeDecl_computed.get(_parameters) == state().cycle())) {
return (Boolean) compatibleLooseContext_TypeDecl_values.get(_parameters);
}
boolean compatibleLooseContext_TypeDecl_value = compatibleStrictContext(type);
if (state().inCircle()) {
compatibleLooseContext_TypeDecl_values.put(_parameters, compatibleLooseContext_TypeDecl_value);
compatibleLooseContext_TypeDecl_computed.put(_parameters, state().cycle());
} else {
compatibleLooseContext_TypeDecl_values.put(_parameters, compatibleLooseContext_TypeDecl_value);
compatibleLooseContext_TypeDecl_computed.put(_parameters, ASTState.NON_CYCLE);
}
return compatibleLooseContext_TypeDecl_value;
}
/** @apilevel internal */
private void pertinentToApplicability_Expr_BodyDecl_int_reset() {
pertinentToApplicability_Expr_BodyDecl_int_computed = null;
pertinentToApplicability_Expr_BodyDecl_int_values = null;
}
/** @apilevel internal */
protected java.util.Map pertinentToApplicability_Expr_BodyDecl_int_values;
/** @apilevel internal */
protected java.util.Map pertinentToApplicability_Expr_BodyDecl_int_computed;
/**
* @attribute syn
* @aspect MethodSignature18
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:130
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodSignature18", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:130")
public boolean pertinentToApplicability(Expr access, BodyDecl decl, int argIndex) {
java.util.List _parameters = new java.util.ArrayList(3);
_parameters.add(access);
_parameters.add(decl);
_parameters.add(argIndex);
if (pertinentToApplicability_Expr_BodyDecl_int_computed == null) pertinentToApplicability_Expr_BodyDecl_int_computed = new java.util.HashMap(4);
if (pertinentToApplicability_Expr_BodyDecl_int_values == null) pertinentToApplicability_Expr_BodyDecl_int_values = new java.util.HashMap(4);
ASTState state = state();
if (pertinentToApplicability_Expr_BodyDecl_int_values.containsKey(_parameters)
&& pertinentToApplicability_Expr_BodyDecl_int_computed.containsKey(_parameters)
&& (pertinentToApplicability_Expr_BodyDecl_int_computed.get(_parameters) == ASTState.NON_CYCLE || pertinentToApplicability_Expr_BodyDecl_int_computed.get(_parameters) == state().cycle())) {
return (Boolean) pertinentToApplicability_Expr_BodyDecl_int_values.get(_parameters);
}
boolean pertinentToApplicability_Expr_BodyDecl_int_value = pertinentToApplicability_compute(access, decl, argIndex);
if (state().inCircle()) {
pertinentToApplicability_Expr_BodyDecl_int_values.put(_parameters, pertinentToApplicability_Expr_BodyDecl_int_value);
pertinentToApplicability_Expr_BodyDecl_int_computed.put(_parameters, state().cycle());
} else {
pertinentToApplicability_Expr_BodyDecl_int_values.put(_parameters, pertinentToApplicability_Expr_BodyDecl_int_value);
pertinentToApplicability_Expr_BodyDecl_int_computed.put(_parameters, ASTState.NON_CYCLE);
}
return pertinentToApplicability_Expr_BodyDecl_int_value;
}
/** @apilevel internal */
private boolean pertinentToApplicability_compute(Expr access, BodyDecl decl, int argIndex) {
if (!isExact()) {
return false;
}
if (decl instanceof MethodDecl
&& decl.isGeneric()
&& !(access instanceof ParMethodAccess)
&& ((MethodDecl) decl).genericDecl().getParameter(argIndex).type().isTypeVariable()) {
GenericMethodDecl genericDecl = ((MethodDecl) decl).genericDecl();
TypeVariable typeVar = (TypeVariable) genericDecl.getParameter(argIndex).type();
for (int i = 0; i < genericDecl.getNumTypeParameter(); i++) {
if (typeVar == genericDecl.getTypeParameter(i)) {
return false;
}
}
} else if (decl instanceof ConstructorDecl
&& decl.isGeneric()
&& !(access instanceof ParConstructorAccess)
&& !(access instanceof ParSuperConstructorAccess)
&& !(access instanceof ParClassInstanceExpr)
&& ((ConstructorDecl) decl).genericDecl().getParameter(argIndex).type().isTypeVariable()) {
GenericConstructorDecl genericDecl = ((ConstructorDecl) decl).genericDecl();
TypeVariable typeVar = (TypeVariable) genericDecl.getParameter(argIndex).type();
for (int i = 0; i < genericDecl.getNumTypeParameter(); i++) {
if (typeVar == genericDecl.getTypeParameter(i)) {
return false;
}
}
}
return true;
}
/** @apilevel internal */
private void moreSpecificThan_TypeDecl_TypeDecl_reset() {
moreSpecificThan_TypeDecl_TypeDecl_computed = null;
moreSpecificThan_TypeDecl_TypeDecl_values = null;
}
/** @apilevel internal */
protected java.util.Map moreSpecificThan_TypeDecl_TypeDecl_values;
/** @apilevel internal */
protected java.util.Map moreSpecificThan_TypeDecl_TypeDecl_computed;
/**
* Computes which type is more specific for a specific argument, as defined in 15.12.2.5
* @param type1
* @param type2
* @return {@code true} if type1 is more specific than type2, {@code false} otherwise
* @attribute syn
* @aspect MethodSignature18
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:256
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodSignature18", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:256")
public boolean moreSpecificThan(TypeDecl type1, TypeDecl type2) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(type1);
_parameters.add(type2);
if (moreSpecificThan_TypeDecl_TypeDecl_computed == null) moreSpecificThan_TypeDecl_TypeDecl_computed = new java.util.HashMap(4);
if (moreSpecificThan_TypeDecl_TypeDecl_values == null) moreSpecificThan_TypeDecl_TypeDecl_values = new java.util.HashMap(4);
ASTState state = state();
if (moreSpecificThan_TypeDecl_TypeDecl_values.containsKey(_parameters)
&& moreSpecificThan_TypeDecl_TypeDecl_computed.containsKey(_parameters)
&& (moreSpecificThan_TypeDecl_TypeDecl_computed.get(_parameters) == ASTState.NON_CYCLE || moreSpecificThan_TypeDecl_TypeDecl_computed.get(_parameters) == state().cycle())) {
return (Boolean) moreSpecificThan_TypeDecl_TypeDecl_values.get(_parameters);
}
boolean moreSpecificThan_TypeDecl_TypeDecl_value = moreSpecificThan_compute(type1, type2);
if (state().inCircle()) {
moreSpecificThan_TypeDecl_TypeDecl_values.put(_parameters, moreSpecificThan_TypeDecl_TypeDecl_value);
moreSpecificThan_TypeDecl_TypeDecl_computed.put(_parameters, state().cycle());
} else {
moreSpecificThan_TypeDecl_TypeDecl_values.put(_parameters, moreSpecificThan_TypeDecl_TypeDecl_value);
moreSpecificThan_TypeDecl_TypeDecl_computed.put(_parameters, ASTState.NON_CYCLE);
}
return moreSpecificThan_TypeDecl_TypeDecl_value;
}
/** @apilevel internal */
private boolean moreSpecificThan_compute(TypeDecl type1, TypeDecl type2) {
if (super.moreSpecificThan(type1, type2)) {
return true;
}
if (!type1.isFunctionalInterface() || !type2.isFunctionalInterface()) {
return false;
}
if (type2.subtype(type1)) {
return false;
}
InterfaceDecl iDecl1 = (InterfaceDecl) type1;
InterfaceDecl iDecl2 = (InterfaceDecl) type2;
if (!isExact()) {
return false;
}
FunctionDescriptor fd1 = iDecl1.functionDescriptor();
FunctionDescriptor fd2 = iDecl2.functionDescriptor();
if (fd1.method.hasValue() && fd2.method.hasValue()) {
// Can only compare method types if both function descriptors have target methods.
MethodDecl method1 = fd1.method.get();
MethodDecl method2 = fd2.method.get();
TypeDecl methodType1 = method1.type();
TypeDecl methodType2 = method2.type();
if (method1.arity() != method2.arity()) {
return false;
}
for (int i = 0; i < method1.getNumParameter(); i++) {
if (method1.getParameter(i).type() != method2.getParameter(i).type()) {
return false;
}
}
// First bullet
if (methodType2.isVoid()) {
return true;
}
// Second bullet
if (methodType1.subtype(methodType2)) {
return true;
}
// Third bullet
if (methodType1.isPrimitiveType() && methodType2.isReferenceType()) {
// A constructor can never have primitive return type
return false;
}
// Fourth bullet
if (methodType1.isReferenceType() && methodType2.isPrimitiveType()) {
// A constructor always have reference return type
return true;
}
}
return false;
}
/** @apilevel internal */
private void potentiallyCompatible_TypeDecl_BodyDecl_reset() {
potentiallyCompatible_TypeDecl_BodyDecl_computed = null;
potentiallyCompatible_TypeDecl_BodyDecl_values = null;
}
/** @apilevel internal */
protected java.util.Map potentiallyCompatible_TypeDecl_BodyDecl_values;
/** @apilevel internal */
protected java.util.Map potentiallyCompatible_TypeDecl_BodyDecl_computed;
/**
* @attribute syn
* @aspect MethodSignature18
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:511
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodSignature18", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:511")
public boolean potentiallyCompatible(TypeDecl type, BodyDecl candidateDecl) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(type);
_parameters.add(candidateDecl);
if (potentiallyCompatible_TypeDecl_BodyDecl_computed == null) potentiallyCompatible_TypeDecl_BodyDecl_computed = new java.util.HashMap(4);
if (potentiallyCompatible_TypeDecl_BodyDecl_values == null) potentiallyCompatible_TypeDecl_BodyDecl_values = new java.util.HashMap(4);
ASTState state = state();
if (potentiallyCompatible_TypeDecl_BodyDecl_values.containsKey(_parameters)
&& potentiallyCompatible_TypeDecl_BodyDecl_computed.containsKey(_parameters)
&& (potentiallyCompatible_TypeDecl_BodyDecl_computed.get(_parameters) == ASTState.NON_CYCLE || potentiallyCompatible_TypeDecl_BodyDecl_computed.get(_parameters) == state().cycle())) {
return (Boolean) potentiallyCompatible_TypeDecl_BodyDecl_values.get(_parameters);
}
boolean potentiallyCompatible_TypeDecl_BodyDecl_value = potentiallyCompatible_compute(type, candidateDecl);
if (state().inCircle()) {
potentiallyCompatible_TypeDecl_BodyDecl_values.put(_parameters, potentiallyCompatible_TypeDecl_BodyDecl_value);
potentiallyCompatible_TypeDecl_BodyDecl_computed.put(_parameters, state().cycle());
} else {
potentiallyCompatible_TypeDecl_BodyDecl_values.put(_parameters, potentiallyCompatible_TypeDecl_BodyDecl_value);
potentiallyCompatible_TypeDecl_BodyDecl_computed.put(_parameters, ASTState.NON_CYCLE);
}
return potentiallyCompatible_TypeDecl_BodyDecl_value;
}
/** @apilevel internal */
private boolean potentiallyCompatible_compute(TypeDecl type, BodyDecl candidateDecl) {
if (type.isTypeVariable()) {
if (candidateDecl.isGeneric()) {
boolean foundTypeVariable = false;
List typeParams = candidateDecl.typeParameters();
for (int i = 0; i < typeParams.getNumChild(); i++) {
if (type == typeParams.getChild(i)) {
foundTypeVariable = true;
break;
}
}
return foundTypeVariable;
} else {
return false;
}
}
if (!type.isFunctionalInterface()) {
return false;
}
return true;
}
/** @apilevel internal */
protected ASTState.Cycle type_cycle = null;
/** @apilevel internal */
private void type_reset() {
type_computed = false;
type_initialized = false;
type_value = null;
type_cycle = null;
}
/** @apilevel internal */
protected boolean type_computed = false;
/** @apilevel internal */
protected TypeDecl type_value;
/** @apilevel internal */
protected boolean type_initialized = false;
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:102")
public TypeDecl type() {
if (type_computed) {
return type_value;
}
ASTState state = state();
if (!type_initialized) {
type_initialized = true;
type_value = unknownType();
}
if (!state.inCircle() || state.calledByLazyAttribute()) {
state.enterCircle();
do {
type_cycle = state.nextCycle();
TypeDecl new_type_value = type_compute();
if (!AttributeValue.equals(type_value, new_type_value)) {
state.setChangeInCycle();
}
type_value = new_type_value;
} while (state.testAndClearChangeInCycle());
type_computed = true;
state.leaveCircle();
} else if (type_cycle != state.cycle()) {
type_cycle = state.cycle();
TypeDecl new_type_value = type_compute();
if (!AttributeValue.equals(type_value, new_type_value)) {
state.setChangeInCycle();
}
type_value = new_type_value;
} else {
}
return type_value;
}
/** @apilevel internal */
private TypeDecl type_compute() {
// 15.13.1
if (!assignmentContext() && !castContext() && !invocationContext()) {
return unknownType();
}
if (targetInterface() == null) {
return unknownType();
}
InterfaceDecl iDecl = targetInterface();
if (!iDecl.isFunctional()) {
return unknownType();
}
return iDecl;
}
/**
* @attribute syn
* @aspect TypeCheck
* @declaredat /home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:393
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:393")
public Collection typeProblems() {
{
Collection problems = new LinkedList();
if (!assignmentContext() && !castContext() && !invocationContext()) {
problems.add(error("Constructor references must target a functional interface"));
return problems;
}
// This means there was an error in the overload resolution, will be reported elsewhere
if (invocationContext() && targetType() == unknownType()) {
return problems;
}
if (!targetType().isFunctionalInterface()) {
problems.add(error("Constructor references must target a functional interface"));
return problems;
}
InterfaceDecl iDecl = targetInterface();
if (!iDecl.isFunctional()) {
problems.add(errorf("Interface %s is not functional and can therefore not be targeted by a constructor reference",
iDecl.typeName()));
return problems;
}
FunctionDescriptor fd = iDecl.functionDescriptor();
if (!fd.method.hasValue()) {
problems.add(errorf(
"Found no matching method in the interface %s for this constructor reference.",
iDecl.typeName()));
} else {
MethodDecl targetMethod = fd.method.get();
if (this instanceof ClassReference) {
ClassReference ref = (ClassReference) this;
ConstructorDecl decl = ref.targetConstructor(fd);
if (unknownConstructor() == decl) {
problems.add(errorf("Found no constructor for the type %s that is compatible with "
+ "the method %s in interface %s",
getTypeAccess().type().typeName(), targetMethod.fullSignature(), iDecl.typeName()));
}
if (!targetMethod.type().isVoid()) {
// 15.13.1
TypeDecl returnType = ref.syntheticInstanceExpr(fd).type();
if (!returnType.assignConversionTo(targetMethod.type(), null)) {
problems.add(errorf("Return type of method %s in interface %s is not compatible with"
+ " referenced constructor which has return type: %s",
targetMethod.fullSignature(), iDecl.typeName(), returnType.typeName()));
}
}
for (int i = 0; i < decl.getNumException(); i++) {
TypeDecl exception = decl.getException(i).type();
if (exception.isUncheckedException()) {
continue;
}
boolean legalException = false;
for (TypeDecl descriptorThrows : iDecl.functionDescriptor().throwsList) {
if (exception.strictSubtype(descriptorThrows)) {
legalException = true;
break;
}
}
if (!legalException) {
// 15.13.1
problems.add(errorf("Referenced constructor %s throws unhandled exception type %s",
decl.name(), exception.typeName()));
}
}
problems.addAll(ref.syntheticInstanceExpr(fd).typeProblems());
} else {
ArrayReference ref = (ArrayReference) this;
if (targetMethod.getNumParameter() != 1) {
problems.add(errorf("Array reference not compatible with method %s in interface %s,"
+ " should have a single parameter of type int",
targetMethod.fullSignature(), iDecl.typeName()));
return problems;
}
if (!targetMethod.paramType(0).assignConversionTo(iDecl.typeInt(), null)) {
problems.add(errorf("Array reference not compatible with method %s in interface %s,"
+ " should have a single parameter of type int",
targetMethod.fullSignature(), iDecl.typeName()));
return problems;
}
if (!targetMethod.type().isVoid()) {
if (!getTypeAccess().type().assignConversionTo(targetMethod.type(), null)) {
problems.add(errorf("Return type %s of method %s in interface %s is not compatible with"
+ " the array reference type %s",
targetMethod.type().typeName(), targetMethod.fullSignature(), iDecl.typeName(),
getTypeAccess().type().typeName()));
}
}
}
}
return problems;
}
}
/** @apilevel internal */
private void toClass_reset() {
toClass_computed = false;
toClass_value = null;
}
/** @apilevel internal */
protected boolean toClass_computed = false;
/** @apilevel internal */
protected ClassInstanceExpr toClass_value;
/** Build an anonymous inner class for bytecode generation.
* @attribute syn
* @aspect ConstructorReferenceToClass
* @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:58
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isNTA=true)
@ASTNodeAnnotation.Source(aspect="ConstructorReferenceToClass", declaredAt="/home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:58")
public ClassInstanceExpr toClass() {
ASTState state = state();
if (toClass_computed) {
return toClass_value;
}
state().enterLazyAttribute();
toClass_value = toClass_compute();
toClass_value.setParent(this);
toClass_computed = true;
state().leaveLazyAttribute();
return toClass_value;
}
/** @apilevel internal */
private ClassInstanceExpr toClass_compute() {
List implementsList = new List();
InterfaceDecl iDecl = targetInterface();
// First compute the interface implemented by the anonymous class.
TypeDecl nonWildcard = targetInterface().nonWildcardParameterization().getOrElse(unknownType());
implementsList.add(nonWildcard.createQualifiedAccess());
// Next, compute the BodyDecls for the anonymous class.
List bodyDecls = new List();
// Which means we must build the method overriding the abstract methods.
Modifiers methodModifiers = new Modifiers(new List().add(new Modifier("public")));
MethodDecl targetMethod = iDecl.functionDescriptor().method.get();
Access returnType = new SyntheticTypeAccess(targetMethod.type());
List methodParams = toParameterList();
List methodThrows = new List();
for (TypeDecl throwsType : iDecl.functionDescriptor().throwsList) {
methodThrows.add(new SyntheticTypeAccess(throwsType));
}
Opt methodBlock = new Opt(toBlock());
MethodDecl method = new MethodDecl(methodModifiers, returnType,
targetMethod.name(),
methodParams, methodThrows, methodBlock);
bodyDecls.add(method);
// Now the anonymous class can be built. We use the type
// LambdaAnonymousDecl instead of a normal AnonymousDecl in order for this
// and super keywords to get the type of the outer scope.
LambdaAnonymousDecl anonymousDecl = new LambdaAnonymousDecl(new Modifiers(),
"ConstructorReference", implementsList, bodyDecls);
return new ClassInstanceExpr(
iDecl.createQualifiedAccess(),
new List(),
new Opt(anonymousDecl));
}
/** @apilevel internal */
private void toParameterList_reset() {
toParameterList_computed = null;
toParameterList_value = null;
}
/** @apilevel internal */
protected ASTState.Cycle toParameterList_computed = null;
/** @apilevel internal */
protected List toParameterList_value;
/**
* @attribute syn
* @aspect ConstructorReferenceToClass
* @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:99
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="ConstructorReferenceToClass", declaredAt="/home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:99")
public List toParameterList() {
ASTState state = state();
if (toParameterList_computed == ASTState.NON_CYCLE || toParameterList_computed == state().cycle()) {
return toParameterList_value;
}
toParameterList_value = toParameterList_compute();
if (state().inCircle()) {
toParameterList_computed = state().cycle();
} else {
toParameterList_computed = ASTState.NON_CYCLE;
}
return toParameterList_value;
}
/** @apilevel internal */
private List toParameterList_compute() {
List list = new List();
MethodDecl targetMethod = targetInterface().functionDescriptor().method.get();
for (int i = 0; i < targetMethod.getNumParameter(); i++) {
TypeDecl paramType = targetMethod.getParameter(i).type();
String paramName = targetMethod.getParameter(i).name();
list.add(new ParameterDeclaration(new SyntheticTypeAccess(paramType), paramName));
}
return list;
}
/**
* @attribute inh
* @aspect ConstructorReference
* @declaredat /home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:30
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="ConstructorReference", declaredAt="/home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:30")
public ConstructorDecl unknownConstructor() {
ConstructorDecl unknownConstructor_value = getParent().Define_unknownConstructor(this, null);
return unknownConstructor_value;
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:235
* @apilevel internal
*/
public boolean Define_assignmentContext(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:404
return false;
}
else {
return getParent().Define_assignmentContext(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:235
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute assignmentContext
*/
protected boolean canDefine_assignmentContext(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:236
* @apilevel internal
*/
public boolean Define_invocationContext(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:405
return false;
}
else {
return getParent().Define_invocationContext(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:236
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute invocationContext
*/
protected boolean canDefine_invocationContext(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:237
* @apilevel internal
*/
public boolean Define_castContext(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:406
return false;
}
else {
return getParent().Define_castContext(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:237
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute castContext
*/
protected boolean canDefine_castContext(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:238
* @apilevel internal
*/
public boolean Define_stringContext(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:407
return false;
}
else {
return getParent().Define_stringContext(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:238
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute stringContext
*/
protected boolean canDefine_stringContext(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:239
* @apilevel internal
*/
public boolean Define_numericContext(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:408
return false;
}
else {
return getParent().Define_numericContext(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:239
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute numericContext
*/
protected boolean canDefine_numericContext(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
* @apilevel internal
*/
public NameType Define_nameType(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:70
return NameType.TYPE_NAME;
}
else {
return getParent().Define_nameType(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute nameType
*/
protected boolean canDefine_nameType(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/** @apilevel internal */
public ASTNode rewriteTo() {
return super.rewriteTo();
}
/** @apilevel internal */
public boolean canRewrite() {
return false;
}
/** @apilevel internal */
protected void collect_contributors_CompilationUnit_problems(CompilationUnit _root, java.util.Map> _map) {
// @declaredat /home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:390
{
java.util.Set contributors = _map.get(_root);
if (contributors == null) {
contributors = new java.util.LinkedHashSet();
_map.put((ASTNode) _root, contributors);
}
contributors.add(this);
}
super.collect_contributors_CompilationUnit_problems(_root, _map);
}
/** @apilevel internal */
protected void collect_contributors_TypeDecl_nestedTypes(CompilationUnit _root, java.util.Map> _map) {
// @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:30
{
TypeDecl target = (TypeDecl) (hostType());
java.util.Set contributors = _map.get(target);
if (contributors == null) {
contributors = new java.util.LinkedHashSet();
_map.put((ASTNode) target, contributors);
}
contributors.add(this);
}
super.collect_contributors_TypeDecl_nestedTypes(_root, _map);
}
/** @apilevel internal */
protected void collect_contributors_TypeDecl_accessors(CompilationUnit _root, java.util.Map> _map) {
toClass().collect_contributors_TypeDecl_accessors(_root, _map);
super.collect_contributors_TypeDecl_accessors(_root, _map);
}
/** @apilevel internal */
protected void contributeTo_CompilationUnit_problems(LinkedList collection) {
super.contributeTo_CompilationUnit_problems(collection);
for (Problem value : typeProblems()) {
collection.add(value);
}
}
/** @apilevel internal */
protected void contributeTo_TypeDecl_nestedTypes(LinkedList collection) {
super.contributeTo_TypeDecl_nestedTypes(collection);
collection.add(toClass().getTypeDecl());
}
}