Community
Participate
Working Groups
3.1.1 I started to infer some type arguments myself, but then realized that the refactoring might do this better. However, on my already modified (but compiling code) the refactoring failed with a ClassCastException - get jdt.core from the 3.2 stream (I20050922), set 5.0 comoliance, change PDE target location to a M2 build - replace ASTNode with the attached file - run ' Infer type argument ' on the 'dom' source folder in jdt.core java.lang.ClassCastException: org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.StandardType at org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.RawType.initialize(RawType.java:30) at org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment.createRawType(TypeEnvironment.java:388) at org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment.create(TypeEnvironment.java:177) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel.createTType(InferTypeArgumentsTCModel.java:299) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel.getBoxedType(InferTypeArgumentsTCModel.java:309) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel.makeTypeVariable(InferTypeArgumentsTCModel.java:375) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsConstraintCreator.endVisit(InferTypeArgumentsConstraintCreator.java:124) at org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor.endVisit(HierarchicalASTVisitor.java:707) at org.eclipse.jdt.core.dom.SimpleType.accept0(SimpleType.java:138) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450) at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2497) at org.eclipse.jdt.core.dom.VariableDeclarationStatement.accept0(VariableDeclarationStatement.java:271) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520) at org.eclipse.jdt.core.dom.Block.accept0(Block.java:135) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450) at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2497) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:501) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:483) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520) at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:299) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring$2.run(InferTypeArgumentsRefactoring.java:194) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044) at org.eclipse.core.runtime.Platform.run(Platform.java:783) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring$1.acceptAST(InferTypeArgumentsRefactoring.java:183) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:691) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:455) at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:664) at org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring.checkFinalConditions(InferTypeArgumentsRefactoring.java:178) at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:84) at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:114) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1719) at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:86) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Created attachment 27511 [details] updated ASTNode.java
Self-contained example: package dom; import java.util.AbstractList; import java.util.Iterator; public class ASTNode { abstract class NodeList<E extends ASTNode> extends AbstractList<E> { abstract class Cursor implements Iterator { } } final void acceptChildren(ASTNode.NodeList children) { NodeList.Cursor cursor; } } The problem is that the reference NodeList.Cursor is raw, but its typeDeclaration is not generic as expected, but a standard type. I'll investigate, but I don't think that's for 3.1.1.
An even smaller example: public class NodeList<E> { class Cursor { } // type declaration is a standard type { NodeList.Cursor cursor; // NodeList.Cursor is raw! NodeList<String>.Cursor c2; // NodeList<String>.Cursor is standard type } } TTypes currently assume that the type declaration of a raw type is a generic type, which is not the case here. I think that's against the current spec: For parameterized types and raw types, getTypeDeclaration() returns the binding for the corresponding generic type. We have to sort out whether the spec or the implementation should be corrected.
*** Bug 134761 has been marked as a duplicate of this bug. ***
Fixed CCE in HEAD. Treating non-generic member type of generic type like other non-generic types for now. Opened bug 149541 for the full fix.