All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.checkerframework.dataflow.cfg.block.BlockImpl Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.44.0
Show newest version
package org.checkerframework.dataflow.cfg.block;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.checkerframework.checker.initialization.qual.UnknownInitialization;

/** Base class of the {@link Block} implementation hierarchy. */
public abstract class BlockImpl implements Block {

  /** The type of this basic block. */
  protected final BlockType type;

  /** The set of predecessors. */
  protected final Set predecessors;

  /** The unique ID for the next-created object. */
  static final AtomicLong nextUid = new AtomicLong(0);
  /** The unique ID of this object. */
  final long uid = nextUid.getAndIncrement();
  /**
   * Returns the unique ID of this object.
   *
   * @return the unique ID of this object
   */
  @Override
  public long getUid(@UnknownInitialization BlockImpl this) {
    return uid;
  }

  /**
   * Create a new BlockImpl.
   *
   * @param type the type of this basic block
   */
  protected BlockImpl(BlockType type) {
    this.type = type;
    this.predecessors = new LinkedHashSet<>();
  }

  @Override
  public BlockType getType() {
    return type;
  }

  @Override
  public Set getPredecessors() {
    // Not "Collections.unmodifiableSet(predecessors)" which has nondeterministic iteration order.
    return new LinkedHashSet<>(predecessors);
  }

  public void addPredecessor(BlockImpl pred) {
    predecessors.add(pred);
  }

  public void removePredecessor(BlockImpl pred) {
    predecessors.remove(pred);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy