Beispiel #1
0
 /**
  * @ast method
  * @aspect PreciseRethrow
  * @declaredat
  *     /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java7Frontend/PreciseRethrow.jrag:163
  */
 public void exceptionHandling() {
   Collection<TypeDecl> exceptionTypes = getExpr().throwTypes();
   for (TypeDecl exceptionType : exceptionTypes) {
     if (exceptionType == typeNull()) exceptionType = typeNullPointerException();
     // 8.4.4
     if (!handlesException(exceptionType))
       error("" + this + " throws uncaught exception " + exceptionType.fullName());
   }
 }
Beispiel #2
0
  /**
   * @ast method
   * @aspect Expressions
   * @declaredat
   *     /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Expressions.jrag:84
   */
  public soot.Value eval(Body b) {
    TypeDecl dest = getDest().type();
    TypeDecl source = getSource().type();
    if (dest.isString()) {

      Value lvalue = getDest().eval(b);

      Value v = asImmediate(b, lvalue);

      // new StringBuffer(left)
      Local local =
          b.newTemp(b.newNewExpr(lookupType("java.lang", "StringBuffer").sootRef(), this));
      b.setLine(this);
      b.add(
          b.newInvokeStmt(
              b.newSpecialInvokeExpr(
                  local,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: void <init>(java.lang.String)>")
                      .makeRef(),
                  v,
                  this),
              this));

      // append right
      Local rightResult =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  local,
                  lookupType("java.lang", "StringBuffer")
                      .methodWithArgs("append", new TypeDecl[] {source.stringPromotion()})
                      .sootRef(),
                  asImmediate(b, getSource().eval(b)),
                  this));

      // toString
      Local result =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  rightResult,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: java.lang.String toString()>")
                      .makeRef(),
                  this));

      Value v2 = lvalue instanceof Local ? lvalue : (Value) lvalue.clone();
      getDest().emitStore(b, v2, result, this);
      return result;
    } else {
      return super.eval(b);
    }
  }
Beispiel #3
0
  // Declared in AnonymousClasses.jrag at line 52
  private AnonymousDecl rewriteRule0() {
    {
      setModifiers(new Modifiers(new List().add(new Modifier("final"))));

      ConstructorDecl constructor = new ConstructorDecl();
      addBodyDecl(constructor);

      constructor.setModifiers((Modifiers) constructorDecl().getModifiers().fullCopy());
      String name = "Anonymous" + nextAnonymousIndex();
      setID(name);
      constructor.setID(name);

      List parameterList = new List();
      for (int i = 0; i < constructorDecl().getNumParameter(); i++) {
        parameterList.add(
            new ParameterDeclaration(
                constructorDecl().getParameter(i).type().createBoundAccess(),
                constructorDecl().getParameter(i).name()));
      }
      constructor.setParameterList(parameterList);

      List argList = new List();
      for (int i = 0; i < constructor.getNumParameter(); i++)
        argList.add(new VarAccess(constructor.getParameter(i).name()));
      constructor.setConstructorInvocation(
          new ExprStmt(new SuperConstructorAccess("super", argList)));
      constructor.setBlock(new Block());

      HashSet set = new HashSet();
      for (int i = 0; i < getNumBodyDecl(); i++) {
        if (getBodyDecl(i) instanceof InstanceInitializer) {
          InstanceInitializer init = (InstanceInitializer) getBodyDecl(i);
          set.addAll(init.exceptions());
        } else if (getBodyDecl(i) instanceof FieldDeclaration) {
          FieldDeclaration f = (FieldDeclaration) getBodyDecl(i);
          if (f.isInstanceVariable()) {
            set.addAll(f.exceptions());
          }
        }
      }
      List exceptionList = new List();
      for (Iterator iter = set.iterator(); iter.hasNext(); ) {
        TypeDecl exceptionType = (TypeDecl) iter.next();
        if (exceptionType.isNull()) exceptionType = typeNullPointerException();
        exceptionList.add(exceptionType.createQualifiedAccess());
      }
      constructor.setExceptionList(exceptionList);
      return this;
    }
  }
Beispiel #4
0
 /** @apilevel internal */
 private TypeDecl sourceType_compute() {
   TypeDecl left = getDest().type();
   TypeDecl right = getSource().type();
   if (!left.isString() && !right.isString()) return super.sourceType();
   if (left.isVoid() || right.isVoid()) return unknownType();
   return left.isString() ? left : right;
 }
Beispiel #5
0
 /**
  * @ast method
  * @aspect PreciseRethrow
  * @declaredat
  *     /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java7Frontend/PreciseRethrow.jrag:176
  */
 protected boolean reachedException(TypeDecl catchType) {
   Collection<TypeDecl> exceptionTypes = getExpr().throwTypes();
   boolean reached = false;
   for (TypeDecl exceptionType : exceptionTypes) {
     if (exceptionType == typeNull()) exceptionType = typeNullPointerException();
     if (catchType.mayCatch(exceptionType)) {
       reached = true;
       break;
     }
     if (super.reachedException(catchType)) {
       reached = true;
       break;
     }
   }
   return reached;
 }
Beispiel #6
0
 private boolean subtype_compute(TypeDecl type) {
   return type.supertypeRawClassDecl(this);
 }
Beispiel #7
0
 private boolean subtype_compute(TypeDecl type) {
   return type.supertypeWildcard(this);
 }
Beispiel #8
0
 private boolean narrowingConversionTo_compute(TypeDecl type) {
   return type.isChar();
 }