package org.eclipse.jdt.internal.compiler.env;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.util.SimpleSetOfCharArray;
public interface IUpdatableModule {
enum UpdateKind { MODULE, PACKAGE }
class AddExports implements Consumer<IUpdatableModule> {
char[] name;
char[][] targets;
public AddExports(char[] pkgName, char[][] targets) {
this.name = pkgName;
this.targets = targets;
}
@Override
public void accept(IUpdatableModule t) {
t.addExports(this.name, this.targets);
}
public char[] getName() {
return this.name;
}
public char[][] getTargetModules() {
return this.targets;
}
public UpdateKind getKind() {
return UpdateKind.PACKAGE;
}
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof AddExports)) return false;
AddExports pu = (AddExports) other;
if (!CharOperation.equals(this.name, pu.name))
return false;
if (!CharOperation.equals(this.targets, pu.targets))
return false;
return true;
}
@Override
public int hashCode() {
int hash = CharOperation.hashCode(this.name);
if (this.targets != null) {
for (int i = 0; i < this.targets.length; i++) {
hash += 17 * CharOperation.hashCode(this.targets[i]);
}
}
return hash;
}
}
class AddReads implements Consumer<IUpdatableModule> {
char[] targetModule;
public AddReads(char[] target) {
this.targetModule = target;
}
@Override
public void accept(IUpdatableModule t) {
t.addReads(this.targetModule);
}
public char[] getTarget() {
return this.targetModule;
}
public UpdateKind getKind() {
return UpdateKind.MODULE;
}
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof AddReads)) return false;
AddReads mu = (AddReads) other;
return CharOperation.equals(this.targetModule, mu.targetModule);
}
@Override
public int hashCode() {
return CharOperation.hashCode(this.targetModule);
}
}
class UpdatesByKind {
List<Consumer<IUpdatableModule>> moduleUpdates = Collections.emptyList();
List<Consumer<IUpdatableModule>> packageUpdates = Collections.emptyList();
public List<Consumer<IUpdatableModule>> getList(UpdateKind kind, boolean create) {
switch (kind) {
case MODULE:
if (this.moduleUpdates == Collections.EMPTY_LIST && create)
this.moduleUpdates = new ArrayList<>();
return this.moduleUpdates;
case PACKAGE:
if (this.packageUpdates == Collections.EMPTY_LIST && create)
this.packageUpdates = new ArrayList<>();
return this.packageUpdates;
default:
throw new IllegalArgumentException("Unknown enum value "+kind);
}
}
}
char[] name();
void addReads(char[] moduleName);
void addExports(char[] packageName, char[][] targetModules);
void setMainClassName(char[] mainClassName);
void setPackageNames(SimpleSetOfCharArray packageNames);
}