code
stringlengths 23
201k
| docstring
stringlengths 17
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
72
| path
stringlengths 11
317
| url
stringlengths 57
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
@SuppressWarnings("unchecked")
protected static final <K, V> ImmutableMap<K, V> mapOf(K k0, V v0, Object... rest) {
Preconditions.checkArgument(rest.length % 2 == 0, "Uneven args: %s", rest.length);
ImmutableMap.Builder<K, V> builder = new ImmutableMap.Builder<>();
builder.put(k0, v0);
for (int i = 0; i < rest.length; i += 2) {
builder.put((K) rest[i], (V) rest[i + 1]);
}
return builder.buildOrThrow();
}
|
Expects the current {@link ExpectFailure} failure message to NOT match the provided regex,
using {@code Pattern.DOTALL} to match newlines.
|
mapOf
|
java
|
google/truth
|
extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
Apache-2.0
|
@SuppressWarnings("unchecked")
protected static final <K, V> ImmutableMultimap<K, V> multimapOf(K k0, V v0, Object... rest) {
Preconditions.checkArgument(rest.length % 2 == 0, "Uneven args: %s", rest.length);
ImmutableMultimap.Builder<K, V> builder = new ImmutableMultimap.Builder<>();
builder.put(k0, v0);
for (int i = 0; i < rest.length; i += 2) {
builder.put((K) rest[i], (V) rest[i + 1]);
}
return builder.build();
}
|
Expects the current {@link ExpectFailure} failure message to NOT match the provided regex,
using {@code Pattern.DOTALL} to match newlines.
|
multimapOf
|
java
|
google/truth
|
extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
Apache-2.0
|
final void checkMethodNamesEndWithForValues(
Class<?> clazz, Class<? extends Subject> pseudoSuperclass) {
// Don't run this test twice.
if (!testIsRunOnce()) {
return;
}
Set<String> diff = Sets.difference(getMethodNames(clazz), getMethodNames(pseudoSuperclass));
assertWithMessage("Found no methods to test. Bug in test?").that(diff).isNotEmpty();
for (String methodName : diff) {
assertThat(methodName).endsWith("ForValues");
}
}
|
Expects the current {@link ExpectFailure} failure message to NOT match the provided regex,
using {@code Pattern.DOTALL} to match newlines.
|
checkMethodNamesEndWithForValues
|
java
|
google/truth
|
extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
Apache-2.0
|
private static ImmutableSet<String> getMethodNames(Class<?> clazz) {
ImmutableSet.Builder<String> names = ImmutableSet.builder();
for (Method method : clazz.getMethods()) {
names.add(method.getName());
}
return names.build();
}
|
Expects the current {@link ExpectFailure} failure message to NOT match the provided regex,
using {@code Pattern.DOTALL} to match newlines.
|
getMethodNames
|
java
|
google/truth
|
extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
Apache-2.0
|
public static Subject.Factory<Re2jStringSubject, String> re2jString() {
return Re2jStringSubject::new;
}
|
Returns a subject factory for {@link String} subjects which you can use to assert things about
{@link com.google.re2j.Pattern} regexes.
<p>This subject does not replace Truth's built-in {@link com.google.common.truth.StringSubject}
but instead provides only the methods needed to deal with regular expressions.
@see com.google.common.truth.StringSubject
|
re2jString
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@Override
protected String actualCustomStringRepresentation() {
return quote(checkNotNull(actual));
}
|
Subject for {@link String} subjects which you can use to assert things about {@link
com.google.re2j.Pattern} regexes.
@see #re2jString
|
actualCustomStringRepresentation
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
public void matches(String regex) {
if (!Pattern.matches(regex, checkNotNull(actual))) {
failWithActual("expected to match ", regex);
}
}
|
Fails if the string does not match the given regex.
|
matches
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@GwtIncompatible("com.google.re2j.Pattern")
public void matches(Pattern regex) {
if (!regex.matcher(checkNotNull(actual)).matches()) {
failWithActual("expected to match ", regex);
}
}
|
Fails if the string does not match the given regex.
|
matches
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
public void doesNotMatch(String regex) {
if (Pattern.matches(regex, checkNotNull(actual))) {
failWithActual("expected to fail to match", regex);
}
}
|
Fails if the string matches the given regex.
|
doesNotMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@GwtIncompatible("com.google.re2j.Pattern")
public void doesNotMatch(Pattern regex) {
if (regex.matcher(checkNotNull(actual)).matches()) {
failWithActual("expected to fail to match", regex);
}
}
|
Fails if the string matches the given regex.
|
doesNotMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@GwtIncompatible("com.google.re2j.Pattern")
public void containsMatch(Pattern pattern) {
if (!pattern.matcher(checkNotNull(actual)).find()) {
failWithActual("expected to contain a match for", pattern);
}
}
|
Fails if the string does not contain a match on the given regex.
|
containsMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
public void containsMatch(String regex) {
if (!doContainsMatch(checkNotNull(actual), regex)) {
failWithActual("expected to contain a match for", regex);
}
}
|
Fails if the string does not contain a match on the given regex.
|
containsMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@GwtIncompatible("com.google.re2j.Pattern")
public void doesNotContainMatch(Pattern pattern) {
if (pattern.matcher(checkNotNull(actual)).find()) {
failWithActual("expected not to contain a match for", pattern);
}
}
|
Fails if the string contains a match on the given regex.
|
doesNotContainMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
public void doesNotContainMatch(String regex) {
if (doContainsMatch(checkNotNull(actual), regex)) {
failWithActual("expected not to contain a match for", regex);
}
}
|
Fails if the string contains a match on the given regex.
|
doesNotContainMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
private static String quote(CharSequence toBeWrapped) {
return "\"" + toBeWrapped + "\"";
}
|
Fails if the string contains a match on the given regex.
|
quote
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
private static boolean doContainsMatch(String subject, String regex) {
return Pattern.compile(regex).matcher(subject).find();
}
|
Fails if the string contains a match on the given regex.
|
doContainsMatch
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
if (!isCorrespondence(tree.getExtendsClause(), state)) {
return NO_MATCH;
}
List<CorrespondenceCode> replacements = computePossibleReplacements(tree, state);
Tree parent = state.getPath().getParentPath().getLeaf();
if (parent.getKind() == NEW_CLASS) {
// Anonymous class. Replace the whole `new Correspondence` with a Correspondence.from call.
for (CorrespondenceCode replacement : replacements) {
SuggestedFix.Builder fix = SuggestedFix.builder();
fix.replace(parent, replacement.callSite());
Tree methodOrField = findChildOfStrictlyEnclosing(state, ClassTree.class);
/*
* If a class declares multiple anonymous Correspondences, we might end up creating multiple
* compare() methods in the same scope. We might get away with it, depending on the types
* involved, or we might need to manually rename some.
*/
fix.postfixWith(methodOrField, replacement.supportingMethodDefinition());
if (compilesWithFix(fix.build(), state)) {
return describeMatch(parent, fix.build());
}
}
return NO_MATCH;
}
Symbol classSymbol = getDeclaredSymbol(tree);
/*
* Named class. Create a Correspondence.from call, but then decide where to put it:
*
* The "safest" thing to do is to replace the body of the class with...
*
* static final Correspondence INSTANCE = Correspondence.from(...);
*
* ...and then make all callers refer to that. (As long as the class isn't top-level, we can
* even delete the class entirely, putting the constant in its place.)
*
* The other option is to inline that into all use sites. That's a great option if there's a
* single use site in a constant or helper method, in which case we produce code like...
*
* private static Correspondence makeCorrespondence() {
* return Correspondence.from(...);
* }
*
* But the danger of inlining is twofold:
*
* 1. If there are multiple callers, we'd duplicate the definition of the Correspondence.
*
* 2. Even if there's only one caller, we might inline a large chunk of code into the middle of
* a comparingElementsUsing call.
*
* So we use the "safe" option unless (a) there's exactly one call and (b) it's not inside a
* comparingElementsUsing call.
*/
SetMultimap<ParentType, NewClassTree> calls = findCalls(classSymbol, state);
/*
* We also sometime see users use the named type for fields and return types, like...
*
* static final MyCorrespondence INSTANCE = new MyCorrespondence();
*
* We need to replace that with the generic Correspondence type, like...
*
* static final Correspondence<String, Integer> INSTANCE = ...;
*/
Set<Tree> typeReferences = findTypeReferences(classSymbol, state);
if (calls.size() == 1 && getOnlyElement(calls.keys()) == ParentType.OTHER) {
// Inline it.
Tree call = getOnlyElement(calls.values());
for (CorrespondenceCode replacement : replacements) {
SuggestedFix.Builder fix = SuggestedFix.builder();
replaceTypeReferences(fix, typeReferences, state.getSourceForNode(tree.getExtendsClause()));
fix.replace(call, replacement.callSite());
fix.replace(tree, replacement.supportingMethodDefinition());
if (compilesWithFix(fix.build(), state)) {
return describeMatch(tree, fix.build());
}
}
return NO_MATCH;
}
// Declare a constant, and make use sites refer to that.
/*
* If we can't find any callers, then they're probably in other files, so we're going to be
* stuck updating them manually. To make the manual updates as simple as possible, we'll declare
* a constant named INSTANCE inside the Correspondence subclass (though it won't be a
* Correspondence subclass after our changes, just a holder class).
*/
if (calls.isEmpty()) {
for (CorrespondenceCode replacement : replacements) {
SuggestedFix.Builder fix = SuggestedFix.builder();
replaceTypeReferences(fix, typeReferences, state.getSourceForNode(tree.getExtendsClause()));
JCTree extendsClause = (JCTree) tree.getExtendsClause();
// Replace everything from `extends` to the end of the class, keeping only "class Foo."
int startOfExtends =
state
.getSourceCode()
.subSequence(0, extendsClause.getStartPosition())
.toString()
.lastIndexOf("extends");
fix.replace(
startOfExtends,
state.getEndPosition(tree),
format(
"{ %s static final %s INSTANCE = %s; %s }",
visibilityModifierOnConstructor(tree),
state.getSourceForNode(extendsClause),
replacement.callSite(),
replacement.supportingMethodDefinition()));
for (Tree call : calls.values()) {
fix.replace(call, tree.getSimpleName() + ".INSTANCE");
}
if (compilesWithFix(fix.build(), state)) {
return describeMatch(tree, fix.build());
}
}
return NO_MATCH;
}
/*
* We found callers. Let's optimistically assume that we found them all, in which case we might
* as well replace the whole class with a constant.
*/
for (CorrespondenceCode replacement : replacements) {
SuggestedFix.Builder fix = SuggestedFix.builder();
replaceTypeReferences(fix, typeReferences, state.getSourceForNode(tree.getExtendsClause()));
String name = CaseFormat.UPPER_CAMEL.to(UPPER_UNDERSCORE, tree.getSimpleName().toString());
// TODO(cpovirk): We're unlikely to get away with declaring everything `static`.
fix.replace(
tree,
format(
"%s static final %s %s = %s; %s",
visibilityModifierOnConstructor(tree),
state.getSourceForNode(tree.getExtendsClause()),
name,
replacement.callSite(),
replacement.supportingMethodDefinition()));
for (Tree call : calls.values()) {
fix.replace(call, name);
}
if (compilesWithFix(fix.build(), state)) {
return describeMatch(tree, fix.build());
}
}
return NO_MATCH;
}
|
Refactors some subclasses of {@code Correspondence} to instead call {@code Correspondence.from}.
The exact change generated for a given correspondence depends on the details of how it is defined
and used.
|
matchClass
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static void replaceTypeReferences(
SuggestedFix.Builder fix, Set<Tree> typeReferences, String newType) {
for (Tree reference : typeReferences) {
fix.replace(reference, newType);
}
}
|
Refactors some subclasses of {@code Correspondence} to instead call {@code Correspondence.from}.
The exact change generated for a given correspondence depends on the details of how it is defined
and used.
|
replaceTypeReferences
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private String visibilityModifierOnConstructor(ClassTree tree) {
MethodTree constructor =
tree.getMembers().stream()
.filter(t -> t instanceof MethodTree)
.map(t -> (MethodTree) t)
.filter(t -> t.getName().contentEquals("<init>"))
.findAny()
.get();
// We don't include the ModifiersTree directly in case it contains any annotations.
return constructor.getModifiers().getFlags().stream()
.filter(m -> m == PUBLIC || m == PROTECTED || m == PRIVATE)
.findAny()
.map(Modifier::toString)
.orElse("");
}
|
Refactors some subclasses of {@code Correspondence} to instead call {@code Correspondence.from}.
The exact change generated for a given correspondence depends on the details of how it is defined
and used.
|
visibilityModifierOnConstructor
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static SetMultimap<ParentType, NewClassTree> findCalls(
Symbol classSymbol, VisitorState state) {
SetMultimap<ParentType, NewClassTree> calls = HashMultimap.create();
new TreeScanner<Void, Void>() {
private ParentType parentType = ParentType.OTHER;
@Override
public @Nullable Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
boolean isComparingElementsUsing =
Optional.of(node.getMethodSelect())
.filter(t -> t.getKind() == MEMBER_SELECT)
.map(t -> (MemberSelectTree) t)
.filter(t -> t.getIdentifier().contentEquals("comparingElementsUsing"))
.isPresent();
if (isComparingElementsUsing) {
ParentType oldParentType = parentType;
parentType = ParentType.COMPARING_ELEMENTS_USING;
super.visitMethodInvocation(node, unused);
parentType = oldParentType;
} else {
super.visitMethodInvocation(node, unused);
}
return null;
}
@Override
public @Nullable Void visitNewClass(NewClassTree node, Void unused) {
if (getSymbol(node.getIdentifier()).equals(classSymbol)) {
calls.put(parentType, node);
}
return super.visitNewClass(node, unused);
}
}.scan(state.findEnclosing(CompilationUnitTree.class), null);
return calls;
}
|
Returns all calls to the constructor for the given {@code classSymbol}, organized by {@linkplain ParentType whether they happen inside a call to {@code comparingElementsUsing}.
|
findCalls
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
@Override
public @Nullable Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
boolean isComparingElementsUsing =
Optional.of(node.getMethodSelect())
.filter(t -> t.getKind() == MEMBER_SELECT)
.map(t -> (MemberSelectTree) t)
.filter(t -> t.getIdentifier().contentEquals("comparingElementsUsing"))
.isPresent();
if (isComparingElementsUsing) {
ParentType oldParentType = parentType;
parentType = ParentType.COMPARING_ELEMENTS_USING;
super.visitMethodInvocation(node, unused);
parentType = oldParentType;
} else {
super.visitMethodInvocation(node, unused);
}
return null;
}
|
Returns all calls to the constructor for the given {@code classSymbol}, organized by {@linkplain ParentType whether they happen inside a call to {@code comparingElementsUsing}.
|
visitMethodInvocation
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
@Override
public @Nullable Void visitNewClass(NewClassTree node, Void unused) {
if (getSymbol(node.getIdentifier()).equals(classSymbol)) {
calls.put(parentType, node);
}
return super.visitNewClass(node, unused);
}
|
Returns all calls to the constructor for the given {@code classSymbol}, organized by {@linkplain ParentType whether they happen inside a call to {@code comparingElementsUsing}.
|
visitNewClass
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static Set<Tree> findTypeReferences(Symbol classSymbol, VisitorState state) {
Set<Tree> references = new HashSet<>();
new TreeScanner<Void, Void>() {
@Override
public @Nullable Void scan(Tree node, Void unused) {
if (Objects.equals(getSymbol(node), classSymbol)
&& getDeclaredSymbol(node) == null // Don't touch the ClassTree that we're replacing.
) {
references.add(node);
}
return super.scan(node, unused);
}
@Override
public @Nullable Void visitNewClass(NewClassTree node, Void aVoid) {
scan(node.getEnclosingExpression(), null);
// Do NOT scan node.getIdentifier().
scan(node.getTypeArguments(), null);
scan(node.getArguments(), null);
scan(node.getClassBody(), null);
return null;
}
}.scan(state.findEnclosing(CompilationUnitTree.class), null);
return references;
}
|
Finds all references to the name of the given type, excluding (a) when the name is defined
(e.g, {@code public class MyCorrespondence}) and (b) calls to its constructor (e.g., {@code new
MyCorrespondence()}). The goal is to find every reference that we aren't already modifying so
that we can rewrite, e.g., fields of the given type.
|
findTypeReferences
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
@Override
public @Nullable Void scan(Tree node, Void unused) {
if (Objects.equals(getSymbol(node), classSymbol)
&& getDeclaredSymbol(node) == null // Don't touch the ClassTree that we're replacing.
) {
references.add(node);
}
return super.scan(node, unused);
}
|
Finds all references to the name of the given type, excluding (a) when the name is defined
(e.g, {@code public class MyCorrespondence}) and (b) calls to its constructor (e.g., {@code new
MyCorrespondence()}). The goal is to find every reference that we aren't already modifying so
that we can rewrite, e.g., fields of the given type.
|
scan
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
@Override
public @Nullable Void visitNewClass(NewClassTree node, Void aVoid) {
scan(node.getEnclosingExpression(), null);
// Do NOT scan node.getIdentifier().
scan(node.getTypeArguments(), null);
scan(node.getArguments(), null);
scan(node.getClassBody(), null);
return null;
}
|
Finds all references to the name of the given type, excluding (a) when the name is defined
(e.g, {@code public class MyCorrespondence}) and (b) calls to its constructor (e.g., {@code new
MyCorrespondence()}). The goal is to find every reference that we aren't already modifying so
that we can rewrite, e.g., fields of the given type.
|
visitNewClass
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static ImmutableList<CorrespondenceCode> computePossibleReplacements(
ClassTree classTree, VisitorState state) {
ImmutableSetMultimap<MemberType, Tree> members =
classTree.getMembers().stream()
.collect(toImmutableSetMultimap(m -> MemberType.from(m, state), m -> m));
if (members.containsKey(MemberType.OTHER)
|| members.get(CONSTRUCTOR).size() != 1
|| members.get(COMPARE_METHOD).size() != 1
|| members.get(TO_STRING_METHOD).size() != 1) {
return ImmutableList.of();
}
MethodTree constructor = (MethodTree) getOnlyElement(members.get(CONSTRUCTOR));
MethodTree compareMethod = (MethodTree) getOnlyElement(members.get(COMPARE_METHOD));
MethodTree toStringMethod = (MethodTree) getOnlyElement(members.get(TO_STRING_METHOD));
if (!constructorCallsOnlySuper(constructor)) {
return ImmutableList.of();
}
ImmutableList<BinaryPredicateCode> binaryPredicates =
makeBinaryPredicates(classTree, compareMethod, state);
ExpressionTree toStringReturns = returnExpression(toStringMethod);
if (toStringReturns == null) {
return ImmutableList.of();
}
/*
* Replace bad toString() implementations that merely `return null`, since the factories make
* that an immediate error.
*/
String description =
toStringReturns.getKind() == NULL_LITERAL
? "\"corresponds to\""
: state.getSourceForNode(toStringReturns);
return binaryPredicates.stream()
.map(p -> CorrespondenceCode.create(p, description))
.collect(toImmutableList());
}
|
If the given correspondence implementation is "simple enough," returns one or more possible
replacements for its definition and instantiation sites.
|
computePossibleReplacements
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static ImmutableList<BinaryPredicateCode> makeBinaryPredicates(
ClassTree classTree, MethodTree compareMethod, VisitorState state) {
Tree comparison = maybeMakeLambdaBody(compareMethod, state);
if (comparison == null) {
ClassTree enclosing = findStrictlyEnclosing(state, ClassTree.class);
CharSequence newCompareMethodOwner;
String newCompareMethodName;
if (enclosing == null) {
newCompareMethodName = "compare";
newCompareMethodOwner = classTree.getSimpleName();
} else {
newCompareMethodName =
"compare" + classTree.getSimpleName().toString().replaceFirst("Correspondence$", "");
newCompareMethodOwner = enclosing.getSimpleName();
}
// TODO(cpovirk): We're unlikely to get away with declaring everything `static`.
String supportingMethodDefinition =
format(
"private static boolean %s(%s, %s) %s",
newCompareMethodName,
state.getSourceForNode(compareMethod.getParameters().get(0)),
state.getSourceForNode(compareMethod.getParameters().get(1)),
state.getSourceForNode(compareMethod.getBody()));
return ImmutableList.of(
BinaryPredicateCode.create(
newCompareMethodOwner + "::" + newCompareMethodName, supportingMethodDefinition));
}
// First try without types, then try with.
return ImmutableList.of(
BinaryPredicateCode.fromParamsAndExpression(
compareMethod.getParameters().get(0).getName(),
compareMethod.getParameters().get(1).getName(),
state.getSourceForNode(comparison)),
BinaryPredicateCode.fromParamsAndExpression(
state.getSourceForNode(compareMethod.getParameters().get(0)),
state.getSourceForNode(compareMethod.getParameters().get(1)),
state.getSourceForNode(comparison)));
}
|
Returns one or more possible replacements for the given correspondence's {@code compare} method's definition and for code to pass to {@code Correspondence.from) to construct a correspondence that uses the replacement.
|
makeBinaryPredicates
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static @Nullable Tree maybeMakeLambdaBody(MethodTree compareMethod, VisitorState state) {
ExpressionTree comparison = returnExpression(compareMethod);
if (comparison != null) {
// compare() is defined as simply `return something;`. Create a lambda.
return comparison;
}
/*
* compare() has multiple statements. Let's keep it as a method (though we might change its
* modifiers, name, and location) and construct the Correspondence with a method reference...
*
* ...unless it relies on parameters from the enclosing method, in which case extracting a
* method isn't going to work because it won't be able to access those parameters.
*/
MethodTree enclosingMethod = state.findEnclosing(MethodTree.class);
if (enclosingMethod == null) {
// No enclosing method, so we're presumably not closing over anything. Safe to extract method.
return null;
}
ImmutableSet<Symbol> paramsOfEnclosingMethod =
enclosingMethod.getParameters().stream()
.map(p -> getDeclaredSymbol(p))
.collect(toImmutableSet());
boolean[] referenceFound = new boolean[1];
new TreeScanner<Void, Void>() {
@Override
public @Nullable Void scan(Tree node, Void aVoid) {
if (paramsOfEnclosingMethod.contains(getSymbol(node))) {
referenceFound[0] = true;
}
return super.scan(node, aVoid);
}
}.scan(state.getPath().getLeaf(), null);
if (!referenceFound[0]) {
// No references to anything from the enclosing method. Probably safe to extract a method.
return null;
}
/*
* compare() both:
*
* - uses a parameter from the enclosing method and
*
* - has multiple statements
*
* So we create a block lambda.
*/
return compareMethod.getBody();
}
|
Converts the given method into a lambda, either expression or block, if "appropriate." For
details about the various cases, see implementation comments.
|
maybeMakeLambdaBody
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
@Override
public @Nullable Void scan(Tree node, Void aVoid) {
if (paramsOfEnclosingMethod.contains(getSymbol(node))) {
referenceFound[0] = true;
}
return super.scan(node, aVoid);
}
|
Converts the given method into a lambda, either expression or block, if "appropriate." For
details about the various cases, see implementation comments.
|
scan
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static <T extends Tree> @Nullable T findStrictlyEnclosing(
VisitorState state, Class<T> clazz) {
return stream(state.getPath().getParentPath())
.filter(clazz::isInstance)
.map(clazz::cast)
.findAny()
.orElse(null);
}
|
Like {@link VisitorState#findEnclosing} but doesn't consider the leaf to enclose itself.
|
findStrictlyEnclosing
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static @Nullable Tree findChildOfStrictlyEnclosing(
VisitorState state, Class<? extends Tree> clazz) {
Tree previous = state.getPath().getLeaf();
for (Tree t : state.getPath().getParentPath()) {
if (clazz.isInstance(t)) {
return previous;
}
previous = t;
}
return null;
}
|
Like {@link #findStrictlyEnclosing} but returns not the found element but its child along the
path. For example, if called with {@code ClassTree}, it might return a {@code MethodTree}
inside the class.
|
findChildOfStrictlyEnclosing
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
static CorrespondenceCode create(BinaryPredicateCode binaryPredicate, String description) {
return new AutoValue_CorrespondenceSubclassToFactoryCall_CorrespondenceCode(
binaryPredicate, description);
}
|
A {@code Correspondence.from} call to replace the instantiation site of a {@code
Correspondence}. Often the call is self-contained (if it's a lambda), but sometimes it's a
method reference, in which case it's accompanied by a separate method definition.
|
create
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
final String callSite() {
return format("Correspondence.from(%s, %s)", binaryPredicate().usage(), description());
}
|
A {@code Correspondence.from} call to replace the instantiation site of a {@code
Correspondence}. Often the call is self-contained (if it's a lambda), but sometimes it's a
method reference, in which case it's accompanied by a separate method definition.
|
callSite
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
final String supportingMethodDefinition() {
return binaryPredicate().supportingMethodDefinition().orElse("");
}
|
A {@code Correspondence.from} call to replace the instantiation site of a {@code
Correspondence}. Often the call is self-contained (if it's a lambda), but sometimes it's a
method reference, in which case it's accompanied by a separate method definition.
|
supportingMethodDefinition
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
static BinaryPredicateCode fromParamsAndExpression(
CharSequence param0, CharSequence param1, String expression) {
return create(String.format("(%s, %s) -> %s", param0, param1, expression), null);
}
|
Code that can be inserted as the first argument of a {@code Correspondence.from} call. Often
it's a lambda, but sometimes it's a method reference, in which case it's accompanied by a
separate method definition.
|
fromParamsAndExpression
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
static BinaryPredicateCode create(String usage, @Nullable String supportingMethodDefinition) {
return new AutoValue_CorrespondenceSubclassToFactoryCall_BinaryPredicateCode(
usage, Optional.ofNullable(supportingMethodDefinition));
}
|
Code that can be inserted as the first argument of a {@code Correspondence.from} call. Often
it's a lambda, but sometimes it's a method reference, in which case it's accompanied by a
separate method definition.
|
create
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static @Nullable ExpressionTree returnExpression(MethodTree method) {
List<? extends StatementTree> statements = method.getBody().getStatements();
if (statements.size() != 1) {
return null;
}
StatementTree statement = getOnlyElement(statements);
if (statement.getKind() != RETURN) {
return null;
}
return ((ReturnTree) statement).getExpression();
}
|
Code that can be inserted as the first argument of a {@code Correspondence.from} call. Often
it's a lambda, but sometimes it's a method reference, in which case it's accompanied by a
separate method definition.
|
returnExpression
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static boolean constructorCallsOnlySuper(MethodTree constructor) {
List<? extends StatementTree> statements = constructor.getBody().getStatements();
if (statements.size() != 1) {
return false;
}
StatementTree statement = getOnlyElement(statements);
if (statement.getKind() != EXPRESSION_STATEMENT) {
return false;
}
ExpressionTree expression = ((ExpressionStatementTree) statement).getExpression();
if (expression.getKind() != METHOD_INVOCATION) {
return false;
}
ExpressionTree methodSelect = ((MethodInvocationTree) expression).getMethodSelect();
if (methodSelect.getKind() != IDENTIFIER
|| !((IdentifierTree) methodSelect).getName().contentEquals("super")) {
return false;
}
return true;
}
|
Code that can be inserted as the first argument of a {@code Correspondence.from} call. Often
it's a lambda, but sometimes it's a method reference, in which case it's accompanied by a
separate method definition.
|
constructorCallsOnlySuper
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
static MemberType from(Tree tree, VisitorState state) {
Symbol symbol = getDeclaredSymbol(tree);
if (!(symbol instanceof MethodSymbol)) {
return OTHER;
}
MethodSymbol methodSymbol = (MethodSymbol) symbol;
if (methodSymbol.getSimpleName().contentEquals("<init>")) {
return CONSTRUCTOR;
} else if (overrides(methodSymbol, CORRESPONDENCE_CLASS, "compare", state)) {
return COMPARE_METHOD;
} else if (overrides(methodSymbol, "java.lang.Object", "toString", state)) {
return TO_STRING_METHOD;
} else {
return OTHER;
}
}
|
Whether a member is of one of the standard {@link Correspondence} methods that we know how to
migrate and, if so, which one.
|
from
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static boolean overrides(
MethodSymbol potentialOverrider, String clazz, String method, VisitorState state) {
Symbol overridable =
getEnclosedElements(state.getTypeFromString(clazz).tsym).stream()
.filter(s -> s.getKind() == METHOD)
.filter(m -> m.getSimpleName().contentEquals(method))
.collect(onlyElement());
return potentialOverrider.getSimpleName().contentEquals(method)
&& potentialOverrider.overrides(
overridable, (TypeSymbol) overridable.owner, state.getTypes(), /* checkResult= */ true);
}
|
Whether a member is of one of the standard {@link Correspondence} methods that we know how to
migrate and, if so, which one.
|
overrides
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static boolean isCorrespondence(Tree supertypeTree, VisitorState state) {
Type correspondenceType = COM_GOOGLE_COMMON_TRUTH_CORRESPONDENCE.get(state);
if (correspondenceType == null) {
return false;
}
return supertypeTree != null
&& state.getTypes().isSameType(getSymbol(supertypeTree).type, correspondenceType);
}
|
Whether a member is of one of the standard {@link Correspondence} methods that we know how to
migrate and, if so, which one.
|
isCorrespondence
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
if (!ONE_ARG_FAIL.matches(tree, state) && !TWO_ARG_FAIL.matches(tree, state)) {
return NO_MATCH;
}
SuggestedFix.Builder fix = SuggestedFix.builder();
if (tree.getMethodSelect().getKind() == IDENTIFIER) {
fix.replace(tree.getMethodSelect(), "failWithActual");
} else if (tree.getMethodSelect().getKind() == MEMBER_SELECT) {
MemberSelectTree methodSelect = (MemberSelectTree) tree.getMethodSelect();
fix.replace(
state.getEndPosition(methodSelect.getExpression()),
state.getEndPosition(methodSelect),
".failWithActual");
} else {
return NO_MATCH;
}
ExpressionTree oldVerbArg = tree.getArguments().get(0);
String oldVerb = constValue(oldVerbArg, String.class);
if (oldVerb == null) {
return NO_MATCH;
}
String newVerb = newVerb(oldVerb);
if (newVerb == null) {
return NO_MATCH;
}
String newVerbQuoted = state.getElements().getConstantExpression(newVerb);
if (ONE_ARG_FAIL.matches(tree, state)) {
fix.addStaticImport("com.google.common.truth.Fact.simpleFact");
fix.replace(oldVerbArg, format("simpleFact(%s)", newVerbQuoted));
} else {
fix.replace(oldVerbArg, newVerbQuoted);
}
return describeMatch(tree, fix.build());
}
|
Migrates Truth subjects from the old {@code fail(String, Object)} to the new {@code
failWithActual(String, Object)}, tweaking verbs for the new grammar. For example:
<pre>{@code
// Before:
fail("has foo", expected);
// After:
failWithActual("expected to have foo", expected);
}</pre>
|
matchMethodInvocation
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/FailWithFacts.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/FailWithFacts.java
|
Apache-2.0
|
private static @Nullable String newVerb(String oldVerb) {
List<String> old = Splitter.on(whitespace()).splitToList(oldVerb);
String first = old.get(0);
if (CAPITAL_LETTER.matchesAnyOf(first)) {
// "hasFoo," etc. TODO(cpovirk): Handle these.
return null;
}
if (first.equals("does") && old.size() >= 2 && old.get(1).equals("not")) {
// "Not true that foo does not exist" -> "expected not to exist"
return "expected not to " + skip(old, 2);
}
if (first.equals("is") && old.size() >= 2 && old.get(1).equals("not")) {
// "Not true that foo is not visible" -> "expected not to be visible"
return "expected not to be " + skip(old, 2);
}
if (first.equals("has")) {
// "Not true that foo has children" -> "expected to have children"
return "expected to have " + skip(old, 1);
} else if (first.equals("is") || first.equals("are") || first.equals("was")) {
// "Not true that foo is empty" -> "expected to be empty"
// "Not true that operations are complete" -> "expected to be complete"
// "Not true that foo was deleted" -> "expected to be deleted"
return "expected to be " + skip(old, 1);
} else if (first.endsWith("ies")) {
// "Not true that foo applies to bar" -> "expected apply to bar"
return "expected to " + first.replaceFirst("ies$", "y") + " " + skip(old, 1);
} else if (first.endsWith("ches")) {
// "Not true that foo matches bar" -> "expected to match bar"
return "expected to " + first.replaceFirst("ches$", "ch") + " " + skip(old, 1);
} else if (first.matches(".*[^aeiouy]s$")) {
// "Not true that foo contains bar" -> "expected to contain bar"
return "expected to " + first.replaceFirst("s$", "") + " " + skip(old, 1);
} else {
return null;
}
}
|
Migrates Truth subjects from the old {@code fail(String, Object)} to the new {@code
failWithActual(String, Object)}, tweaking verbs for the new grammar. For example:
<pre>{@code
// Before:
fail("has foo", expected);
// After:
failWithActual("expected to have foo", expected);
}</pre>
|
newVerb
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/FailWithFacts.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/FailWithFacts.java
|
Apache-2.0
|
private static String skip(List<String> old, int i) {
return old.stream().skip(i).collect(joining(" "));
}
|
Migrates Truth subjects from the old {@code fail(String, Object)} to the new {@code
failWithActual(String, Object)}, tweaking verbs for the new grammar. For example:
<pre>{@code
// Before:
fail("has foo", expected);
// After:
failWithActual("expected to have foo", expected);
}</pre>
|
skip
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/FailWithFacts.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/FailWithFacts.java
|
Apache-2.0
|
@Before
public void setUp() {
compilationHelper =
CompilationTestHelper.newInstance(CorrespondenceSubclassToFactoryCall.class, getClass());
refactoringHelper =
BugCheckerRefactoringTestHelper.newInstance(
CorrespondenceSubclassToFactoryCall.class, getClass());
}
|
@author cpovirk@google.com (Chris Povirk)
|
setUp
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
Apache-2.0
|
@Test
public void testPositiveCase() {
compilationHelper
.addSourceFile("testdata/CorrespondenceSubclassToFactoryCallPositiveCases.java")
.doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testPositiveCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
Apache-2.0
|
@Test
public void testPositiveCase2() {
compilationHelper
.addSourceFile("testdata/CorrespondenceSubclassToFactoryCallPositiveCases2.java")
.doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testPositiveCase2
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
Apache-2.0
|
@Test
public void testNegativeCase() {
compilationHelper
.addSourceFile("testdata/CorrespondenceSubclassToFactoryCallNegativeCases.java")
.doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testNegativeCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
Apache-2.0
|
@Test
public void refactoring() {
refactoringHelper
.addInput("testdata/CorrespondenceSubclassToFactoryCallPositiveCases.java")
.addOutput("testdata/CorrespondenceSubclassToFactoryCallPositiveCases_expected.java")
.doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
refactoring
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
Apache-2.0
|
@Test
public void refactoring2() {
refactoringHelper
.addInput("testdata/CorrespondenceSubclassToFactoryCallPositiveCases2.java")
.addOutput("testdata/CorrespondenceSubclassToFactoryCallPositiveCases2_expected.java")
.doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
refactoring2
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCallTest.java
|
Apache-2.0
|
@Test
public void testPositiveCase() {
compilationHelper.addSourceFile("testdata/FailWithFactsPositiveCases.java").doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testPositiveCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/FailWithFactsTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/FailWithFactsTest.java
|
Apache-2.0
|
@Before
public void setUp() {
compilationHelper = CompilationTestHelper.newInstance(NamedToWithMessage.class, getClass());
}
|
@author cpovirk@google.com (Chris Povirk)
|
setUp
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/NamedToWithMessageTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/NamedToWithMessageTest.java
|
Apache-2.0
|
@Test
public void testPositiveCase() {
compilationHelper.addSourceFile("NamedToWithMessagePositiveCases.java").doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testPositiveCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/NamedToWithMessageTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/NamedToWithMessageTest.java
|
Apache-2.0
|
@Test
public void testNegativeCase() {
compilationHelper.addSourceFile("NamedToWithMessageNegativeCases.java").doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testNegativeCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/NamedToWithMessageTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/NamedToWithMessageTest.java
|
Apache-2.0
|
@Before
public void setUp() {
compilationHelper =
CompilationTestHelper.newInstance(StoreActualValueInField.class, getClass());
refactoringHelper =
BugCheckerRefactoringTestHelper.newInstance(new StoreActualValueInField(), getClass());
}
|
@author cpovirk@google.com (Chris Povirk)
|
setUp
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
Apache-2.0
|
@Test
public void testPositiveCase() {
compilationHelper.addSourceFile("StoreActualValueInFieldPositiveCases.java").doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testPositiveCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
Apache-2.0
|
@Test
public void testNegativeCase() {
compilationHelper.addSourceFile("StoreActualValueInFieldNegativeCases.java").doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
testNegativeCase
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
Apache-2.0
|
@Test
public void refactoring() {
refactoringHelper
.addInput("StoreActualValueInFieldPositiveCases.java")
.addOutput("StoreActualValueInFieldPositiveCases_expected.java")
.doTest();
}
|
@author cpovirk@google.com (Chris Povirk)
|
refactoring
|
java
|
google/truth
|
refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
https://github.com/google/truth/blob/master/refactorings/src/test/java/com/google/common/truth/refactorings/StoreActualValueInFieldTest.java
|
Apache-2.0
|
public static <V, E> DirectedAcyclicGraph<V, E> from(DirectedGraph<V, E> graph) {
if (Graphs.stronglyConnectedComponents(graph, false).size() > 0) {
throw new CycleException();
}
Set<V> top = new Set<>(graph.vertexHash(), graph.vertexEquality()).linear();
Set<V> bottom = new Set<>(graph.vertexHash(), graph.vertexEquality()).linear();
graph.vertices().stream().filter(v -> graph.in(v).size() == 0).forEach(top::add);
graph.vertices().stream().filter(v -> graph.out(v).size() == 0).forEach(bottom::add);
return new DirectedAcyclicGraph<>(graph, top.forked(), bottom.forked());
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
public Set<V> top() {
return top;
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
top
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
public Set<V> bottom() {
return bottom;
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
bottom
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
public DirectedGraph<V, E> directedGraph() {
return graph.clone();
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
directedGraph
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> add(IEdge<V, E> edge) {
return link(edge.from(), edge.to(), edge.value());
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
add
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> remove(IEdge<V, E> edge) {
return unlink(edge.from(), edge.to());
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> link(V from, V to, E edge) {
return link(from, to, edge, (BinaryOperator<E>) MERGE_LAST_WRITE_WINS);
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
link
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> link(V from, V to) {
return link(from, to, null, (BinaryOperator<E>) MERGE_LAST_WRITE_WINS);
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
link
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public Set<V> vertices() {
return graph.vertices();
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
vertices
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public Iterable<IEdge<V, E>> edges() {
return graph.edges();
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
edges
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public E edge(V src, V dst) {
return graph.edge(src, dst);
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
edge
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public E edge(V src, V dst, E notFound) {
return graph.edge(src, dst, notFound);
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
edge
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public Set<V> in(V vertex) {
return graph.in(vertex);
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
in
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public Set<V> out(V vertex) {
return graph.out(vertex);
}
|
@return a directed acyclic graph equivalent to {@code graph}
@throws CycleException if {@code graph} contains a cycle
|
out
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> link(V from, V to, E edge, BinaryOperator<E> merge) {
boolean
newFrom = !vertices().contains(from),
newTo = !vertices().contains(to);
if (!newFrom && !newTo && !out(from).contains(to) && createsCycle(from, to)) {
throw new CycleException();
}
DirectedGraph<V, E> graphPrime = graph.link(from, to, edge, merge);
Set<V> topPrime = top.remove(to);
Set<V> bottomPrime = bottom.remove(from);
if (newFrom) {
topPrime = top.add(from);
}
if (newTo) {
bottomPrime = bottom.add(to);
}
if (isLinear()) {
graph = graphPrime;
top = topPrime;
bottom = bottomPrime;
return this;
} else {
return new DirectedAcyclicGraph<>(graphPrime, topPrime, bottomPrime);
}
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
link
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> unlink(V from, V to) {
DirectedGraph<V, E> graphPrime = graph.unlink(from, to);
Set<V> topPrime = graph.in(to).size() == 1 ? top.add(to) : top;
Set<V> bottomPrime = graph.out(from).size() == 1 ? bottom.add(from) : bottom;
if (isLinear() || graph == graphPrime) {
graph = graphPrime;
top = topPrime;
bottom = bottomPrime;
return this;
} else {
return new DirectedAcyclicGraph<>(graphPrime, topPrime, bottomPrime);
}
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
unlink
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> merge(IGraph<V, E> graph, BinaryOperator<E> merge) {
return from(this.graph.merge(graph, merge));
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
merge
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> select(ISet<V> vertices) {
return from(graph.select(vertices));
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
select
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> add(V vertex) {
if (graph.vertices().contains(vertex)) {
return this;
} else {
DirectedGraph<V, E> graphPrime = graph.add(vertex);
Set<V> topPrime = top.add(vertex);
Set<V> bottomPrime = bottom.add(vertex);
if (isLinear()) {
graph = graphPrime;
top = topPrime;
bottom = bottomPrime;
return this;
} else {
return new DirectedAcyclicGraph<>(graphPrime, topPrime, bottomPrime);
}
}
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
add
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> remove(V vertex) {
if (graph.vertices().contains(vertex)) {
Set<V> topPrime =
top.union(graph.out(vertex).stream().filter(v -> graph.in(v).size() == 1).collect(Sets.collector()));
Set<V> bottomPrime =
bottom.union(graph.in(vertex).stream().filter(v -> graph.out(v).size() == 1).collect(Sets.collector()));
DirectedGraph<V, E> graphPrime = graph.remove(vertex);
if (isLinear()) {
graph = graphPrime;
top = topPrime;
bottom = bottomPrime;
return this;
} else {
return new DirectedAcyclicGraph<>(graphPrime, topPrime, bottomPrime);
}
} else {
return this;
}
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> forked() {
return graph.isLinear() ? new DirectedAcyclicGraph<>(graph.forked(), top.forked(), bottom.forked()) : this;
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
forked
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> linear() {
return graph.isLinear() ? this : new DirectedAcyclicGraph<>(graph.linear(), top.linear(), bottom.linear());
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
linear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public boolean isLinear() {
return graph.isLinear();
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
isLinear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public boolean isDirected() {
return true;
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
isDirected
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public <U> DirectedAcyclicGraph<V, U> mapEdges(Function<IEdge<V, E>, U> f) {
return new DirectedAcyclicGraph<>(graph.mapEdges(f), top, bottom);
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
mapEdges
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> transpose() {
return new DirectedAcyclicGraph<>(graph.transpose(), bottom, top);
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
transpose
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public ToLongFunction<V> vertexHash() {
return graph.vertexHash();
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
vertexHash
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public BiPredicate<V, V> vertexEquality() {
return graph.vertexEquality();
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
vertexEquality
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public int hashCode() {
return graph.hashCode();
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
hashCode
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public boolean equals(Object obj) {
return graph.equals(obj);
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public String toString() {
return graph.toString();
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
toString
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
@Override
public DirectedAcyclicGraph<V, E> clone() {
return new DirectedAcyclicGraph<V, E>(graph.clone(), bottom.clone(), top.clone());
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
clone
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
private boolean createsCycle(V from, V to) {
Iterator<V> upstreamIterator = Graphs.bfsVertices(LinearList.of(from), this::in).iterator();
Iterator<V> downstreamIterator = Graphs.bfsVertices(LinearList.of(to), this::out).iterator();
if (!upstreamIterator.hasNext() || !downstreamIterator.hasNext()) {
return false;
}
LinearSet<V> upstream = new LinearSet<V>(vertexHash(), vertexEquality());
LinearSet<V> downstream = new LinearSet<V>(vertexHash(), vertexEquality());
while (upstreamIterator.hasNext() && downstreamIterator.hasNext()) {
V a = upstreamIterator.next();
if (downstream.contains(a)) {
return true;
}
upstream.add(a);
V b = downstreamIterator.next();
if (upstream.contains(b)) {
return true;
}
downstream.add(b);
}
return false;
}
|
@param from the source of the edge
@param to the destination of the edge
@param edge the value of the edge
@param merge the merge function for the edge values, if an edge already exists
@return a graph containing the new edge
@throws CycleException if the new edge creates a cycle
|
createsCycle
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
|
MIT
|
public static <V> FloatMap<V> from(IMap<Number, V> m) {
if (m instanceof FloatMap) {
return (FloatMap) m.forked();
} else {
return from(m.entries());
}
}
|
A map which has floating-point keys, built atop {@link IntMap}, with which it shares performance characteristics.
<p>
Since this is intended foremost as a sorted data structure, it does not allow {@code NaN} and treats {@code -0.0} as
equivalent to {@code 0.0}. Anyone looking for identity-based semantics should use a normal {@code Map} instead.
@author ztellman
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
public static <V> FloatMap<V> from(java.util.Map<Number, V> m) {
return from(m.entrySet());
}
|
@param m a Java map
@return a forked copy of the map
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
public static <V> FloatMap<V> from(Collection<java.util.Map.Entry<Number, V>> collection) {
FloatMap<V> map = new FloatMap<V>().linear();
for (java.util.Map.Entry<Number, V> entry : collection) {
map = map.put(entry.getKey().doubleValue(), entry.getValue());
}
return map.forked();
}
|
@param collection a collection of {@link java.util.Map.Entry} objects
@return an {@link IntMap} representing the entries in the collection
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
public static <V> FloatMap<V> from(IList<IEntry<Number, V>> list) {
FloatMap<V> map = new FloatMap<V>().linear();
for (IEntry<Number, V> entry : list) {
map = map.put(entry.key().doubleValue(), entry.value());
}
return map.forked();
}
|
@param list a list of {@link IEntry} objects
@return an {@link IntMap} representing the entries in the list
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
@Override
public Comparator<Double> comparator() {
return Comparator.naturalOrder();
}
|
@param list a list of {@link IEntry} objects
@return an {@link IntMap} representing the entries in the list
|
comparator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
@Override
public ToLongFunction<Double> keyHash() {
return HASH;
}
|
@param list a list of {@link IEntry} objects
@return an {@link IntMap} representing the entries in the list
|
keyHash
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
@Override
public BiPredicate<Double, Double> keyEquality() {
return Double::equals;
}
|
@param list a list of {@link IEntry} objects
@return an {@link IntMap} representing the entries in the list
|
keyEquality
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
public boolean contains(double key) {
return map.contains(doubleToLong(key));
}
|
@param list a list of {@link IEntry} objects
@return an {@link IntMap} representing the entries in the list
|
contains
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
@Override
public IList<IEntry<Double, V>> entries() {
return Lists.lazyMap(map.entries(), FloatMap::convertEntry);
}
|
@param list a list of {@link IEntry} objects
@return an {@link IntMap} representing the entries in the list
|
entries
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.