StandaloneExp extends Exp { public void insertBefore(CtBehavior behavior) throws CannotCompileException { if (isEmpty()) { return; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("insert before " + behavior.getLongName() + ": " + this); } if (isInitializer(behavior)) { ((CtConstructor) behavior).insertBeforeBody(getInsertCode(getCode())); } else { behavior.insertBefore(getInsertCode(getCode())); } }  StandaloneExp append(StandaloneExp other); StandaloneExp append(NestedExp other); @Override abstract String getCode(); void insertBefore(CtBehavior behavior); void insertAfter(CtBehavior behavior); void insertCatch(CtClass exceptionType, CtBehavior behavior); void insertFinally(CtBehavior behavior); void replace(Expr expression); boolean isEmpty(); static final StandaloneExp PROCEED_AND_ASSIGN; }
@Test public void testInsertBeforeWithMethod() throws Exception { CtBehavior behavior = mock(CtMethod.class); StandaloneExp exp = new IfExp(BooleanExp.TRUE); exp.insertBefore(behavior); verify(behavior).insertBefore("{ \nif (true) {\n} }"); }
@Test public void testInsertBeforeWithConstructor() throws Exception { CtConstructor behavior = mock(CtConstructor.class); when(behavior.isClassInitializer()).thenReturn(Boolean.FALSE); StandaloneExp exp = new IfExp(BooleanExp.TRUE); exp.insertBefore(behavior); verify(behavior).insertBeforeBody("{ \nif (true) {\n} }"); }
@Test public void testInsertBeforeWithInitializer() throws Exception { CtConstructor behavior = mock(CtConstructor.class); when(behavior.isClassInitializer()).thenReturn(Boolean.TRUE); StandaloneExp exp = new IfExp(BooleanExp.TRUE); exp.insertBefore(behavior); verify(behavior).insertBefore("{ \nif (true) {\n} }"); }