Beispiel #1
0
 /** @see Traverser */
 public void traverseNewAnonymousClassInstance(Java.NewAnonymousClassInstance naci) throws EX {
   if (naci.optionalQualification != null) {
     naci.optionalQualification.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   }
   naci.anonymousClassDeclaration.accept(this.cv);
   for (Java.Rvalue argument : naci.arguments)
     argument.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   this.traverseRvalue(naci);
 }
Beispiel #2
0
 /** @see Traverser */
 public void traverseNewClassInstance(Java.NewClassInstance nci) throws EX {
   if (nci.optionalQualification != null) {
     nci.optionalQualification.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   }
   if (nci.type != null) nci.type.accept((Visitor.TypeVisitor<Void, EX>) this.cv);
   for (Java.Rvalue argument : nci.arguments)
     argument.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   this.traverseRvalue(nci);
 }
Beispiel #3
0
 /** @see Traverser */
 public void traverseSwitchStatement(Java.SwitchStatement ss) throws EX {
   ss.condition.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   for (Java.SwitchStatement.SwitchBlockStatementGroup sbsg : ss.sbsgs) {
     for (Java.Rvalue cl : sbsg.caseLabels) cl.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
     for (Java.BlockStatement bs : sbsg.blockStatements) bs.accept(this.cv);
     this.traverseLocated(sbsg);
   }
   this.traverseBreakableStatement(ss);
 }
Beispiel #4
0
 /** @see Traverser */
 public void traverseForStatement(Java.ForStatement fs) throws EX {
   if (fs.optionalInit != null) fs.optionalInit.accept(this.cv);
   if (fs.optionalCondition != null)
     fs.optionalCondition.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   if (fs.optionalUpdate != null) {
     for (Java.Rvalue rv : fs.optionalUpdate) rv.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   }
   fs.body.accept(this.cv);
   this.traverseContinuableStatement(fs);
 }
Beispiel #5
0
 /** @see Traverser */
 public void traverseConstructorInvocation(Java.ConstructorInvocation ci) throws EX {
   for (Java.Rvalue argument : ci.arguments)
     argument.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   this.traverseAtom(ci);
 }
