This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c03633
commit 788a5f6
Showing
11 changed files
with
504 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
gcontracts-core/src/main/java/org/gcontracts/CyclicAssertionCallException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2011, Andre Steingress | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
* following conditions are met: | ||
* | ||
* 1.) Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* 2.) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided with the distribution. | ||
* 3.) Neither the name of Andre Steingress nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.gcontracts; | ||
|
||
/** | ||
* Thrown whenever pre- or post-conditions are called in a cyclic way. | ||
* | ||
* @author ast | ||
*/ | ||
public class CyclicAssertionCallException extends RuntimeException { | ||
|
||
public CyclicAssertionCallException() { | ||
} | ||
|
||
public CyclicAssertionCallException(String s) { | ||
super(s); | ||
} | ||
|
||
public CyclicAssertionCallException(String s, Throwable throwable) { | ||
super(s, throwable); | ||
} | ||
|
||
public CyclicAssertionCallException(Throwable throwable) { | ||
super(throwable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
gcontracts-core/src/main/java/org/gcontracts/generation/CyclicAssertionCallInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2011, Andre Steingress | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
* following conditions are met: | ||
* | ||
* 1.) Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* 2.) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided with the distribution. | ||
* 3.) Neither the name of Andre Steingress nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.gcontracts.generation; | ||
|
||
import groovy.lang.Interceptor; | ||
import org.gcontracts.CyclicAssertionCallException; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* {@link Interceptor} implementation which checks for cyclic method calls - as these need to be avoided | ||
* in contract definitions. | ||
* | ||
* @see Interceptor | ||
* | ||
* @author ast | ||
*/ | ||
public class CyclicAssertionCallInterceptor implements Interceptor { | ||
|
||
private List<String> callStack = new LinkedList<String>(); | ||
|
||
@Override | ||
public Object beforeInvoke(Object object, String methodName, Object[] arguments) { | ||
if (callStack.contains(methodName)) throw new CyclicAssertionCallException("Method '" + methodName + "' has already been called from the current assertion - assertion call cycle detected!"); | ||
callStack.add(methodName); | ||
System.out.println("ADDED " + methodName); | ||
return object; | ||
} | ||
|
||
@Override | ||
public Object afterInvoke(Object object, String methodName, Object[] arguments, Object result) { | ||
callStack.remove(methodName); | ||
System.out.println("REMOVED " + methodName); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean doInvoke() { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.