Skip to content

Commit

Permalink
Ignore synthetic method in Qute template
Browse files Browse the repository at this point in the history
Fixes #723

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Aug 26, 2022
1 parent c76ddfb commit bd08a60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.redhat.qute.commons.JavaMethodInfo;
import com.redhat.qute.commons.QuteResolvedJavaTypeParams;
import com.redhat.qute.commons.ResolvedJavaTypeInfo;
import com.redhat.qute.commons.datamodel.resolvers.ValueResolverInfo;
import com.redhat.qute.jdt.QuteProjectTest.QuteMavenProjectName;
import com.redhat.qute.jdt.QuteSupportForTemplate;

Expand Down Expand Up @@ -446,6 +445,22 @@ public void registerForReflection() throws CoreException, Exception {
Assert.assertEquals(InvalidMethodReason.Static, reason);
}

@Test
public void ignoreSyntheticMethod() throws CoreException, Exception {
loadMavenProject(QuteMavenProjectName.qute_quickstart);

QuteResolvedJavaTypeParams params = new QuteResolvedJavaTypeParams("java.lang.CharSequence",
QuteMavenProjectName.qute_quickstart);
ResolvedJavaTypeInfo result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(),
new NullProgressMonitor());
Assert.assertNotNull(result);

// lambda$chars$0 should be ignored
Assert.assertEquals("java.lang.CharSequence", result.getSignature());
JavaMethodInfo syntheticMethod = findMethod(result, "lambda$chars$0");
Assert.assertNull(syntheticMethod);
}

private static void assertExtendedTypes(String type, String extendedType, List<String> extendedTypes) {
Assert.assertTrue("The Java type '" + type + "' should extends '" + extendedType + "'.",
extendedTypes.contains(extendedType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams param
Map<String, InvalidMethodReason> invalidMethods = new HashMap<>();
IMethod[] methods = type.getMethods();
for (IMethod method : methods) {
if (isValidMethod(method, type.isInterface())) {
if (isValidMethod(method, type)) {
try {
InvalidMethodReason invalid = getValidMethodForQute(method, typeName);
if (invalid != null) {
Expand Down Expand Up @@ -469,12 +469,12 @@ private static boolean isValidField(IField field, IType type) throws JavaModelEx
return Flags.isPublic(field.getFlags());
}

private static boolean isValidMethod(IMethod method, boolean isInterface) {
private static boolean isValidMethod(IMethod method, IType type) {
try {
if (method.isConstructor() || !method.exists()) {
if (method.isConstructor() || !method.exists() || Flags.isSynthetic(method.getFlags())) {
return false;
}
if (!isInterface && !Flags.isPublic(method.getFlags())) {
if (!type.isInterface() && !Flags.isPublic(method.getFlags())) {
return false;
}
} catch (Exception e) {
Expand Down

0 comments on commit bd08a60

Please sign in to comment.