org.extendj.ast.MethodReference 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/MethodReference.ast:1
* @astdecl MethodReference : Expr ::= TypeArgument:Access* ;
* @production MethodReference : {@link Expr} ::= TypeArgument:{@link Access}* <ID:String>;
*/
public abstract class MethodReference extends Expr implements Cloneable {
/**
* @aspect PrettyPrintUtil8
* @declaredat /home/jesper/git/extendj/java8/frontend/PrettyPrintUtil.jadd:98
*/
@Override public String toString() {
StringBuilder params = new StringBuilder();
for (Access arg : getTypeArgumentListNoTransform()) {
if (params.length() > 0) {
params.append(", ");
}
params.append(arg.toString());
}
if (params.length() == 0) {
return "::" + getID();
} else {
return String.format("::<%s>%s", params.toString(), getID());
}
}
/**
* @declaredat ASTNode:1
*/
public MethodReference() {
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];
setChild(new List(), 0);
}
/**
* @declaredat ASTNode:14
*/
@ASTNodeAnnotation.Constructor(
name = {"TypeArgument", "ID"},
type = {"List", "String"},
kind = {"List", "Token"}
)
public MethodReference(List p0, String p1) {
setChild(p0, 0);
setID(p1);
}
/**
* @declaredat ASTNode:23
*/
public MethodReference(List p0, beaver.Symbol p1) {
setChild(p0, 0);
setID(p1);
}
/** @apilevel low-level
* @declaredat ASTNode:28
*/
protected int numChildren() {
return 1;
}
/**
* @apilevel internal
* @declaredat ASTNode:34
*/
public boolean mayHaveRewrite() {
return false;
}
/** @apilevel internal
* @declaredat ASTNode:38
*/
public void flushAttrCache() {
super.flushAttrCache();
isPolyExpression_reset();
assignConversionTo_TypeDecl_reset();
targetInterface_reset();
isExact_reset();
compatibleStrictContext_TypeDecl_reset();
compatibleLooseContext_TypeDecl_reset();
pertinentToApplicability_Expr_BodyDecl_int_reset();
moreSpecificThan_TypeDecl_TypeDecl_reset();
potentiallyCompatible_TypeDecl_BodyDecl_reset();
type_reset();
toParameterList_reset();
}
/** @apilevel internal
* @declaredat ASTNode:53
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:57
*/
public MethodReference clone() throws CloneNotSupportedException {
MethodReference node = (MethodReference) 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:68
*/
@Deprecated
public abstract MethodReference 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:76
*/
public abstract MethodReference 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:84
*/
public abstract MethodReference treeCopy();
/**
* Replaces the TypeArgument list.
* @param list The new list node to be used as the TypeArgument list.
* @apilevel high-level
*/
public void setTypeArgumentList(List list) {
setChild(list, 0);
}
/**
* Retrieves the number of children in the TypeArgument list.
* @return Number of children in the TypeArgument list.
* @apilevel high-level
*/
public int getNumTypeArgument() {
return getTypeArgumentList().getNumChild();
}
/**
* Retrieves the number of children in the TypeArgument list.
* Calling this method will not trigger rewrites.
* @return Number of children in the TypeArgument list.
* @apilevel low-level
*/
public int getNumTypeArgumentNoTransform() {
return getTypeArgumentListNoTransform().getNumChildNoTransform();
}
/**
* Retrieves the element at index {@code i} in the TypeArgument list.
* @param i Index of the element to return.
* @return The element at position {@code i} in the TypeArgument list.
* @apilevel high-level
*/
public Access getTypeArgument(int i) {
return (Access) getTypeArgumentList().getChild(i);
}
/**
* Check whether the TypeArgument list has any children.
* @return {@code true} if it has at least one child, {@code false} otherwise.
* @apilevel high-level
*/
public boolean hasTypeArgument() {
return getTypeArgumentList().getNumChild() != 0;
}
/**
* Append an element to the TypeArgument list.
* @param node The element to append to the TypeArgument list.
* @apilevel high-level
*/
public void addTypeArgument(Access node) {
List list = (parent == null) ? getTypeArgumentListNoTransform() : getTypeArgumentList();
list.addChild(node);
}
/** @apilevel low-level
*/
public void addTypeArgumentNoTransform(Access node) {
List list = getTypeArgumentListNoTransform();
list.addChild(node);
}
/**
* Replaces the TypeArgument list element at index {@code i} with the new node {@code node}.
* @param node The new node to replace the old list element.
* @param i The list index of the node to be replaced.
* @apilevel high-level
*/
public void setTypeArgument(Access node, int i) {
List list = getTypeArgumentList();
list.setChild(node, i);
}
/**
* Retrieves the TypeArgument list.
* @return The node representing the TypeArgument list.
* @apilevel high-level
*/
@ASTNodeAnnotation.ListChild(name="TypeArgument")
public List getTypeArgumentList() {
List list = (List) getChild(0);
return list;
}
/**
* Retrieves the TypeArgument list.
* This method does not invoke AST transformations.
* @return The node representing the TypeArgument list.
* @apilevel low-level
*/
public List getTypeArgumentListNoTransform() {
return (List) getChildNoTransform(0);
}
/**
* @return the element at index {@code i} in the TypeArgument list without
* triggering rewrites.
*/
public Access getTypeArgumentNoTransform(int i) {
return (Access) getTypeArgumentListNoTransform().getChildNoTransform(i);
}
/**
* Retrieves the TypeArgument list.
* @return The node representing the TypeArgument list.
* @apilevel high-level
*/
public List getTypeArguments() {
return getTypeArgumentList();
}
/**
* Retrieves the TypeArgument list.
* This method does not invoke AST transformations.
* @return The node representing the TypeArgument list.
* @apilevel low-level
*/
public List getTypeArgumentsNoTransform() {
return getTypeArgumentListNoTransform();
}
/**
* Replaces the lexeme ID.
* @param value The new value for the lexeme ID.
* @apilevel high-level
*/
public void setID(String value) {
tokenString_ID = value;
}
/** @apilevel internal
*/
protected String tokenString_ID;
/**
*/
public int IDstart;
/**
*/
public int IDend;
/**
* JastAdd-internal setter for lexeme ID using the Beaver parser.
* @param symbol Symbol containing the new value for the lexeme ID
* @apilevel internal
*/
public void setID(beaver.Symbol symbol) {
if (symbol.value != null && !(symbol.value instanceof String))
throw new UnsupportedOperationException("setID is only valid for String lexemes");
tokenString_ID = (String)symbol.value;
IDstart = symbol.getStart();
IDend = symbol.getEnd();
}
/**
* Retrieves the value for the lexeme ID.
* @return The value for the lexeme ID.
* @apilevel high-level
*/
@ASTNodeAnnotation.Token(name="ID")
public String getID() {
return tokenString_ID != null ? tokenString_ID : "";
}
/**
* @attribute syn
* @aspect MethodReference
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:239
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodReference", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodReference.jrag:239")
public abstract boolean congruentTo(FunctionDescriptor fd);
/**
* @attribute syn
* @aspect MethodReference
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:292
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodReference", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodReference.jrag:292")
public abstract java.util.List potentiallyApplicableMethods(FunctionDescriptor fd);
/**
* @attribute syn
* @aspect MethodReference
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:360
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodReference", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodReference.jrag:360")
public abstract MethodDecl exactCompileTimeDeclaration();
/** @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);
}
/**
* @attribute syn
* @aspect Names
* @declaredat /home/jesper/git/extendj/java8/frontend/QualifiedNames.jrag:30
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="Names", declaredAt="/home/jesper/git/extendj/java8/frontend/QualifiedNames.jrag:30")
public String name() {
String name_value = getID();
return name_value;
}
/** @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:158
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TargetType", declaredAt="/home/jesper/git/extendj/java8/frontend/TargetType.jrag:158")
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 isExact_reset() {
isExact_computed = null;
}
/** @apilevel internal */
protected ASTState.Cycle isExact_computed = null;
/** @apilevel internal */
protected boolean isExact_value;
/**
* @attribute syn
* @aspect MethodReference
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:359
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodReference", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodReference.jrag:359")
public boolean isExact() {
ASTState state = state();
if (isExact_computed == ASTState.NON_CYCLE || isExact_computed == state().cycle()) {
return isExact_value;
}
isExact_value = exactCompileTimeDeclaration() != unknownMethod();
if (state().inCircle()) {
isExact_computed = state().cycle();
} else {
isExact_computed = ASTState.NON_CYCLE;
}
return isExact_value;
}
/**
* @attribute syn
* @aspect Java8NameCheck
* @declaredat /home/jesper/git/extendj/java8/frontend/NameCheck.jrag:505
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="Java8NameCheck", declaredAt="/home/jesper/git/extendj/java8/frontend/NameCheck.jrag:505")
public Collection nameProblems() {
{
for (int i = 0; i < getNumTypeArgument(); i++) {
if (getTypeArgument(i) instanceof AbstractWildcard) {
return Collections.singletonList(
error("Wildcard not allowed in method reference type argument lists"));
}
}
return Collections.emptyList();
}
}
/** @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()) {
return exactCompileTimeDeclaration().type().isPrimitiveType();
}
// Fourth bullet
if (methodType1.isReferenceType() && methodType2.isPrimitiveType()) {
return exactCompileTimeDeclaration().type().isReferenceType();
}
}
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:81")
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();
}
if (congruentTo(iDecl.functionDescriptor())) {
return iDecl;
} else {
return unknownType();
}
}
/**
* @attribute syn
* @aspect TypeCheck
* @declaredat /home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:250
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:250")
public Collection typeProblems() {
{
Collection problems = new LinkedList();
// 15.13.1
if (!assignmentContext() && !castContext() && !invocationContext()) {
problems.add(error("Method 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 Collections.emptyList();
}
if (!targetType().isFunctionalInterface()) {
problems.add(error("Method 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 method 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 method reference.",
iDecl.typeName()));
} else {
MethodDecl targetMethod = fd.method.get();
MethodDecl found = null;
// Lookup method here and check that one most specific can be found
if (this instanceof ExprMethodReference) {
ExprMethodReference ref = (ExprMethodReference) this;
found = ref.targetMethod(fd);
if (unknownMethod() == found) {
// 15.13.1
problems.add(errorf("Found no method %s that is compatible with the method %s in the interface %s",
name(), targetMethod.fullSignature(), iDecl.typeName()));
} else if (found.isStatic()) {
problems.add(errorf("The method %s in type %s must be accessed in a static way",
found.fullSignature(), found.hostType().typeName()));
} else if (ref.getExpr() instanceof Access && ((Access) ref.getExpr()).lastAccess() instanceof SuperAccess) {
// 15.13.2
if (found.isAbstract()) {
problems.add(errorf("Cannot directly invoke the abstract method %s in type %s",
found.fullSignature(), found.hostType().typeName()));
}
SuperAccess superAccess = (SuperAccess)((Access) ref.getExpr()).lastAccess();
if (superAccess.isQualified() && superAccess.decl() instanceof InterfaceDecl) {
if (hostType().isClassDecl()) {
ClassDecl classDecl = (ClassDecl) hostType();
if (classDecl.hasOverridingMethodInSuper(found)) {
problems.add(errorf(
"Cannot make a super reference to method %s, there is a more specific override",
found.fullSignature()));
}
} else if (hostType().isInterfaceDecl()) {
InterfaceDecl interfaceDecl = (InterfaceDecl) hostType();
if (interfaceDecl.hasOverridingMethodInSuper(found)) {
problems.add(errorf(
"Cannot make a super reference to method %s, there is a more specific override",
found.fullSignature()));
}
}
}
}
} else if (this instanceof TypeMethodReference) {
TypeMethodReference ref = (TypeMethodReference) this;
MethodDecl staticMethod = ref.targetStaticMethod(fd);
MethodDecl instanceMethod = ref.targetInstanceMethod(fd);
if (ref.validStaticMethod(fd) && ref.validInstanceMethod(fd)) {
problems.add(errorf("Ambiguity error: two possible methods %s was found",
staticMethod.name()));
return problems;
} else if (unknownMethod() == staticMethod && unknownMethod() == instanceMethod) {
problems.add(errorf(
"Found no method %s that is compatible with the method %s in the interface %s",
name(), targetMethod.fullSignature(), iDecl.typeName()));
return problems;
} else if (ref.validStaticMethod(fd)) {
if (ref.getTypeAccess() instanceof ParTypeAccess) {
problems.add(
error("Parameterized qualifier is not allowed for static method references"));
} else {
found = staticMethod;
}
} else if (ref.validInstanceMethod(fd)) {
found = instanceMethod;
} else if (unknownMethod() != staticMethod && !staticMethod.isStatic()) {
problems.add(errorf("Cannot make a static reference to the non-static method %s in type %s",
staticMethod.fullSignature(), staticMethod.hostType().typeName()));
return problems;
} else if (instanceMethod.isStatic()) {
problems.add(errorf("The method %s in type %s must be accessed in a static way",
instanceMethod.fullSignature(), instanceMethod.hostType().typeName()));
return problems;
}
}
if (found != null && unknownMethod() != found) {
// Check that found is compatible with the function descriptor
if (!targetMethod.type().isVoid()) {
// 15.13.1
if (found.type().isVoid()
|| !found.type().assignConversionTo(targetMethod.type(), null)) {
problems.add(errorf("Return type of referenced method %s is not compatible with method %s in interface %s",
found.fullSignature(), targetMethod.fullSignature(),
iDecl.typeName()));
}
}
for (int i = 0; i < found.getNumException(); i++) {
TypeDecl exception = found.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 method %s throws unhandled exception type %s",
found.name(), exception.typeName()));
}
}
}
}
return problems;
}
}
/** @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 MethodReferenceToClass
* @declaredat /home/jesper/git/extendj/java8/backend/MethodReferenceToClass.jrag:102
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="MethodReferenceToClass", declaredAt="/home/jesper/git/extendj/java8/backend/MethodReferenceToClass.jrag:102")
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 MethodReference
* @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:31
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="MethodReference", declaredAt="/home/jesper/git/extendj/java8/frontend/MethodReference.jrag:31")
public MethodDecl unknownMethod() {
MethodDecl unknownMethod_value = getParent().Define_unknownMethod(this, null);
return unknownMethod_value;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
* @apilevel internal
*/
public NameType Define_nameType(ASTNode _callerNode, ASTNode _childNode) {
if (_callerNode == getTypeArgumentListNoTransform()) {
// @declaredat /home/jesper/git/extendj/java8/frontend/MethodReference.jrag:215
int childIndex = _callerNode.getIndexOfChild(_childNode);
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/NameCheck.jrag:503
{
java.util.Set contributors = _map.get(_root);
if (contributors == null) {
contributors = new java.util.LinkedHashSet();
_map.put((ASTNode) _root, contributors);
}
contributors.add(this);
}
// @declaredat /home/jesper/git/extendj/java8/frontend/TypeCheck.jrag:248
{
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 contributeTo_CompilationUnit_problems(LinkedList collection) {
super.contributeTo_CompilationUnit_problems(collection);
for (Problem value : nameProblems()) {
collection.add(value);
}
for (Problem value : typeProblems()) {
collection.add(value);
}
}
}