Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down