org.checkerframework.dataflow.cfg.builder.TryFinallyScopeMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
The Checker Framework enhances Java's type system to
make it more powerful and useful. This lets software developers
detect and prevent errors in their Java programs.
The Checker Framework includes compiler plug-ins ("checkers")
that find bugs or verify their absence. It also permits you to
write your own compiler plug-ins.
package org.checkerframework.dataflow.cfg.builder;
import java.util.HashMap;
import java.util.Map;
import javax.lang.model.element.Name;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.plumelib.util.ArrayMap;
/**
* A map that keeps track of new labels added within a try block. For names that are outside of the
* try block, the finally label is returned. This ensures that a finally block is executed when
* control flows outside of the try block.
*/
@SuppressWarnings("serial")
/*package-private*/ class TryFinallyScopeMap extends HashMap {
/** New labels within a try block that were added by this implementation. */
private final Map accessedNames;
/** Create a new TryFinallyScopeMap. */
protected TryFinallyScopeMap() {
this.accessedNames = new ArrayMap<>(2);
}
@Override
public Label get(@Nullable Object key) {
if (key == null) {
throw new IllegalArgumentException();
}
if (super.containsKey(key)) {
return super.get(key);
} else {
if (accessedNames.containsKey(key)) {
return accessedNames.get(key);
}
Label l = new Label();
accessedNames.put((Name) key, l);
return l;
}
}
@Override
@SuppressWarnings("keyfor:contracts.conditional.postcondition") // get adds everything
public boolean containsKey(@Nullable Object key) {
return true;
}
public Map getAccessedNames() {
return accessedNames;
}
}