Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for aliasing #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions static/examples/aliasing/AliasingExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.*;
import org.checkerframework.checker.aliasing.qual.*;

// Annotations on the StringBuffer class, used in the examples below.
// class StringBuffer {
// @Unique StringBuffer();
// StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked String s);
// }

public class AliasingExample {
public void foo() {
StringBuffer sb = new StringBuffer(); // sb is refined to @Unique.

StringBuffer sb2 = sb; // sb loses its refinement.
// Both sb and sb2 have aliases and because of that have type @MaybeAliased.
}

public void bar() {
StringBuffer sb = new StringBuffer(); // sb is refined to @Unique.

sb.append("someString");
// sb stays @Unique, as no aliases are created.

StringBuffer sb2 = sb.append("someString");
// sb is leaked and becomes @MaybeAliased.

// Both sb and sb2 have aliases and because of that have type @MaybeAliased.
}
}


3 changes: 3 additions & 0 deletions static/js/cf-load-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var JAVA_EXAMPLES = {
/*GUIEffect Checker examples*/
GUIEffectExampleWithWarningsLink: 'examples/gui_effect/GUIEffectExampleWithWarnings.java',

/*Aliasing Checker examples*/
AliasingExample: 'examples/aliasing/AliasingExample.java',

/*Units Checker examples*/
SimpleDemoWithWarningsLink: 'examples/units/SimpleDemoWithWarnings.java',
MethodsDemoWithWarningsLink: 'examples/units/MethodsDemoWithWarnings.java',
Expand Down
1 change: 1 addition & 0 deletions views/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

<p data-checker-type="aliasing">
Aliasing (<a class="manualLink" href="https://checkerframework.org/manual/#aliasing-checker" target="_blank"><i>manual</i></a>)
<a class="manualLink" id="AliasingExample" href="#">AliasChecker</a>
</p>

<!-- <p data-checker-type="igj">
Expand Down