Skip to content

Commit

Permalink
Remove code from EclipseHack that is apparently no longer needed.
Browse files Browse the repository at this point in the history
`CompileWithEclipseTest` still passes with these removals, which suggests that
the Eclipse bugs that made this code necessary have been fixed.

RELNOTES=n/a
PiperOrigin-RevId: 602524517
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Jan 30, 2024
1 parent 759a557 commit 14a55ed
Showing 1 changed file with 4 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@

import static java.util.stream.Collectors.toList;

import com.google.auto.common.MoreElements;
import com.google.auto.common.MoreTypes;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
Expand All @@ -33,7 +29,6 @@
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;

Expand Down Expand Up @@ -120,12 +115,8 @@ static TypeMirror getEnclosingType(DeclaredType type) {
}

TypeMirror methodReturnType(ExecutableElement method, DeclaredType in) {
try {
TypeMirror methodMirror = typeUtils.asMemberOf(in, method);
return MoreTypes.asExecutable(methodMirror).getReturnType();
} catch (IllegalArgumentException e) {
return methodReturnTypes(ImmutableSet.of(method), in).get(method);
}
TypeMirror methodMirror = typeUtils.asMemberOf(in, method);
return MoreTypes.asExecutable(methodMirror).getReturnType();
}

/**
Expand All @@ -144,7 +135,6 @@ TypeMirror methodReturnType(ExecutableElement method, DeclaredType in) {
ImmutableMap<ExecutableElement, TypeMirror> methodReturnTypes(
Set<ExecutableElement> methods, DeclaredType in) {
ImmutableMap.Builder<ExecutableElement, TypeMirror> map = ImmutableMap.builder();
Map<Name, ExecutableElement> noArgMethods = null;
for (ExecutableElement method : methods) {
TypeMirror returnType = method.getReturnType();
if (!in.asElement().equals(method.getEnclosingElement())) {
Expand All @@ -155,39 +145,11 @@ ImmutableMap<ExecutableElement, TypeMirror> methodReturnTypes(
// We can still hit that issue in the case where the method *is* inherited. Fixing it in
// general would probably involve keeping track of type annotations ourselves, separately
// from TypeMirror instances.
try {
TypeMirror methodMirror = typeUtils.asMemberOf(in, method);
returnType = MoreTypes.asExecutable(methodMirror).getReturnType();
} catch (IllegalArgumentException e) {
if (method.getParameters().isEmpty()) {
if (noArgMethods == null) {
noArgMethods = noArgMethodsIn(in);
}
returnType = noArgMethods.get(method.getSimpleName()).getReturnType();
}
}
TypeMirror methodMirror = typeUtils.asMemberOf(in, method);
returnType = MoreTypes.asExecutable(methodMirror).getReturnType();
}
map.put(method, returnType);
}
return map.build();
}

/**
* Constructs a map from name to method of the no-argument methods in the given type. We need this
* because an ExecutableElement returned by {@link Elements#getAllMembers} will not compare equal
* to the original ExecutableElement if {@code getAllMembers} substituted type parameters, as it
* does in Eclipse.
*/
private Map<Name, ExecutableElement> noArgMethodsIn(DeclaredType in) {
TypeElement autoValueType = MoreElements.asType(typeUtils.asElement(in));
List<ExecutableElement> allMethods =
ElementFilter.methodsIn(elementUtils.getAllMembers(autoValueType));
Map<Name, ExecutableElement> map = new LinkedHashMap<Name, ExecutableElement>();
for (ExecutableElement method : allMethods) {
if (method.getParameters().isEmpty()) {
map.put(method.getSimpleName(), method);
}
}
return map;
}
}

0 comments on commit 14a55ed

Please sign in to comment.