@Override public ITypeBinding[] getTypeParameters() { return originalBinding.getTypeParameters(); }
private String genericTypeParametersFor(IMethodBinding method) { final IMethodBinding bind = method.getMethodDeclaration(); return genericQualifierFor(bind.getTypeParameters()); }
private static Map<ITypeBinding, ITypeBinding> getGenericToConcreteTypeParamsMap( final IMethodBinding method, final IMethodBinding methodErasure) { return getGenericToConcreteTypeParamsMap(method.getTypeArguments(), methodErasure.getTypeParameters()); }
/** * @return a map from type variable key to type variable constraint variable */ private Map<String, IndependentTypeVariable2> createMethodTypeArguments(IMethodBinding methodBinding) { ITypeBinding[] methodTypeParameters= methodBinding.getMethodDeclaration().getTypeParameters(); Map<String, IndependentTypeVariable2> methodTypeVariables; if (methodTypeParameters.length == 0) { methodTypeVariables= Collections.emptyMap(); } else { methodTypeVariables= new HashMap<>(); for (int i= 0; i < methodTypeParameters.length; i++) { ITypeBinding methodTypeParameter= methodTypeParameters[i]; //TODO: typeVariable does not need a type binding - only used in equality constraints TypeVariable typeVariable= (TypeVariable) fTCModel.createTType(methodTypeParameter); IndependentTypeVariable2 typeVariableCv= fTCModel.makeIndependentTypeVariable(typeVariable); methodTypeVariables.put(methodTypeParameter.getKey(), typeVariableCv); } } return methodTypeVariables; }
/** * @return a map from type variable key to type variable constraint variable */ private Map<String, IndependentTypeVariable2> createMethodTypeArguments(IMethodBinding methodBinding) { ITypeBinding[] methodTypeParameters= methodBinding.getMethodDeclaration().getTypeParameters(); Map<String, IndependentTypeVariable2> methodTypeVariables; if (methodTypeParameters.length == 0) { methodTypeVariables= Collections.emptyMap(); } else { methodTypeVariables= new HashMap<>(); for (int i= 0; i < methodTypeParameters.length; i++) { ITypeBinding methodTypeParameter= methodTypeParameters[i]; //TODO: typeVariable does not need a type binding - only used in equality constraints TypeVariable typeVariable= (TypeVariable) fTCModel.createTType(methodTypeParameter); IndependentTypeVariable2 typeVariableCv= fTCModel.makeIndependentTypeVariable(typeVariable); methodTypeVariables.put(methodTypeParameter.getKey(), typeVariableCv); } } return methodTypeVariables; }
/** * @return a map from type variable key to type variable constraint variable */ private Map/*<String, IndependentTypeVariable2>*/ createMethodTypeArguments(IMethodBinding methodBinding) { ITypeBinding[] methodTypeParameters= methodBinding.getMethodDeclaration().getTypeParameters(); Map methodTypeVariables; if (methodTypeParameters.length == 0) { methodTypeVariables= Collections.EMPTY_MAP; } else { methodTypeVariables= new HashMap(); for (int i= 0; i < methodTypeParameters.length; i++) { ITypeBinding methodTypeParameter= methodTypeParameters[i]; //TODO: typeVariable does not need a type binding - only used in equality constraints TypeVariable typeVariable= (TypeVariable) fTCModel.createTType(methodTypeParameter); IndependentTypeVariable2 typeVariableCv= fTCModel.makeIndependentTypeVariable(typeVariable); methodTypeVariables.put(methodTypeParameter.getKey(), typeVariableCv); } } return methodTypeVariables; }
private void checkTempInitializerForLocalTypeUsage() { Expression initializer= fTempDeclarationNode.getInitializer(); if (initializer == null) return; IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer localTypeAnalyer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); initializer.accept(localTypeAnalyer); fInitializerUsesLocalTypes= ! localTypeAnalyer.getUsageOfEnclosingNodes().isEmpty(); }
private void checkTempInitializerForLocalTypeUsage() { Expression initializer= fTempDeclarationNode.getInitializer(); if (initializer == null) return; IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer localTypeAnalyer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); initializer.accept(localTypeAnalyer); fInitializerUsesLocalTypes= ! localTypeAnalyer.getUsageOfEnclosingNodes().isEmpty(); }
private void checkTempInitializerForLocalTypeUsage() { Expression initializer= fTempDeclarationNode.getInitializer(); if (initializer == null) return; IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer localTypeAnalyer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); initializer.accept(localTypeAnalyer); fInitializerUsesLocalTypes= ! localTypeAnalyer.getUsageOfEnclosingNodes().isEmpty(); }
public static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) { ITypeBinding[] typeParams= binding.getTypeParameters(); List<TypeParameter> typeParameters= decl.typeParameters(); for (int i= 0; i < typeParams.length; i++) { ITypeBinding curr= typeParams[i]; TypeParameter newTypeParam= ast.newTypeParameter(); newTypeParam.setName(ast.newSimpleName(curr.getName())); ITypeBinding[] typeBounds= curr.getTypeBounds(); if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$ List<Type> newTypeBounds= newTypeParam.typeBounds(); for (int k= 0; k < typeBounds.length; k++) { newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND)); } } typeParameters.add(newTypeParam); } }
private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) { ITypeBinding[] typeParams= binding.getTypeParameters(); List<TypeParameter> typeParameters= decl.typeParameters(); for (int i= 0; i < typeParams.length; i++) { ITypeBinding curr= typeParams[i]; TypeParameter newTypeParam= ast.newTypeParameter(); newTypeParam.setName(ast.newSimpleName(curr.getName())); ITypeBinding[] typeBounds= curr.getTypeBounds(); if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$ List<Type> newTypeBounds= newTypeParam.typeBounds(); for (int k= 0; k < typeBounds.length; k++) { newTypeBounds.add(imports.addImport(typeBounds[k], ast, context)); } } typeParameters.add(newTypeParam); } }
private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context)); intermediary.typeParameters().add(parameter); } }
private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context, TypeLocation.TYPE_BOUND)); intermediary.typeParameters().add(parameter); } }
private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST())); intermediary.typeParameters().add(parameter); } }
@Override public final boolean visit(final SimpleName node) { final ITypeBinding binding= node.resolveTypeBinding(); if (binding != null && binding.isTypeVariable()) { String name= null; for (int index= 0; index < fMapping.length; index++) { name= binding.getName(); if (fMapping[index].getSourceName().equals(name) && node.getIdentifier().equals(name)) { final MethodDeclaration declaration= ASTNodes.getParent(node, MethodDeclaration.class); if (declaration != null) { final IMethodBinding method= declaration.resolveBinding(); if (method != null) { final ITypeBinding[] bindings= method.getTypeParameters(); for (int offset= 0; offset < bindings.length; offset++) { if (bindings[offset].isEqualTo(binding)) return true; } } } fRewrite.set(node, SimpleName.IDENTIFIER_PROPERTY, fMapping[index].getTargetName(), null); } } } return true; } }
public final boolean visit(final SimpleName node) { final ITypeBinding binding= node.resolveTypeBinding(); if (binding != null && binding.isTypeVariable()) { String name= null; for (int index= 0; index < fMapping.length; index++) { name= binding.getName(); if (fMapping[index].getSourceName().equals(name) && node.getIdentifier().equals(name)) { final MethodDeclaration declaration= (MethodDeclaration) ASTNodes.getParent(node, MethodDeclaration.class); if (declaration != null) { final IMethodBinding method= declaration.resolveBinding(); if (method != null) { final ITypeBinding[] bindings= method.getTypeParameters(); for (int offset= 0; offset < bindings.length; offset++) { if (bindings[offset].isEqualTo(binding)) return true; } } } fRewrite.set(node, SimpleName.IDENTIFIER_PROPERTY, fMapping[index].getTargetName(), null); } } } return true; } }
private IConstructor computeMethodTypeSymbol(ISourceLocation decl, IMethodBinding binding, boolean isDeclaration) { IList parameters = computeTypes(isDeclaration ? binding.getParameterTypes() : binding.getTypeArguments(), false); if (binding.isConstructor()) { return constructorSymbol(decl, parameters); } else { IList typeParameters = computeTypes(isDeclaration ? binding.getTypeParameters() : binding.getTypeArguments(), isDeclaration); IConstructor retSymbol = resolveType(binding.getReturnType(), false); return methodSymbol(decl, typeParameters, retSymbol, parameters); } }
private RefactoringStatus checkTempTypeForLocalTypeUsage(){ VariableDeclarationStatement vds= getTempDeclarationStatement(); if (vds == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote); Type type= vds.getType(); ITypeBinding binding= type.resolveBinding(); if (binding == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote); IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer analyzer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); type.accept(analyzer); boolean usesLocalTypes= ! analyzer.getUsageOfEnclosingNodes().isEmpty(); fTempTypeUsesClassTypeVariables= analyzer.getClassTypeVariablesUsed(); if (usesLocalTypes) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally); return null; }
private RefactoringStatus checkTempTypeForLocalTypeUsage(){ VariableDeclarationStatement vds= getTempDeclarationStatement(); if (vds == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote); Type type= vds.getType(); ITypeBinding binding= type.resolveBinding(); if (binding == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote); IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer analyzer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); type.accept(analyzer); boolean usesLocalTypes= ! analyzer.getUsageOfEnclosingNodes().isEmpty(); fTempTypeUsesClassTypeVariables= analyzer.getClassTypeVariablesUsed(); if (usesLocalTypes) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally); return null; }
private RefactoringStatus checkTempTypeForLocalTypeUsage(){ VariableDeclarationStatement vds= getTempDeclarationStatement(); if (vds == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote); Type type= vds.getType(); ITypeBinding binding= type.resolveBinding(); if (binding == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote); IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer analyzer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); type.accept(analyzer); boolean usesLocalTypes= ! analyzer.getUsageOfEnclosingNodes().isEmpty(); fTempTypeUsesClassTypeVariables= analyzer.getClassTypeVariablesUsed(); if (usesLocalTypes) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally); return null; }