Move stored value creation into StoredValues
Methods that compute and store certain values when needed now occur during StoredValues.<Type>.get() for those stored values. If the interpreter does not have a value, it will create one using createValue() and then store it in the interpreter's hash map. By default, createValue() returns null (which throws an exception in get()). To use it, override it with code that computes the desired value for a certain type. StoredValue also now uses Java Object instead of JavaObjectTerm for its key. Some existing predicates have also been refactored to not create values on their own. Change-Id: Ia3d44169f86526c0c16f9580f3d52d04b0b83b2b
This commit is contained in:
@@ -82,19 +82,4 @@ abstract class AbstractCommitUserIdentityPredicate extends Predicate.P3 {
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
protected PatchSetInfo getPatchSetInfo(Prolog engine)
|
||||
throws PatchSetInfoNotAvailableException {
|
||||
PrologEnvironment env = (PrologEnvironment) engine.control;
|
||||
PatchSetInfo psInfo = env.get(StoredValues.PATCH_SET_INFO);
|
||||
if (psInfo == null) {
|
||||
PatchSet.Id patchSetId = env.get(StoredValues.PATCH_SET_ID);
|
||||
PatchSetInfoFactory patchInfoFactory =
|
||||
env.getInjector().getInstance(PatchSetInfoFactory.class);
|
||||
psInfo = patchInfoFactory.get(patchSetId);
|
||||
env.set(StoredValues.PATCH_SET_INFO, psInfo);
|
||||
}
|
||||
|
||||
return psInfo;
|
||||
}
|
||||
}
|
@@ -16,9 +16,8 @@ package gerrit;
|
||||
|
||||
import com.google.gerrit.reviewdb.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.UserIdentity;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.rules.StoredValues;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.JavaException;
|
||||
import com.googlecode.prolog_cafe.lang.Operation;
|
||||
import com.googlecode.prolog_cafe.lang.Prolog;
|
||||
import com.googlecode.prolog_cafe.lang.PrologException;
|
||||
@@ -33,12 +32,7 @@ public class PRED_commit_author_3 extends AbstractCommitUserIdentityPredicate {
|
||||
|
||||
@Override
|
||||
public Operation exec(Prolog engine) throws PrologException {
|
||||
PatchSetInfo psInfo;
|
||||
try {
|
||||
psInfo = getPatchSetInfo(engine);
|
||||
} catch (PatchSetInfoNotAvailableException err) {
|
||||
throw new JavaException(this, 1, err);
|
||||
}
|
||||
PatchSetInfo psInfo = StoredValues.PATCH_SET_INFO.get(engine);
|
||||
UserIdentity author = psInfo.getAuthor();
|
||||
return exec(engine, author);
|
||||
}
|
||||
|
@@ -16,9 +16,8 @@ package gerrit;
|
||||
|
||||
import com.google.gerrit.reviewdb.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.UserIdentity;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.rules.StoredValues;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.JavaException;
|
||||
import com.googlecode.prolog_cafe.lang.Operation;
|
||||
import com.googlecode.prolog_cafe.lang.Prolog;
|
||||
import com.googlecode.prolog_cafe.lang.PrologException;
|
||||
@@ -33,12 +32,7 @@ public class PRED_commit_committer_3 extends AbstractCommitUserIdentityPredicate
|
||||
|
||||
@Override
|
||||
public Operation exec(Prolog engine) throws PrologException {
|
||||
PatchSetInfo psInfo;
|
||||
try {
|
||||
psInfo = getPatchSetInfo(engine);
|
||||
} catch (PatchSetInfoNotAvailableException err) {
|
||||
throw new JavaException(this, 1, err);
|
||||
}
|
||||
PatchSetInfo psInfo = StoredValues.PATCH_SET_INFO.get(engine);
|
||||
UserIdentity committer = psInfo.getCommitter();
|
||||
return exec(engine, committer);
|
||||
}
|
||||
|
@@ -14,23 +14,13 @@
|
||||
|
||||
package gerrit;
|
||||
|
||||
import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.Patch;
|
||||
import com.google.gerrit.reviewdb.PatchSet;
|
||||
import com.google.gerrit.reviewdb.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gerrit.rules.PrologEnvironment;
|
||||
import com.google.gerrit.rules.StoredValues;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListEntry;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.IllegalTypeException;
|
||||
import com.googlecode.prolog_cafe.lang.JavaException;
|
||||
import com.googlecode.prolog_cafe.lang.JavaObjectTerm;
|
||||
import com.googlecode.prolog_cafe.lang.Operation;
|
||||
import com.googlecode.prolog_cafe.lang.PInstantiationException;
|
||||
@@ -40,8 +30,6 @@ import com.googlecode.prolog_cafe.lang.PrologException;
|
||||
import com.googlecode.prolog_cafe.lang.SymbolTerm;
|
||||
import com.googlecode.prolog_cafe.lang.Term;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -92,15 +80,8 @@ public class PRED_commit_delta_4 extends Predicate.P4 {
|
||||
engine.areg3 = arg3;
|
||||
engine.areg4 = arg4;
|
||||
|
||||
PrologEnvironment env = (PrologEnvironment) engine.control;
|
||||
PatchSetInfo psInfo;
|
||||
try {
|
||||
psInfo = getPatchSetInfo(env);
|
||||
} catch (PatchSetInfoNotAvailableException err) {
|
||||
throw new JavaException(this, 1, err);
|
||||
}
|
||||
|
||||
PatchList pl = getPatchList(env, psInfo);
|
||||
PatchSetInfo psInfo = StoredValues.PATCH_SET_INFO.get(engine);
|
||||
PatchList pl = StoredValues.PATCH_LIST.get(engine);
|
||||
Iterator<PatchListEntry> iter = pl.getPatches().iterator();
|
||||
|
||||
engine.areg5 = new JavaObjectTerm(iter);
|
||||
@@ -188,35 +169,4 @@ public class PRED_commit_delta_4 extends Predicate.P4 {
|
||||
}
|
||||
throw new IllegalArgumentException("ChangeType not recognized");
|
||||
}
|
||||
|
||||
protected PatchSetInfo getPatchSetInfo(PrologEnvironment env)
|
||||
throws PatchSetInfoNotAvailableException {
|
||||
PatchSetInfo psInfo = env.get(StoredValues.PATCH_SET_INFO);
|
||||
if (psInfo == null) {
|
||||
PatchSet.Id patchSetId = env.get(StoredValues.PATCH_SET_ID);
|
||||
PatchSetInfoFactory patchInfoFactory =
|
||||
env.getInjector().getInstance(PatchSetInfoFactory.class);
|
||||
psInfo = patchInfoFactory.get(patchSetId);
|
||||
env.set(StoredValues.PATCH_SET_INFO, psInfo);
|
||||
}
|
||||
|
||||
return psInfo;
|
||||
}
|
||||
|
||||
protected PatchList getPatchList(PrologEnvironment env, PatchSetInfo psInfo) {
|
||||
PatchList patchList = env.get(StoredValues.PATCH_LIST);
|
||||
if (patchList == null) {
|
||||
PatchListCache plCache = env.getInjector().getInstance(PatchListCache.class);
|
||||
Change change = env.get(StoredValues.CHANGE);
|
||||
Project.NameKey projectKey = change.getProject();
|
||||
ObjectId a = null;
|
||||
ObjectId b = ObjectId.fromString(psInfo.getRevId());
|
||||
Whitespace ws = Whitespace.IGNORE_NONE;
|
||||
PatchListKey plKey = new PatchListKey(projectKey, a, b, ws);
|
||||
patchList = plCache.get(plKey);
|
||||
env.set(StoredValues.PATCH_LIST, patchList);
|
||||
}
|
||||
|
||||
return patchList;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user