From 842c498259e98a63d184212e717cf31f893edc0a Mon Sep 17 00:00:00 2001 From: Seamus McMorrow Date: Fri, 16 Mar 2018 19:11:30 +0000 Subject: [PATCH] Fixes #373 --- .../com/google/gdt/eclipse/core/JavaASTUtils.java | 11 +++++++++++ .../eclipse/core/uibinder/UiBinderUtilities.java | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/com.gwtplugins.gdt.eclipse.core/src/com/google/gdt/eclipse/core/JavaASTUtils.java b/plugins/com.gwtplugins.gdt.eclipse.core/src/com/google/gdt/eclipse/core/JavaASTUtils.java index 822082f9..897a386e 100644 --- a/plugins/com.gwtplugins.gdt.eclipse.core/src/com/google/gdt/eclipse/core/JavaASTUtils.java +++ b/plugins/com.gwtplugins.gdt.eclipse.core/src/com/google/gdt/eclipse/core/JavaASTUtils.java @@ -49,6 +49,7 @@ import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; +import org.eclipse.jdt.internal.corext.dom.ASTNodes; import org.eclipse.jdt.internal.corext.dom.TypeBindingVisitor; import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; @@ -122,6 +123,7 @@ public static boolean containsTypeVariable(Type type) { final boolean[] containsTypeVariable = {false}; ASTResolving.visitAllBindings(type, new TypeBindingVisitor() { + @Override public boolean visit(ITypeBinding visitedBinding) { if (visitedBinding.isTypeVariable()) { containsTypeVariable[0] = true; @@ -262,6 +264,15 @@ public static TypeDeclaration findTypeDeclaration(IJavaProject javaProject, return null; } + public static ITypeBinding findTypeBinding(IType currentType) throws JavaModelException{ + final ASTParser parser = ASTParser.newParser(AST.JLS8); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setSource(currentType.getCompilationUnit()); + parser.setResolveBindings(true); + CompilationUnit unit = (CompilationUnit) parser.createAST(null); + return ASTNodes.getTypeBinding(unit, currentType); + } + /** * Identical to * {@link org.eclipse.jdt.internal.corext.dom.Bindings#findTypeInHierarchy(ITypeBinding, String)} diff --git a/plugins/com.gwtplugins.gwt.eclipse.core/src/com/google/gwt/eclipse/core/uibinder/UiBinderUtilities.java b/plugins/com.gwtplugins.gwt.eclipse.core/src/com/google/gwt/eclipse/core/uibinder/UiBinderUtilities.java index 0814c4bb..c9c247bb 100644 --- a/plugins/com.gwtplugins.gwt.eclipse.core/src/com/google/gwt/eclipse/core/uibinder/UiBinderUtilities.java +++ b/plugins/com.gwtplugins.gwt.eclipse.core/src/com/google/gwt/eclipse/core/uibinder/UiBinderUtilities.java @@ -33,8 +33,11 @@ import org.eclipse.jdt.core.ITypeHierarchy; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.internal.corext.dom.Bindings; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; @@ -409,6 +412,16 @@ public static IType resolveJavaElExpression(IType contextType, currentType = fragmentType; continue; } + + // Final attempt to resolve the type, this resolves the binding + // in the case of generics or parameterized types. Fixes issue 373 + ITypeBinding binding = JavaASTUtils.findTypeBinding(currentType); + IMethodBinding methodBinding = Bindings.findMethodInHierarchy(binding, + fragment, new ITypeBinding[] {}); + if(methodBinding.getReturnType() != null) { + currentType = fragmentType; + continue; + } } } catch (JavaModelException e) { // Ignore, and continue the search