All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.extendj.ast.MethodAccess Maven / Gradle / Ivy

There is a newer version: 8.1.2
Show newest version
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.0 */
package org.extendj.ast;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
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.*;
import java.util.zip.*;
import java.io.*;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import org.jastadd.util.*;
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.io.BufferedInputStream;
import java.io.DataInputStream;
/** A method invocation. 
 * @ast node
 * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:84
 * @astdecl MethodAccess : Access ::=  Arg:Expr*;
 * @production MethodAccess : {@link Access} ::= <ID:String> Arg:{@link Expr}*;

 */
public class MethodAccess extends Access implements Cloneable {
  /**
   * @aspect Java4PrettyPrint
   * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:460
   */
  public void prettyPrint(PrettyPrinter out) {
    out.print(getID());
    out.print("(");
    out.join(getArgList(), new PrettyPrinter.Joiner() {
      @Override
      public void printSeparator(PrettyPrinter out) {
        out.print(", ");
      }
    });
    out.print(")");
  }
  /**
   * @aspect NodeConstructors
   * @declaredat /home/jesper/git/extendj/java4/frontend/NodeConstructors.jrag:70
   */
  public MethodAccess(String name, List args, int start, int end) {
    this(name, args);
    setStart(start);
    setEnd(end);
  }
  /**
   * @aspect PrettyPrintUtil
   * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:68
   */
  @Override public String toString() {
    return name() + "()";
  }
  /**
   * @aspect ExceptionHandling
   * @declaredat /home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:335
   */
  protected boolean reachedException(TypeDecl catchType) {
    for (TypeDecl exceptionType : exceptionCollection()) {
      if (catchType.mayCatch(exceptionType)) {
        return true;
      }
    }
    return super.reachedException(catchType);
  }
  /**
   * @aspect AnonymousClasses
   * @declaredat /home/jesper/git/extendj/java4/frontend/AnonymousClasses.jrag:142
   */
  protected void collectExceptions(Collection exceptions) {
    super.collectExceptions(exceptions);
    for (int i = 0; i < decl().getNumException(); i++) {
      exceptions.add(decl().getException(i).type());
    }
  }
  /**
   * Filter a set of methods, keeping only the static methods
   * from the input set.
   * @aspect LookupMethod
   * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:285
   */
  protected static SimpleSet keepStaticMethods(
      SimpleSet methods) {
    SimpleSet result = emptySet();
    for (MethodDecl method : methods) {
      if (method.isStatic()) {
        result = result.add(method);
      }
    }
    return result;
  }
  /**
   * Determine if a candidate method declaration is applicable
   * for this invocation.
   * @aspect MethodDecl
   * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:391
   */
  public boolean applicable(MethodDecl decl) {
    if (getNumArg() != decl.getNumParameter()) {
      return false;
    }
    if (!name().equals(decl.name())) {
      return false;
    }
    for (int i = 0; i < getNumArg(); i++) {
      if (!getArg(i).type().instanceOf(decl.paramType(i))) {
        return false;
      }
    }
    return true;
  }
  /**
   * @aspect MethodSignature15
   * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:65
   */
  protected SimpleSet potentiallyApplicable(
      Collection candidates) {
    SimpleSet potentiallyApplicable = emptySet();
    // Select potentially applicable methods.
    for (MethodDecl method : candidates) {
      if (potentiallyApplicable(method) && accessible(method)) {
        if (method.isGeneric()) {
          GenericMethodDecl gm = method.genericDecl();
          Collection typeArguments = inferTypeArguments(
              method.type(),
              method.getParameterList(),
              getArgList(),
              gm.getTypeParameterList());
          method = gm.lookupParMethodDecl(typeArguments);
        }
        potentiallyApplicable = potentiallyApplicable.add(method);
      }
    }
    return potentiallyApplicable;
  }
  /**
   * @aspect MethodSignature15
   * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:175
   */
  private static SimpleSet mostSpecific(
      SimpleSet maxSpecific, MethodDecl decl) {
    if (maxSpecific.isEmpty()) {
      maxSpecific = maxSpecific.add(decl);
    } else {
      MethodDecl other = maxSpecific.iterator().next();
      if (decl.moreSpecificThan(other)) {
        maxSpecific = decl;
      } else if (!other.moreSpecificThan(decl)) {
        maxSpecific = maxSpecific.add(decl);
      }
    }
    return maxSpecific;
  }
  /**
   * Prints diagnostic error messages for debugging method binding errors.
   * @aspect CreateBCode
   * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:664
   */
  public void printDiagnosticMessages() {
    if (decl().type().isUnknown()) {
      System.err.format("Could not bind %s()%n", name());
      for (Expr arg : getArgList()) {
        System.err.format("Argument %d is of type %s%n",
            arg,
            arg.type().typeName());
        if (arg.varDecl() != null) {
          System.err.format("%s in %s%n",
              arg.varDecl().name(),
              arg.varDecl().hostType().typeName());
        }
      }
      if (isQualified()) {
        System.err.format("Qualifier %s is of type %s%n",
            qualifier().prettyPrint(),
            qualifier().type().typeName());
      }
      throw new Error(String.format("Could not bind %s()", name()));
    }
    if (decl().getNumParameter() != getNumArg()) {
      System.out.format("%s() does not have the same number of arguments as %s()%n",
          name(), decl().name());
    }
  }
  /**
   * @aspect CreateBCode
   * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:716
   */
  protected void createLoadQualifier(CodeGeneration gen) {
    MethodDecl m = decl();
    if (hasPrevExpr()) {
      // Load explicit qualifier
      prevExpr().createBCode(gen);
      // Pop qualifier stack element for class variables.
      // This qualifier must be computed to ensure side effects are evaluated.
      if (m.isStatic() && !prevExpr().isTypeAccess()) {
        gen.POP(prevExpr().type());
      } else {
        prevExpr().emitCastTo(gen, methodQualifierType());
      }
    } else if (!m.isStatic()) {
      // Load implicit this qualifier.
      emitThis(gen, methodQualifierType());
    }
  }
  /**
   * @aspect InnerClasses
   * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:280
   */
  private boolean isSuperAccessor = false;
  /**
   * Flags this method access as a call that should be done with invokespecial.
   * @aspect InnerClasses
   * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:285
   */
  protected MethodAccess setSuperAccessor() {
    isSuperAccessor = true;
    return this;
  }
  /**
   * @declaredat ASTNode:1
   */
  public MethodAccess() {
    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 = {"ID", "Arg"},
    type = {"String", "List"},
    kind = {"Token", "List"}
  )
  public MethodAccess(String p0, List p1) {
    setID(p0);
    setChild(p1, 0);
  }
  /**
   * @declaredat ASTNode:23
   */
  public MethodAccess(beaver.Symbol p0, List p1) {
    setID(p0);
    setChild(p1, 0);
  }
  /** @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();
    type_reset();
    exceptionCollection_reset();
    decls_reset();
    decl_reset();
    computeDAbefore_int_Variable_reset();
    computeDUbefore_int_Variable_reset();
    unassignedAfter_Variable_reset();
    unassignedAfterTrue_Variable_reset();
    unassignedAfterFalse_Variable_reset();
    transformed_reset();
    transformedQualified_reset();
    transformedVariableArity_reset();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:54
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:58
   */
  public MethodAccess clone() throws CloneNotSupportedException {
    MethodAccess node = (MethodAccess) super.clone();
    return node;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:63
   */
  public MethodAccess copy() {
    try {
      MethodAccess node = (MethodAccess) clone();
      node.parent = null;
      if (children != null) {
        node.children = (ASTNode[]) children.clone();
      }
      return node;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " + getClass().getName());
    }
  }
  /**
   * 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:82
   */
  @Deprecated
  public MethodAccess fullCopy() {
    return treeCopyNoTransform();
  }
  /**
   * 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:92
   */
  public MethodAccess treeCopyNoTransform() {
    MethodAccess tree = (MethodAccess) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) children[i];
        if (child != null) {
          child = child.treeCopyNoTransform();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /**
   * 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:112
   */
  public MethodAccess treeCopy() {
    MethodAccess tree = (MethodAccess) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) getChild(i);
        if (child != null) {
          child = child.treeCopy();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:126
   */
  protected boolean is$Equal(ASTNode node) {
    return super.is$Equal(node) && (tokenString_ID == ((MethodAccess) node).tokenString_ID);    
  }
  /**
   * 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 : "";
  }
  /**
   * Replaces the Arg list.
   * @param list The new list node to be used as the Arg list.
   * @apilevel high-level
   */
  public void setArgList(List list) {
    setChild(list, 0);
  }
  /**
   * Retrieves the number of children in the Arg list.
   * @return Number of children in the Arg list.
   * @apilevel high-level
   */
  public int getNumArg() {
    return getArgList().getNumChild();
  }
  /**
   * Retrieves the number of children in the Arg list.
   * Calling this method will not trigger rewrites.
   * @return Number of children in the Arg list.
   * @apilevel low-level
   */
  public int getNumArgNoTransform() {
    return getArgListNoTransform().getNumChildNoTransform();
  }
  /**
   * Retrieves the element at index {@code i} in the Arg list.
   * @param i Index of the element to return.
   * @return The element at position {@code i} in the Arg list.
   * @apilevel high-level
   */
  public Expr getArg(int i) {
    return (Expr) getArgList().getChild(i);
  }
  /**
   * Check whether the Arg list has any children.
   * @return {@code true} if it has at least one child, {@code false} otherwise.
   * @apilevel high-level
   */
  public boolean hasArg() {
    return getArgList().getNumChild() != 0;
  }
  /**
   * Append an element to the Arg list.
   * @param node The element to append to the Arg list.
   * @apilevel high-level
   */
  public void addArg(Expr node) {
    List list = (parent == null) ? getArgListNoTransform() : getArgList();
    list.addChild(node);
  }
  /** @apilevel low-level 
   */
  public void addArgNoTransform(Expr node) {
    List list = getArgListNoTransform();
    list.addChild(node);
  }
  /**
   * Replaces the Arg 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 setArg(Expr node, int i) {
    List list = getArgList();
    list.setChild(node, i);
  }
  /**
   * Retrieves the Arg list.
   * @return The node representing the Arg list.
   * @apilevel high-level
   */
  @ASTNodeAnnotation.ListChild(name="Arg")
  public List getArgList() {
    List list = (List) getChild(0);
    return list;
  }
  /**
   * Retrieves the Arg list.
   * 

This method does not invoke AST transformations.

* @return The node representing the Arg list. * @apilevel low-level */ public List getArgListNoTransform() { return (List) getChildNoTransform(0); } /** * @return the element at index {@code i} in the Arg list without * triggering rewrites. */ public Expr getArgNoTransform(int i) { return (Expr) getArgListNoTransform().getChildNoTransform(i); } /** * Retrieves the Arg list. * @return The node representing the Arg list. * @apilevel high-level */ public List getArgs() { return getArgList(); } /** * Retrieves the Arg list. *

This method does not invoke AST transformations.

* @return The node representing the Arg list. * @apilevel low-level */ public List getArgsNoTransform() { return getArgListNoTransform(); } /** * @aspect MethodSignature15 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:33 */ protected SimpleSet maxSpecific(Collection candidates) { SimpleSet potentiallyApplicable = potentiallyApplicable(candidates); // First phase. SimpleSet maxSpecific = emptySet(); for (MethodDecl method : potentiallyApplicable) { if (applicableBySubtyping(method)) { maxSpecific = mostSpecific(maxSpecific, method); } } // Second phase. if (maxSpecific.isEmpty()) { for (MethodDecl method : potentiallyApplicable) { if (applicableByMethodInvocationConversion(method)) { maxSpecific = mostSpecific(maxSpecific, method); } } } // Third phase. if (maxSpecific.isEmpty()) { for (MethodDecl method : potentiallyApplicable) { if (method.isVariableArity() && applicableVariableArity(method)) { maxSpecific = mostSpecific(maxSpecific, method); } } } return maxSpecific; } /** * @aspect GenericsCodegen * @declaredat /home/jesper/git/extendj/java5/backend/GenericsCodegen.jrag:162 */ public void createBCode(CodeGeneration gen) { if (transformed() != this) { // Ensure bytecode is generated for the transformed access. transformed().createBCode(gen); return; } MethodDecl decl = decl().erasedMethod(); createLoadQualifier(gen); if (program().options().hasOption("-debug")) { printDiagnosticMessages(); } // Perform method invocation conversions. for (int i = 0; i < getNumArg(); ++i) { getArg(i).createBCode(gen); // The cast or boxing/unboxing operation must know the bound rather than the erased type. getArg(i).emitCastTo(gen, decl.paramType(i)); // Invocation conversion. } if (!decl.isStatic() && isQualified() && prevExpr().isSuperAccess() || isSuperAccessor) { decl.emitInvokeSpecialMethod(gen, methodQualifierType()); } else { decl.emitInvokeMethod(gen, methodQualifierType()); } } /** * @aspect TypeAnalysis * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:307 */ private TypeDecl refined_TypeAnalysis_MethodAccess_type() { return decl().type(); } /** * @aspect Transformations * @declaredat /home/jesper/git/extendj/java4/backend/Transformations.jrag:33 */ private Access refined_Transformations_MethodAccess_transformed() { if (requiresAccessor()) { return transformedQualified(); } else { return this; } } /** * @aspect InnerClasses * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:85 */ private TypeDecl refined_InnerClasses_MethodAccess_methodQualifierType() { if (hasPrevExpr()) { return prevExpr().type(); } TypeDecl typeDecl = hostType(); // Find closest type that has the target method. while (typeDecl != null) { if (typeDecl.hasMethod(decl())) { return typeDecl; } else { typeDecl = typeDecl.enclosingType(); } } return decl().hostType(); } /** * @attribute syn * @aspect AccessTypes * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:47 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="AccessTypes", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:47") public boolean isMethodAccess() { boolean isMethodAccess_value = true; return isMethodAccess_value; } /** * @attribute syn * @aspect NameCheck * @declaredat /home/jesper/git/extendj/java4/frontend/NameCheck.jrag:95 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="NameCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/NameCheck.jrag:95") public boolean validArgs() { { for (int i = 0; i < getNumArg(); i++) { if (getArg(i).type().isUnknown()) { return false; } } return true; } } /** @apilevel internal */ private void type_reset() { type_computed = null; type_value = null; } /** @apilevel internal */ protected ASTState.Cycle type_computed = null; /** @apilevel internal */ protected TypeDecl type_value; /** * @attribute syn * @aspect TypeAnalysis * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:296 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="TypeAnalysis", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:296") public TypeDecl type() { ASTState state = state(); if (type_computed == ASTState.NON_CYCLE || type_computed == state().cycle()) { return type_value; } type_value = type_compute(); if (state().inCircle()) { type_computed = state().cycle(); } else { type_computed = ASTState.NON_CYCLE; } return type_value; } /** @apilevel internal */ private TypeDecl type_compute() { if (getNumArg() == 0 && name().equals("getClass") && decl().hostType().isObject()) { TypeDecl typeClass = lookupType("java.lang", "Class"); if (typeClass instanceof GenericClassDecl) { TypeDecl bound = isQualified() ? qualifier().type() : hostType(); ArrayList args = new ArrayList(); args.add(bound.erasure().asWildcardExtends()); return ((GenericClassDecl) typeClass).lookupParTypeDecl(args); } } // Legacy getClass access using non-generic java.lang.Class. return refined_TypeAnalysis_MethodAccess_type(); } /** * @attribute syn * @aspect TypeCheck * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:149 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:149") public Collection typeProblems() { { Collection problems = new LinkedList(); for (int i = 0; i < getNumArg(); ++i) { if (getArg(i).type().isVoid()) { problems.add(errorf("expression '%s' has type void and is not a valid method argument", getArg(i).prettyPrint())); } } if (isQualified() && decl().isAbstract() && qualifier().isSuperAccess()) { problems.add(error("may not access abstract methods in superclass")); } if (!decl().isVariableArity() || invokesVariableArityAsArray()) { for (int i = 0; i < decl().getNumParameter(); i++) { TypeDecl exprType = getArg(i).type(); TypeDecl parmType = decl().getParameter(i).type(); if (!exprType.methodInvocationConversionTo(parmType) && !exprType.isUnknown() && !parmType.isUnknown()) { problems.add(errorf("argument '%s' of type %s is not compatible with the method parameter type %s", getArg(i).prettyPrint(), exprType.typeName(), parmType.typeName())); } } } return problems; } } /** * @attribute syn * @aspect Names * @declaredat /home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:36 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Names", declaredAt="/home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:36") public String name() { String name_value = getID(); return name_value; } /** * Defines the expected kind of name for the left hand side in a qualified * expression. * @attribute syn * @aspect SyntacticClassification * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:60 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="SyntacticClassification", declaredAt="/home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:60") public NameType predNameType() { NameType predNameType_value = NameType.AMBIGUOUS_NAME; return predNameType_value; } /** * @attribute syn * @aspect ExceptionHandling * @declaredat /home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:100 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="ExceptionHandling", declaredAt="/home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:100") public Collection exceptionHandlingProblems() { { Collection problems = new LinkedList(); for (TypeDecl exceptionType : exceptionCollection()) { if (exceptionType.isCheckedException() && !handlesException(exceptionType)) { problems.add(errorf("%s.%s invoked in %s may throw uncaught exception %s", decl().hostType().fullName(), this.name(), hostType().fullName(), exceptionType.fullName())); } } return problems; } } /** @apilevel internal */ private void exceptionCollection_reset() { exceptionCollection_computed = null; exceptionCollection_value = null; } /** @apilevel internal */ protected ASTState.Cycle exceptionCollection_computed = null; /** @apilevel internal */ protected Collection exceptionCollection_value; /** @return the exception types possibly thrown by this method access * @attribute syn * @aspect ExceptionHandling * @declaredat /home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:113 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="ExceptionHandling", declaredAt="/home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:113") public Collection exceptionCollection() { ASTState state = state(); if (exceptionCollection_computed == ASTState.NON_CYCLE || exceptionCollection_computed == state().cycle()) { return exceptionCollection_value; } exceptionCollection_value = exceptionCollection_compute(); if (state().inCircle()) { exceptionCollection_computed = state().cycle(); } else { exceptionCollection_computed = ASTState.NON_CYCLE; } return exceptionCollection_value; } /** @apilevel internal */ private Collection exceptionCollection_compute() { Collection exceptions = new HashSet(); Iterator iter = decls().iterator(); if (!iter.hasNext()) { return exceptions; } MethodDecl m = iter.next(); for (int i = 0; i < m.getNumException(); i++) { TypeDecl exceptionType = m.getException(i).type(); exceptions.add(exceptionType); } while (iter.hasNext()) { Collection first = new HashSet(); first.addAll(exceptions); Collection second = new HashSet(); m = iter.next(); for (int i = 0; i < m.getNumException(); i++) { TypeDecl exceptionType = m.getException(i).type(); second.add(exceptionType); } exceptions = new HashSet(); for (TypeDecl firstType : first) { for (TypeDecl secondType : second) { if (firstType.instanceOf(secondType)) { exceptions.add(firstType); } else if (secondType.instanceOf(firstType)) { exceptions.add(secondType); } } } } return exceptions; } /** * Returns one of the candidate declarations of this method access, * or {@code null} if there exist no possible candidate declarations. * *

This attribute is only used in error reporting, to give a hint about * a candidate declaration that was not applicable for method invocation * for some reason. * @attribute syn * @aspect LookupMethod * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:204 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="LookupMethod", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:204") public MethodDecl singleCandidateDecl() { { String signature = ""; MethodDecl result = null; for (MethodDecl m : lookupMethod(name())) { String otherSignature = m.fullSignature(); // Choose the candidate matching arity or the lexicographically first signature. if (result == null || (m.getNumParameter() == getNumArg() && result.getNumParameter() != getNumArg()) || (m.getNumParameter() == getNumArg() && otherSignature.compareTo(signature) < 0)) { signature = otherSignature; result = m; } } return result; } } /** @apilevel internal */ private void decls_reset() { decls_computed = null; decls_value = null; } /** @apilevel internal */ protected ASTState.Cycle decls_computed = null; /** @apilevel internal */ protected SimpleSet decls_value; /** * Find all most specific applicable method declarations for this invocation. * @attribute syn * @aspect LookupMethod * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:246 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="LookupMethod", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:246") public SimpleSet decls() { ASTState state = state(); if (decls_computed == ASTState.NON_CYCLE || decls_computed == state().cycle()) { return decls_value; } decls_value = decls_compute(); if (state().inCircle()) { decls_computed = state().cycle(); } else { decls_computed = ASTState.NON_CYCLE; } return decls_value; } /** @apilevel internal */ private SimpleSet decls_compute() { SimpleSet maxSpecific = maxSpecific(lookupMethod(name())); if (isQualified() ? qualifier().staticContextQualifier() : inStaticContext()) { maxSpecific = keepStaticMethods(maxSpecific); } return maxSpecific; } /** @apilevel internal */ private void decl_reset() { decl_computed = null; decl_value = null; } /** @apilevel internal */ protected ASTState.Cycle decl_computed = null; /** @apilevel internal */ protected MethodDecl decl_value; /** * Find the single method declaration matching this invocation. * *

If no such declaration exists, the unknown method declaration is returned * instead. * @attribute syn * @aspect LookupMethod * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:260 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="LookupMethod", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:260") public MethodDecl decl() { ASTState state = state(); if (decl_computed == ASTState.NON_CYCLE || decl_computed == state().cycle()) { return decl_value; } decl_value = decl_compute(); if (state().inCircle()) { decl_computed = state().cycle(); } else { decl_computed = ASTState.NON_CYCLE; } return decl_value; } /** @apilevel internal */ private MethodDecl decl_compute() { SimpleSet decls = decls(); if (decls.isSingleton()) { return decls.singletonValue(); } // Only return the first method in case of multiply inherited abstract methods. // See JLS6 section 8.4.6.4. boolean allAbstract = true; for (MethodDecl m : decls) { if (!m.isAbstract() && !m.hostType().isObject()) { allAbstract = false; break; } } if (decls.size() > 1 && allAbstract) { return decls.iterator().next(); } return unknownMethod(); } /** * Determine if a candidate method declaration is accessible * from this invocation. * @attribute syn * @aspect MethodDecl * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:410 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="MethodDecl", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:410") public boolean accessible(MethodDecl m) { { if (!isQualified()) { return true; } if (!m.accessibleFrom(hostType())) { return false; } // The method is not accessible if the type is not accessible. if (!qualifier().type().accessibleFrom(hostType())) { return false; } // 6.6.2.1 - include qualifier type for protected access if (m.isProtected() && !m.hostPackage().equals(hostPackage()) && !m.isStatic() && !qualifier().isSuperAccess()) { return hostType().mayAccess(this, m); } return true; } } /** @apilevel internal */ private void computeDAbefore_int_Variable_reset() { computeDAbefore_int_Variable_values = null; } protected java.util.Map computeDAbefore_int_Variable_values; @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true) @ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:502") public boolean computeDAbefore(int i, Variable v) { java.util.List _parameters = new java.util.ArrayList(2); _parameters.add(i); _parameters.add(v); if (computeDAbefore_int_Variable_values == null) computeDAbefore_int_Variable_values = new java.util.HashMap(4); ASTState.CircularValue _value; if (computeDAbefore_int_Variable_values.containsKey(_parameters)) { Object _cache = computeDAbefore_int_Variable_values.get(_parameters); if (!(_cache instanceof ASTState.CircularValue)) { return (Boolean) _cache; } else { _value = (ASTState.CircularValue) _cache; } } else { _value = new ASTState.CircularValue(); computeDAbefore_int_Variable_values.put(_parameters, _value); _value.value = true; } ASTState state = state(); if (!state.inCircle() || state.calledByLazyAttribute()) { state.enterCircle(); boolean new_computeDAbefore_int_Variable_value; do { _value.cycle = state.nextCycle(); new_computeDAbefore_int_Variable_value = i == 0 ? assignedBefore(v) : getArg(i-1).assignedAfter(v); if (((Boolean)_value.value) != new_computeDAbefore_int_Variable_value) { state.setChangeInCycle(); _value.value = new_computeDAbefore_int_Variable_value; } } while (state.testAndClearChangeInCycle()); computeDAbefore_int_Variable_values.put(_parameters, new_computeDAbefore_int_Variable_value); state.leaveCircle(); return new_computeDAbefore_int_Variable_value; } else if (_value.cycle != state.cycle()) { _value.cycle = state.cycle(); boolean new_computeDAbefore_int_Variable_value = i == 0 ? assignedBefore(v) : getArg(i-1).assignedAfter(v); if (((Boolean)_value.value) != new_computeDAbefore_int_Variable_value) { state.setChangeInCycle(); _value.value = new_computeDAbefore_int_Variable_value; } return new_computeDAbefore_int_Variable_value; } else { return (Boolean) _value.value; } } /** * @attribute syn * @aspect DefiniteAssignment * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:268 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:268") public boolean assignedAfter(Variable v) { boolean assignedAfter_Variable_value = getNumArg() == 0 ? assignedBefore(v) : getArg(getNumArg()-1).assignedAfter(v); return assignedAfter_Variable_value; } /** * @attribute syn * @aspect DefiniteAssignment * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:375 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:375") public boolean assignedAfterTrue(Variable v) { boolean assignedAfterTrue_Variable_value = isFalse() || (getNumArg() == 0 ? assignedBefore(v) : getArg(getNumArg()-1).assignedAfter(v)); return assignedAfterTrue_Variable_value; } /** * @attribute syn * @aspect DefiniteAssignment * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:377 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:377") public boolean assignedAfterFalse(Variable v) { boolean assignedAfterFalse_Variable_value = isTrue() || (getNumArg() == 0 ? assignedBefore(v) : getArg(getNumArg()-1).assignedAfter(v)); return assignedAfterFalse_Variable_value; } /** @apilevel internal */ private void computeDUbefore_int_Variable_reset() { computeDUbefore_int_Variable_values = null; } protected java.util.Map computeDUbefore_int_Variable_values; @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true) @ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:1118") public boolean computeDUbefore(int i, Variable v) { java.util.List _parameters = new java.util.ArrayList(2); _parameters.add(i); _parameters.add(v); if (computeDUbefore_int_Variable_values == null) computeDUbefore_int_Variable_values = new java.util.HashMap(4); ASTState.CircularValue _value; if (computeDUbefore_int_Variable_values.containsKey(_parameters)) { Object _cache = computeDUbefore_int_Variable_values.get(_parameters); if (!(_cache instanceof ASTState.CircularValue)) { return (Boolean) _cache; } else { _value = (ASTState.CircularValue) _cache; } } else { _value = new ASTState.CircularValue(); computeDUbefore_int_Variable_values.put(_parameters, _value); _value.value = true; } ASTState state = state(); if (!state.inCircle() || state.calledByLazyAttribute()) { state.enterCircle(); boolean new_computeDUbefore_int_Variable_value; do { _value.cycle = state.nextCycle(); new_computeDUbefore_int_Variable_value = i == 0 ? unassignedBefore(v) : getArg(i-1).unassignedAfter(v); if (((Boolean)_value.value) != new_computeDUbefore_int_Variable_value) { state.setChangeInCycle(); _value.value = new_computeDUbefore_int_Variable_value; } } while (state.testAndClearChangeInCycle()); computeDUbefore_int_Variable_values.put(_parameters, new_computeDUbefore_int_Variable_value); state.leaveCircle(); return new_computeDUbefore_int_Variable_value; } else if (_value.cycle != state.cycle()) { _value.cycle = state.cycle(); boolean new_computeDUbefore_int_Variable_value = i == 0 ? unassignedBefore(v) : getArg(i-1).unassignedAfter(v); if (((Boolean)_value.value) != new_computeDUbefore_int_Variable_value) { state.setChangeInCycle(); _value.value = new_computeDUbefore_int_Variable_value; } return new_computeDUbefore_int_Variable_value; } else { return (Boolean) _value.value; } } /** @apilevel internal */ private void unassignedAfter_Variable_reset() { unassignedAfter_Variable_values = null; } protected java.util.Map unassignedAfter_Variable_values; @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true) @ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:899") public boolean unassignedAfter(Variable v) { Object _parameters = v; if (unassignedAfter_Variable_values == null) unassignedAfter_Variable_values = new java.util.HashMap(4); ASTState.CircularValue _value; if (unassignedAfter_Variable_values.containsKey(_parameters)) { Object _cache = unassignedAfter_Variable_values.get(_parameters); if (!(_cache instanceof ASTState.CircularValue)) { return (Boolean) _cache; } else { _value = (ASTState.CircularValue) _cache; } } else { _value = new ASTState.CircularValue(); unassignedAfter_Variable_values.put(_parameters, _value); _value.value = true; } ASTState state = state(); if (!state.inCircle() || state.calledByLazyAttribute()) { state.enterCircle(); boolean new_unassignedAfter_Variable_value; do { _value.cycle = state.nextCycle(); new_unassignedAfter_Variable_value = getNumArg() == 0 ? unassignedBefore(v) : getArg(getNumArg()-1).unassignedAfter(v); if (((Boolean)_value.value) != new_unassignedAfter_Variable_value) { state.setChangeInCycle(); _value.value = new_unassignedAfter_Variable_value; } } while (state.testAndClearChangeInCycle()); unassignedAfter_Variable_values.put(_parameters, new_unassignedAfter_Variable_value); state.leaveCircle(); return new_unassignedAfter_Variable_value; } else if (_value.cycle != state.cycle()) { _value.cycle = state.cycle(); boolean new_unassignedAfter_Variable_value = getNumArg() == 0 ? unassignedBefore(v) : getArg(getNumArg()-1).unassignedAfter(v); if (((Boolean)_value.value) != new_unassignedAfter_Variable_value) { state.setChangeInCycle(); _value.value = new_unassignedAfter_Variable_value; } return new_unassignedAfter_Variable_value; } else { return (Boolean) _value.value; } } /** @apilevel internal */ private void unassignedAfterTrue_Variable_reset() { unassignedAfterTrue_Variable_values = null; } protected java.util.Map unassignedAfterTrue_Variable_values; @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true) @ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:905") public boolean unassignedAfterTrue(Variable v) { Object _parameters = v; if (unassignedAfterTrue_Variable_values == null) unassignedAfterTrue_Variable_values = new java.util.HashMap(4); ASTState.CircularValue _value; if (unassignedAfterTrue_Variable_values.containsKey(_parameters)) { Object _cache = unassignedAfterTrue_Variable_values.get(_parameters); if (!(_cache instanceof ASTState.CircularValue)) { return (Boolean) _cache; } else { _value = (ASTState.CircularValue) _cache; } } else { _value = new ASTState.CircularValue(); unassignedAfterTrue_Variable_values.put(_parameters, _value); _value.value = true; } ASTState state = state(); if (!state.inCircle() || state.calledByLazyAttribute()) { state.enterCircle(); boolean new_unassignedAfterTrue_Variable_value; do { _value.cycle = state.nextCycle(); new_unassignedAfterTrue_Variable_value = isFalse() || (getNumArg() == 0 ? unassignedBefore(v) : getArg(getNumArg()-1).unassignedAfter(v)); if (((Boolean)_value.value) != new_unassignedAfterTrue_Variable_value) { state.setChangeInCycle(); _value.value = new_unassignedAfterTrue_Variable_value; } } while (state.testAndClearChangeInCycle()); unassignedAfterTrue_Variable_values.put(_parameters, new_unassignedAfterTrue_Variable_value); state.leaveCircle(); return new_unassignedAfterTrue_Variable_value; } else if (_value.cycle != state.cycle()) { _value.cycle = state.cycle(); boolean new_unassignedAfterTrue_Variable_value = isFalse() || (getNumArg() == 0 ? unassignedBefore(v) : getArg(getNumArg()-1).unassignedAfter(v)); if (((Boolean)_value.value) != new_unassignedAfterTrue_Variable_value) { state.setChangeInCycle(); _value.value = new_unassignedAfterTrue_Variable_value; } return new_unassignedAfterTrue_Variable_value; } else { return (Boolean) _value.value; } } /** @apilevel internal */ private void unassignedAfterFalse_Variable_reset() { unassignedAfterFalse_Variable_values = null; } protected java.util.Map unassignedAfterFalse_Variable_values; @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true) @ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:907") public boolean unassignedAfterFalse(Variable v) { Object _parameters = v; if (unassignedAfterFalse_Variable_values == null) unassignedAfterFalse_Variable_values = new java.util.HashMap(4); ASTState.CircularValue _value; if (unassignedAfterFalse_Variable_values.containsKey(_parameters)) { Object _cache = unassignedAfterFalse_Variable_values.get(_parameters); if (!(_cache instanceof ASTState.CircularValue)) { return (Boolean) _cache; } else { _value = (ASTState.CircularValue) _cache; } } else { _value = new ASTState.CircularValue(); unassignedAfterFalse_Variable_values.put(_parameters, _value); _value.value = true; } ASTState state = state(); if (!state.inCircle() || state.calledByLazyAttribute()) { state.enterCircle(); boolean new_unassignedAfterFalse_Variable_value; do { _value.cycle = state.nextCycle(); new_unassignedAfterFalse_Variable_value = isTrue() || (getNumArg() == 0 ? unassignedBefore(v) : getArg(getNumArg()-1).unassignedAfter(v)); if (((Boolean)_value.value) != new_unassignedAfterFalse_Variable_value) { state.setChangeInCycle(); _value.value = new_unassignedAfterFalse_Variable_value; } } while (state.testAndClearChangeInCycle()); unassignedAfterFalse_Variable_values.put(_parameters, new_unassignedAfterFalse_Variable_value); state.leaveCircle(); return new_unassignedAfterFalse_Variable_value; } else if (_value.cycle != state.cycle()) { _value.cycle = state.cycle(); boolean new_unassignedAfterFalse_Variable_value = isTrue() || (getNumArg() == 0 ? unassignedBefore(v) : getArg(getNumArg()-1).unassignedAfter(v)); if (((Boolean)_value.value) != new_unassignedAfterFalse_Variable_value) { state.setChangeInCycle(); _value.value = new_unassignedAfterFalse_Variable_value; } return new_unassignedAfterFalse_Variable_value; } else { return (Boolean) _value.value; } } /** * @attribute syn * @aspect TypeHierarchyCheck * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:53 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="TypeHierarchyCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:53") public Collection typeHierarchyProblems() { { Collection problems = new LinkedList(); if (isQualified() && qualifier().isPackageAccess() && !qualifier().isUnknown()) { problems.add(errorf("The method %s can not be qualified by a package name.", decl().fullSignature())); } if (isQualified() && decl().isAbstract() && qualifier().isSuperAccess()) { problems.add(error("may not access abstract methods in superclass")); } if (decls().isEmpty() && (!isQualified() || !qualifier().isUnknown())) { StringBuilder sb = new StringBuilder(); sb.append("no method named " + name()); sb.append("("); for (int i = 0; i < getNumArg(); i++) { TypeDecl argType = getArg(i).type(); if (argType.isVoid()) { // Error will be reported for the void argument in typeCheck // so we return now to avoid confusing double errors. return problems; } if (i != 0) { sb.append(", "); } sb.append(argType.typeName()); } sb.append(")" + " in " + methodHost() + " matches."); if (singleCandidateDecl() != null) { sb.append(" However, there is a method " + singleCandidateDecl().fullSignature()); } problems.add(error(sb.toString())); } if (decls().size() > 1) { boolean allAbstract = true; for (MethodDecl m : decls()) { if (!m.isAbstract() && !m.hostType().isObject()) { allAbstract = false; break; } } if (!allAbstract && validArgs()) { StringBuilder sb = new StringBuilder(); sb.append("several most specific methods for " + this.prettyPrint() + "\n"); for (MethodDecl m : decls()) { sb.append(" " + m.fullSignature() + " in " + m.hostType().typeName() + "\n"); } problems.add(error(sb.toString())); } } return problems; } } /** * @attribute syn * @aspect VariableArityParameters * @declaredat /home/jesper/git/extendj/java5/frontend/VariableArityParameters.jrag:65 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="VariableArityParameters", declaredAt="/home/jesper/git/extendj/java5/frontend/VariableArityParameters.jrag:65") public boolean invokesVariableArityAsArray() { { if (!decl().isVariableArity()) { return false; } if (arity() != decl().arity()) { return false; } return getArg(getNumArg()-1).type().methodInvocationConversionTo(decl().lastParameter().type()); } } /** * @attribute syn * @aspect MethodSignature15 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:232 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="MethodSignature15", declaredAt="/home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:232") public boolean applicableBySubtyping(MethodDecl m) { { if (m.getNumParameter() != getNumArg()) { return false; } for (int i = 0; i < m.getNumParameter(); i++) { TypeDecl arg = getArg(i).type(); TypeDecl param = m.getParameter(i).type(); if (!arg.subtype(param)) { return false; } } return true; } } /** * @attribute syn * @aspect MethodSignature15 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:260 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="MethodSignature15", declaredAt="/home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:260") public boolean applicableByMethodInvocationConversion(MethodDecl m) { { if (m.getNumParameter() != getNumArg()) { return false; } for (int i = 0; i < m.getNumParameter(); i++) { if (!getArg(i).type().methodInvocationConversionTo(m.getParameter(i).type())) { return false; } } return true; } } /** * @attribute syn * @aspect MethodSignature15 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:285 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="MethodSignature15", declaredAt="/home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:285") public boolean applicableVariableArity(MethodDecl m) { { for (int i = 0; i < m.getNumParameter() - 1; i++) { if (!getArg(i).type().methodInvocationConversionTo(m.getParameter(i).type())) { return false; } } for (int i = m.getNumParameter() - 1; i < getNumArg(); i++) { if (!getArg(i).type().methodInvocationConversionTo( m.lastParameter().type().componentType())) { return false; } } return true; } } /** * A member method is potentially applicable to a method invocation if and * only if all of the following are true: *

    *
  • The name of the member is identical to the name of the method in the * method invocation. *
  • The member is accessible (\ufffd6.6) to the class or interface in which * the method invocation appears. *
  • The arity of the member is lesser or equal to the arity of the * method invocation. *
  • If the member is a variable arity method with arity n, the arity of * the method invocation is greater or equal to n-1. *
  • If the member is a fixed arity method with arity n, the arity of the * method invocation is equal to n. *
  • If the method invocation includes explicit type parameters, and the * member is a generic method, then the number of actual type parameters is * equal to the number of formal type parameters. *
* @attribute syn * @aspect MethodSignature15 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:385 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="MethodSignature15", declaredAt="/home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:385") public boolean potentiallyApplicable(MethodDecl m) { { if (!m.name().equals(name())) { return false; } if (!m.accessibleFrom(hostType())) { return false; } if (m.isVariableArity() && !(arity() >= m.arity() - 1)) { return false; } if (!m.isVariableArity() && !(m.arity() == arity())) { return false; } if (m.isGeneric()) { GenericMethodDecl gm = m.genericDecl(); ArrayList typeArguments = inferTypeArguments( m.type(), m.getParameterList(), getArgList(), gm.getTypeParameterList()); if (!typeArguments.isEmpty()) { if (gm.getNumTypeParameter() != typeArguments.size()) { return false; } ParMethodDecl parMethod = gm.lookupParMethodDecl(typeArguments); for (int i = 0; i < gm.getNumTypeParameter(); i++) { if (!typeArguments.get(i).withinBounds(parMethod.getTypeParameter(i))) { return false; } } } } return true; } } /** * @attribute syn * @aspect MethodSignature15 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:421 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="MethodSignature15", declaredAt="/home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:421") public int arity() { int arity_value = getNumArg(); return arity_value; } /** * @return {@code true} if this access is a method call of a non-static method. * @attribute syn * @aspect GenerateClassfile * @declaredat /home/jesper/git/extendj/java4/backend/GenerateClassfile.jrag:418 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="GenerateClassfile", declaredAt="/home/jesper/git/extendj/java4/backend/GenerateClassfile.jrag:418") public boolean isInstanceMethodAccess() { boolean isInstanceMethodAccess_value = !decl().isStatic(); return isInstanceMethodAccess_value; } /** @apilevel internal */ private void transformed_reset() { transformed_computed = null; transformed_value = null; } /** @apilevel internal */ protected ASTState.Cycle transformed_computed = null; /** @apilevel internal */ protected Access transformed_value; /** * @attribute syn * @aspect Transformations * @declaredat /home/jesper/git/extendj/java4/backend/Transformations.jrag:33 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Transformations", declaredAt="/home/jesper/git/extendj/java4/backend/Transformations.jrag:33") public Access transformed() { ASTState state = state(); if (transformed_computed == ASTState.NON_CYCLE || transformed_computed == state().cycle()) { return transformed_value; } transformed_value = transformed_compute(); if (state().inCircle()) { transformed_computed = state().cycle(); } else { transformed_computed = ASTState.NON_CYCLE; } return transformed_value; } /** @apilevel internal */ private Access transformed_compute() { if (decl().isVariableArity() && !invokesVariableArityAsArray()) { return transformedVariableArity(); } else { return refined_Transformations_MethodAccess_transformed(); } } /** @apilevel internal */ private void transformedQualified_reset() { transformedQualified_computed = false; transformedQualified_value = null; } /** @apilevel internal */ protected boolean transformedQualified_computed = false; /** @apilevel internal */ protected Access transformedQualified_value; /** * @attribute syn * @aspect Transformations * @declaredat /home/jesper/git/extendj/java4/backend/Transformations.jrag:44 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isNTA=true) @ASTNodeAnnotation.Source(aspect="Transformations", declaredAt="/home/jesper/git/extendj/java4/backend/Transformations.jrag:44") public Access transformedQualified() { ASTState state = state(); if (transformedQualified_computed) { return transformedQualified_value; } state().enterLazyAttribute(); transformedQualified_value = methodQualifierType().methodAccessor(decl()) .createBoundAccess(getArgList().treeCopyNoTransform()); transformedQualified_value.setParent(this); transformedQualified_computed = true; state().leaveLazyAttribute(); return transformedQualified_value; } /** * @attribute syn * @aspect InnerClasses * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:85 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="InnerClasses", declaredAt="/home/jesper/git/extendj/java4/backend/InnerClasses.jrag:85") public TypeDecl methodQualifierType() { { TypeDecl typeDecl = refined_InnerClasses_MethodAccess_methodQualifierType(); if (typeDecl == null) { return null; } typeDecl = typeDecl.erasure(); Collection methods = typeDecl.memberMethods(name()); if (!methods.contains(decl()) && !methods.contains(decl().sourceMethodDecl())) { return decl().hostType(); } return typeDecl; } } /** * @attribute syn * @aspect InnerClasses * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:415 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="InnerClasses", declaredAt="/home/jesper/git/extendj/java4/backend/InnerClasses.jrag:415") public boolean requiresAccessor() { { MethodDecl decl = decl(); if (decl.isPrivate() && decl.hostType().original() != hostType().original()) { return true; } return decl.isProtected() && !decl.hostPackage().equals(hostPackage()) && !hostType().hasMethod(decl); } } /** * This finds the erased runtime type of an expression. * *

The erased type of a field or method depends on the original * declaration of the field or method (without generic type substitution). * @attribute syn * @aspect GenericsCodegen * @declaredat /home/jesper/git/extendj/java5/backend/GenericsCodegen.jrag:144 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="GenericsCodegen", declaredAt="/home/jesper/git/extendj/java5/backend/GenericsCodegen.jrag:144") public TypeDecl erasedType() { TypeDecl erasedType_value = decl().erasedMethod().type(); return erasedType_value; } /** @apilevel internal */ private void transformedVariableArity_reset() { transformedVariableArity_computed = false; transformedVariableArity_value = null; } /** @apilevel internal */ protected boolean transformedVariableArity_computed = false; /** @apilevel internal */ protected MethodAccess transformedVariableArity_value; /** * @attribute syn * @aspect VariableArityParametersCodegen * @declaredat /home/jesper/git/extendj/java5/backend/VariableArityParametersCodegen.jrag:49 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isNTA=true) @ASTNodeAnnotation.Source(aspect="VariableArityParametersCodegen", declaredAt="/home/jesper/git/extendj/java5/backend/VariableArityParametersCodegen.jrag:49") public MethodAccess transformedVariableArity() { ASTState state = state(); if (transformedVariableArity_computed) { return transformedVariableArity_value; } state().enterLazyAttribute(); transformedVariableArity_value = transformedVariableArity_compute(); transformedVariableArity_value.setParent(this); transformedVariableArity_computed = true; state().leaveLazyAttribute(); return transformedVariableArity_value; } /** @apilevel internal */ private MethodAccess transformedVariableArity_compute() { MethodDecl decl = decl(); // Copy regular arguments. List args = new List(); for (int i = 0; i < decl.getNumParameter() - 1; i++) { args.add(getArg(i).treeCopyNoTransform()); } // Compress arguments to the variable arity parameter. List last = new List(); for (int i = decl.getNumParameter() - 1; i < getNumArg(); i++) { last.add(getArg(i).treeCopyNoTransform()); } // Build an array holding arguments. Access typeAccess = decl.lastParameter().type().elementType().createQualifiedAccess(); for (int i = 0; i < decl.lastParameter().type().dimension(); i++) { typeAccess = new ArrayTypeAccess(typeAccess); } args.add(new ArrayCreationExpr(typeAccess, new Opt(new ArrayInit(last)))); return new MethodAccess(getID(), args); } /** * @attribute inh * @aspect ExceptionHandling * @declaredat /home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:88 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH) @ASTNodeAnnotation.Source(aspect="ExceptionHandling", declaredAt="/home/jesper/git/extendj/java4/frontend/ExceptionHandling.jrag:88") public boolean handlesException(TypeDecl exceptionType) { boolean handlesException_TypeDecl_value = getParent().Define_handlesException(this, null, exceptionType); return handlesException_TypeDecl_value; } /** * Returns a method declaration representing unknown methods. * Used in method lookup when no matching method was found. * @attribute inh * @aspect LookupMethod * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:49 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH) @ASTNodeAnnotation.Source(aspect="LookupMethod", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:49") public MethodDecl unknownMethod() { MethodDecl unknownMethod_value = getParent().Define_unknownMethod(this, null); return unknownMethod_value; } /** * @attribute inh * @aspect TypeHierarchyCheck * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:184 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH) @ASTNodeAnnotation.Source(aspect="TypeHierarchyCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:184") public boolean inExplicitConstructorInvocation() { boolean inExplicitConstructorInvocation_value = getParent().Define_inExplicitConstructorInvocation(this, null); return inExplicitConstructorInvocation_value; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:101 * @apilevel internal */ public boolean Define_isRightChildOfDot(ASTNode _callerNode, ASTNode _childNode) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:107 int childIndex = _callerNode.getIndexOfChild(_childNode); return false; } else { int childIndex = this.getIndexOfChild(_callerNode); return isRightChildOfDot(); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:101 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute isRightChildOfDot */ protected boolean canDefine_isRightChildOfDot(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:118 * @apilevel internal */ public Expr Define_prevExpr(ASTNode _callerNode, ASTNode _childNode) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:123 int childIndex = _callerNode.getIndexOfChild(_childNode); return prevExprError(); } else { int childIndex = this.getIndexOfChild(_callerNode); return prevExpr(); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:118 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute prevExpr */ protected boolean canDefine_prevExpr(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:109 * @apilevel internal */ public boolean Define_hasPackage(ASTNode _callerNode, ASTNode _childNode, String packageName) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:110 int childIndex = _callerNode.getIndexOfChild(_childNode); return unqualifiedScope().hasPackage(packageName); } else { return getParent().Define_hasPackage(this, _callerNode, packageName); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:109 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute hasPackage */ protected boolean canDefine_hasPackage(ASTNode _callerNode, ASTNode _childNode, String packageName) { return true; } /** * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:231 * @apilevel internal */ public SimpleSet Define_lookupType(ASTNode _callerNode, ASTNode _childNode, String name) { if (_callerNode == transformedQualified_value) { // @declaredat /home/jesper/git/extendj/java4/backend/Transformations.jrag:41 return unqualifiedScope().lookupType(name); } else if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:381 int childIndex = _callerNode.getIndexOfChild(_childNode); return unqualifiedScope().lookupType(name); } else { return getParent().Define_lookupType(this, _callerNode, name); } } /** * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:231 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute lookupType */ protected boolean canDefine_lookupType(ASTNode _callerNode, ASTNode _childNode, String name) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 * @apilevel internal */ public NameType Define_nameType(ASTNode _callerNode, ASTNode _childNode) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:139 int childIndex = _callerNode.getIndexOfChild(_childNode); return NameType.EXPRESSION_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; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:116 * @apilevel internal */ public Collection Define_lookupMethod(ASTNode _callerNode, ASTNode _childNode, String name) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:128 int childIndex = _callerNode.getIndexOfChild(_childNode); return unqualifiedScope().lookupMethod(name); } else { return getParent().Define_lookupMethod(this, _callerNode, name); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:116 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute lookupMethod */ protected boolean canDefine_lookupMethod(ASTNode _callerNode, ASTNode _childNode, String name) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:256 * @apilevel internal */ public boolean Define_assignedBefore(ASTNode _callerNode, ASTNode _childNode, Variable v) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:500 int i = _callerNode.getIndexOfChild(_childNode); return computeDAbefore(i, v); } else { return getParent().Define_assignedBefore(this, _callerNode, v); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:256 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute assignedBefore */ protected boolean canDefine_assignedBefore(ASTNode _callerNode, ASTNode _childNode, Variable v) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:887 * @apilevel internal */ public boolean Define_unassignedBefore(ASTNode _callerNode, ASTNode _childNode, Variable v) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:1116 int i = _callerNode.getIndexOfChild(_childNode); return computeDUbefore(i, v); } else { return getParent().Define_unassignedBefore(this, _callerNode, v); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:887 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute unassignedBefore */ protected boolean canDefine_unassignedBefore(ASTNode _callerNode, ASTNode _childNode, Variable v) { return true; } /** * @declaredat /home/jesper/git/extendj/java5/frontend/EnhancedFor.jrag:138 * @apilevel internal */ public SimpleSet Define_lookupVariable(ASTNode _callerNode, ASTNode _childNode, String name) { int childIndex = this.getIndexOfChild(_callerNode); return unqualifiedScope().lookupVariable(name); } /** * @declaredat /home/jesper/git/extendj/java5/frontend/EnhancedFor.jrag:138 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute lookupVariable */ protected boolean canDefine_lookupVariable(ASTNode _callerNode, ASTNode _childNode, String name) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:33 * @apilevel internal */ public String Define_methodHost(ASTNode _callerNode, ASTNode _childNode) { int childIndex = this.getIndexOfChild(_callerNode); return unqualifiedScope().methodHost(); } /** * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:33 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute methodHost */ protected boolean canDefine_methodHost(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethodsInference.jrag:69 * @apilevel internal */ public TypeDecl Define_assignConvertedType(ASTNode _callerNode, ASTNode _childNode) { if (_callerNode == getArgListNoTransform()) { // @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethodsInference.jrag:84 int index = _callerNode.getIndexOfChild(_childNode); return typeObject(); } else { return getParent().Define_assignConvertedType(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethodsInference.jrag:69 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute assignConvertedType */ protected boolean canDefine_assignConvertedType(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/java4/frontend/TypeCheck.jrag:147 { 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/java4/frontend/ExceptionHandling.jrag:98 { 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/java4/frontend/TypeHierarchyCheck.jrag:51 { 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/java5/frontend/Annotations.jrag:499 if (decl().isDeprecated() && !withinDeprecatedAnnotation() && hostType().topLevelType() != decl().hostType().topLevelType() && !withinSuppressWarnings("deprecation")) { { 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_accessors(CompilationUnit _root, java.util.Map> _map) { // @declaredat /home/jesper/git/extendj/java4/backend/GenerateClassfile.jrag:379 if (requiresAccessor()) { { TypeDecl target = (TypeDecl) (methodQualifierType()); 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_accessors(_root, _map); } /** @apilevel internal */ protected void collect_contributors_TypeDecl_nestedTypes(CompilationUnit _root, java.util.Map> _map) { { if (transformed() != this) { transformed().collect_contributors_TypeDecl_nestedTypes(_root, _map); } else { super.collect_contributors_TypeDecl_nestedTypes(_root, _map); } } } /** @apilevel internal */ protected void contributeTo_CompilationUnit_problems(LinkedList collection) { super.contributeTo_CompilationUnit_problems(collection); for (Problem value : typeProblems()) { collection.add(value); } for (Problem value : exceptionHandlingProblems()) { collection.add(value); } for (Problem value : typeHierarchyProblems()) { collection.add(value); } if (decl().isDeprecated() && !withinDeprecatedAnnotation() && hostType().topLevelType() != decl().hostType().topLevelType() && !withinSuppressWarnings("deprecation")) { collection.add(warning(decl().signature() + " in " + decl().hostType().typeName() + " has been deprecated")); } } /** @apilevel internal */ protected void contributeTo_TypeDecl_accessors(HashSet collection) { super.contributeTo_TypeDecl_accessors(collection); if (requiresAccessor()) { collection.add(methodQualifierType().methodAccessor(decl())); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy