Skip to content

Commit

Permalink
(1) Introduced some Java 17 syntax, (2) included the jar and the Java…
Browse files Browse the repository at this point in the history
… 17 example class, (3) reformat the code I added to comply with Google Java Style Guide
  • Loading branch information
mayaba committed Aug 12, 2023
1 parent edd2e5e commit 52dc457
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void setDepClasspath(String _dependenciesClasspath) {
/**
* {@inheritDoc}
*
* Filter and find all entrypoints in scope
* <p>Filter and find all entrypoints in scope
*/
public void setEntrypoints(Set<org.eclipse.steady.shared.json.model.ConstructId> _constructs)
throws CallgraphConstructException {
Expand Down Expand Up @@ -333,7 +333,7 @@ public Configuration getConstructorConfiguration() {
/**
* {@inheritDoc}
*
* Parse command line arguments, and then build callgraph based on these properties
* <p>Parse command line arguments, and then build callgraph based on these properties
*/
public void buildCallgraph(boolean _policy) throws CallgraphConstructException {
WalaCallgraphConstructor.log.info(
Expand Down Expand Up @@ -377,7 +377,8 @@ public void buildCallgraph(boolean _policy) throws CallgraphConstructException {
} else if (cg_algorithm.equals("0-ctn-CFA")) {
builder = Util.makeZeroContainerCFABuilder(options, cache, this.cha, this.scope);
} else if (cg_algorithm.equals("vanilla-0-1-CFA")) {
builder = Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, cache, this.cha, this.scope);
builder =
Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, cache, this.cha, this.scope);
} else if (cg_algorithm.equals("0-1-CFA")) {
builder = Util.makeZeroOneCFABuilder(Language.JAVA, options, cache, this.cha, this.scope);
} else if (cg_algorithm.equals("0-1-ctn-CFA")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,17 @@ public void examplesWalaTestJdk17() {
// Set the EP manually
final Set<ConstructId> entrypoint = new HashSet<ConstructId>();
entrypoint.add(
JavaId.toSharedType(
JavaId.parseMethodQName("org.example.Examples.main(String[])")));
JavaId.toSharedType(JavaId.parseMethodQName("org.example.ExamplesJdk17.main(String[])")));
ra.setEntryPoints(entrypoint, PathSource.A2C, false);
ra.setAppConstructs(entrypoint);

// Set the target constructs (manually, rather than using a bug)
final Map<String, Set<ConstructId>> target_constructs = new HashMap<String, Set<ConstructId>>();
final Set<ConstructId> changes = new HashSet<ConstructId>();
changes.add(
JavaId.toSharedType(
JavaId.parseMethodQName("org.example.Cat.saySomething()")));
changes.add(
JavaId.toSharedType(
JavaId.parseMethodQName("org.example.Fish.saySomething()")));
changes.add(
JavaId.toSharedType(
JavaId.parseMethodQName("org.example.Dog.saySomething()")));
changes.add(
JavaId.toSharedType(
JavaId.parseMethodQName("org.example.Car.saySomething()")));
changes.add(JavaId.toSharedType(JavaId.parseMethodQName("org.example.Cat.saySomething()")));
changes.add(JavaId.toSharedType(JavaId.parseMethodQName("org.example.Fish.saySomething()")));
changes.add(JavaId.toSharedType(JavaId.parseMethodQName("org.example.Dog.saySomething()")));
changes.add(JavaId.toSharedType(JavaId.parseMethodQName("org.example.Car.saySomething()")));
target_constructs.put("does-not-exist", changes);
ra.setTargetConstructs(target_constructs);

Expand Down
80 changes: 80 additions & 0 deletions lang-java-reach-wala/src/test/resources/ExamplesJdk17.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* This file is part of Eclipse Steady.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Copyright (c) 2018-2020 SAP SE or an SAP affiliate company and Eclipse Steady contributors
*/
package org.example;

import java.util.SortedSet;
import java.util.TreeSet;

sealed abstract class Animal implements Comparable<Animal> permits Cat, Dog, Fish {

public abstract void saySomething();

public int compareTo(Animal _a) {
return getClass().getName().compareTo(_a.getClass().getName());
}
}

final class Cat extends Animal {
public void saySomething() {
System.out.println("purr");
}
}

final class Dog extends Animal {
public void saySomething() {
System.out.println("woof");
}
}

final class Fish extends Animal {
public void saySomething() {
System.out.println("...");
}
}

class Car {
public void saySomething() {
System.out.println("honk!");
}
}

public class ExamplesJdk17 {
static SortedSet<Animal> animals = new TreeSet<>();

private static Animal createFish() {
return new Fish();
}

private static Animal createCat() {
Animal cat = new Cat();
animals.add(cat);
return cat;
}

public static void main(String[] args) {
Animal animal;
if (args.length == 0) {
animal = createCat();
animal.saySomething();
} else {
animal = createFish();
animal.saySomething();
}
}
}
Binary file modified lang-java-reach-wala/src/test/resources/examplesJdk17.jar
Binary file not shown.

0 comments on commit 52dc457

Please sign in to comment.