Beispiel #6
0
 /** @see Traverser */
 public void traverseInvocation(Java.Invocation i) throws EX {
   for (Java.Rvalue argument : i.arguments)
     argument.accept((Visitor.RvalueVisitor<Void, EX>) this.cv);
   this.traverseRvalue(i);
 }
  private static Java.Rvalue stripUnnecessaryParenExprs(Java.Rvalue rvalue) {
    if (rvalue == null) {
      return null;
    }
    final Java.Rvalue[] res = new Java.Rvalue[1];
    Visitor.RvalueVisitor rv =
        new Visitor.RvalueVisitor() {

          @Override
          public void visitArrayLength(ArrayLength al) {
            res[0] =
                new Java.ArrayLength(
                    al.getLocation(), UnparseTests.stripUnnecessaryParenExprs(al.lhs));
          }

          @Override
          public void visitAssignment(Assignment a) {
            res[0] =
                new Java.Assignment(
                    a.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(a.lhs),
                    a.operator,
                    UnparseTests.stripUnnecessaryParenExprs(a.rhs));
          }

          @Override
          public void visitBinaryOperation(BinaryOperation bo) {
            res[0] =
                new Java.BinaryOperation(
                    bo.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(bo.lhs),
                    bo.op,
                    UnparseTests.stripUnnecessaryParenExprs(bo.rhs));
          }

          @Override
          public void visitCast(Cast c) {
            res[0] =
                new Java.Cast(
                    c.getLocation(),
                    c.targetType,
                    UnparseTests.stripUnnecessaryParenExprs(c.value));
          }

          @Override
          public void visitClassLiteral(ClassLiteral cl) {
            res[0] = cl; // too much effort
          }

          @Override
          public void visitConditionalExpression(ConditionalExpression ce) {
            res[0] =
                new Java.ConditionalExpression(
                    ce.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(ce.lhs),
                    UnparseTests.stripUnnecessaryParenExprs(ce.mhs),
                    UnparseTests.stripUnnecessaryParenExprs(ce.rhs));
          }

          @Override
          public void visitCrement(Crement c) {
            if (c.pre) {
              res[0] =
                  new Java.Crement(
                      c.getLocation(),
                      c.operator,
                      UnparseTests.stripUnnecessaryParenExprs(c.operand));
            } else {
              res[0] =
                  new Java.Crement(
                      c.getLocation(),
                      UnparseTests.stripUnnecessaryParenExprs(c.operand),
                      c.operator);
            }
          }

          @Override
          public void visitInstanceof(Instanceof io) {
            res[0] =
                new Java.Instanceof(
                    io.getLocation(), UnparseTests.stripUnnecessaryParenExprs(io.lhs), io.rhs);
          }

          @Override
          public void visitIntegerLiteral(IntegerLiteral il) {
            res[0] = il;
          }

          @Override
          public void visitFloatingPointLiteral(FloatingPointLiteral fpl) {
            res[0] = fpl;
          }

          @Override
          public void visitBooleanLiteral(BooleanLiteral bl) {
            res[0] = bl;
          }

          @Override
          public void visitCharacterLiteral(CharacterLiteral cl) {
            res[0] = cl;
          }

          @Override
          public void visitStringLiteral(StringLiteral sl) {
            res[0] = sl;
          }

          @Override
          public void visitNullLiteral(NullLiteral nl) {
            res[0] = nl;
          }

          @Override
          public void visitSimpleConstant(SimpleConstant sl) {
            res[0] = sl;
          }

          @Override
          public void visitMethodInvocation(MethodInvocation mi) {
            res[0] =
                new Java.MethodInvocation(
                    mi.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(mi.optionalTarget),
                    mi.methodName,
                    UnparseTests.stripUnnecessaryParenExprs(mi.arguments));
          }

          @Override
          public void visitNewAnonymousClassInstance(NewAnonymousClassInstance naci) {
            res[0] = naci; // too much effort
          }

          @Override
          public void visitNewArray(NewArray na) {
            res[0] =
                new Java.NewArray(
                    na.getLocation(),
                    na.type,
                    UnparseTests.stripUnnecessaryParenExprs(na.dimExprs),
                    na.dims);
          }

          @Override
          public void visitNewClassInstance(NewClassInstance nci) {
            res[0] =
                new Java.NewClassInstance(
                    nci.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(nci.optionalQualification),
                    nci.type,
                    UnparseTests.stripUnnecessaryParenExprs(nci.arguments));
          }

          @Override
          public void visitNewInitializedArray(NewInitializedArray nia) {
            res[0] = nia; // too much effort
          }

          @Override
          public void visitParameterAccess(ParameterAccess pa) {
            res[0] = pa;
          }

          @Override
          public void visitQualifiedThisReference(QualifiedThisReference qtr) {
            res[0] = qtr;
          }

          @Override
          public void visitSuperclassMethodInvocation(SuperclassMethodInvocation smi) {
            res[0] =
                new Java.SuperclassMethodInvocation(
                    smi.getLocation(),
                    smi.methodName,
                    UnparseTests.stripUnnecessaryParenExprs(smi.arguments));
          }

          @Override
          public void visitThisReference(ThisReference tr) {
            res[0] = tr;
          }

          @Override
          public void visitUnaryOperation(UnaryOperation uo) {
            res[0] =
                new Java.UnaryOperation(
                    uo.getLocation(),
                    uo.operator,
                    UnparseTests.stripUnnecessaryParenExprs(uo.operand));
          }

          @Override
          public void visitAmbiguousName(AmbiguousName an) {
            res[0] = an;
          }

          @Override
          public void visitArrayAccessExpression(ArrayAccessExpression aae) {
            res[0] =
                new Java.ArrayAccessExpression(
                    aae.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(aae.lhs),
                    UnparseTests.stripUnnecessaryParenExprs(aae.index));
          }

          @Override
          public void visitFieldAccess(FieldAccess fa) {
            res[0] =
                new Java.FieldAccess(
                    fa.getLocation(), UnparseTests.stripUnnecessaryParenExprs(fa.lhs), fa.field);
          }

          @Override
          public void visitFieldAccessExpression(FieldAccessExpression fae) {
            res[0] =
                new Java.FieldAccessExpression(
                    fae.getLocation(),
                    UnparseTests.stripUnnecessaryParenExprs(fae.lhs),
                    fae.fieldName);
          }

          @Override
          public void visitLocalVariableAccess(LocalVariableAccess lva) {
            res[0] = lva;
          }

          @Override
          public void visitParenthesizedExpression(ParenthesizedExpression pe) {
            res[0] = UnparseTests.stripUnnecessaryParenExprs(pe.value);
          }

          @Override
          public void visitSuperclassFieldAccessExpression(SuperclassFieldAccessExpression scfae) {
            res[0] = scfae;
          }
        };
    rvalue.accept(rv);
    return res[0];
  }