@Test public void testReplaceTypeVariables() { Map<String, TypeUsage> typeParams = ImmutableMap.of("A", string, "B", object); assertEquals(invokableA, invokableA.replaceTypeVariables(Collections.emptyMap())); assertEquals(invokableA, invokableA.replaceTypeVariables(typeParams)); assertEquals(invokableB, invokableB.replaceTypeVariables(Collections.emptyMap())); assertEquals(invokableB, invokableB.replaceTypeVariables(typeParams)); assertEquals(invokableC, invokableC.replaceTypeVariables(Collections.emptyMap())); assertNotEquals(invokableC, invokableC.replaceTypeVariables(typeParams)); TypeUsage invokableCReplaced = invokableC.replaceTypeVariables(typeParams); InternalInvokableDefinition internalCReplaced = new InternalMethodDefinition( "bar", ImmutableList.of(), string, new JvmMethodDefinition("a/b/MyClass", "internalC", "()A", false, true)); assertEquals(new InvokableReferenceTypeUsage(internalCReplaced), invokableCReplaced); assertEquals(invokableD, invokableD.replaceTypeVariables(Collections.emptyMap())); assertEquals(invokableD, invokableD.replaceTypeVariables(typeParams)); }
@Override public <T extends TypeUsage> TypeUsage replaceTypeVariables(Map<String, T> typeParams) { if (typeParams.isEmpty()) { return this; } List<FormalParameterSymbol> replacedParams = internalInvokableDefinition .getFormalParameters() .stream() .map((fp) -> new FormalParameterSymbol( fp.getType().replaceTypeVariables(typeParams), fp.getName(), fp.hasDefaultValue())) .collect(Collectors.toList()); if (internalInvokableDefinition.isMethod()) { return new InvokableReferenceTypeUsage(new InternalMethodDefinition( internalInvokableDefinition.asMethod().getMethodName(), replacedParams, internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), internalInvokableDefinition.asMethod().getJvmMethodDefinition())); } else if (internalInvokableDefinition.isConstructor()) { return new InvokableReferenceTypeUsage(new InternalConstructorDefinition( internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), replacedParams, internalInvokableDefinition.asConstructor().getJvmConstructorDefinition())); } else { throw new UnsupportedOperationException(); } }
InvokableReferenceTypeUsage implements TypeUsage, Invokable { @Override public <T extends TypeUsage> TypeUsage replaceTypeVariables(Map<String, T> typeParams) { if (typeParams.isEmpty()) { return this; } List<FormalParameterSymbol> replacedParams = internalInvokableDefinition .getFormalParameters() .stream() .map((fp) -> new FormalParameterSymbol( fp.getType().replaceTypeVariables(typeParams), fp.getName(), fp.hasDefaultValue())) .collect(Collectors.toList()); if (internalInvokableDefinition.isMethod()) { return new InvokableReferenceTypeUsage(new InternalMethodDefinition( internalInvokableDefinition.asMethod().getMethodName(), replacedParams, internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), internalInvokableDefinition.asMethod().getJvmMethodDefinition())); } else if (internalInvokableDefinition.isConstructor()) { return new InvokableReferenceTypeUsage(new InternalConstructorDefinition( internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), replacedParams, internalInvokableDefinition.asConstructor().getJvmConstructorDefinition())); } else { throw new UnsupportedOperationException(); } } }
InvokableReferenceTypeUsage implements TypeUsage, Invokable { @Override public <T extends TypeUsage> TypeUsage replaceTypeVariables(Map<String, T> typeParams) { if (typeParams.isEmpty()) { return this; } List<FormalParameterSymbol> replacedParams = internalInvokableDefinition .getFormalParameters() .stream() .map((fp) -> new FormalParameterSymbol( fp.getType().replaceTypeVariables(typeParams), fp.getName(), fp.hasDefaultValue())) .collect(Collectors.toList()); if (internalInvokableDefinition.isMethod()) { return new InvokableReferenceTypeUsage(new InternalMethodDefinition( internalInvokableDefinition.asMethod().getMethodName(), replacedParams, internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), internalInvokableDefinition.asMethod().getJvmMethodDefinition())); } else if (internalInvokableDefinition.isConstructor()) { return new InvokableReferenceTypeUsage(new InternalConstructorDefinition( internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), replacedParams, internalInvokableDefinition.asConstructor().getJvmConstructorDefinition())); } else { throw new UnsupportedOperationException(); } } InvokableReferenceTypeUsage(InternalInvokableDefinition internalInvokableDefinition); }
InvokableReferenceTypeUsage implements TypeUsage, Invokable { @Override public <T extends TypeUsage> TypeUsage replaceTypeVariables(Map<String, T> typeParams) { if (typeParams.isEmpty()) { return this; } List<FormalParameterSymbol> replacedParams = internalInvokableDefinition .getFormalParameters() .stream() .map((fp) -> new FormalParameterSymbol( fp.getType().replaceTypeVariables(typeParams), fp.getName(), fp.hasDefaultValue())) .collect(Collectors.toList()); if (internalInvokableDefinition.isMethod()) { return new InvokableReferenceTypeUsage(new InternalMethodDefinition( internalInvokableDefinition.asMethod().getMethodName(), replacedParams, internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), internalInvokableDefinition.asMethod().getJvmMethodDefinition())); } else if (internalInvokableDefinition.isConstructor()) { return new InvokableReferenceTypeUsage(new InternalConstructorDefinition( internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), replacedParams, internalInvokableDefinition.asConstructor().getJvmConstructorDefinition())); } else { throw new UnsupportedOperationException(); } } InvokableReferenceTypeUsage(InternalInvokableDefinition internalInvokableDefinition); @Override TypeUsage replaceTypeVariables(Map<String, T> typeParams); @Override boolean sameType(TypeUsage other); @Override boolean isInvokable(); @Override Invokable asInvokable(); @Override JvmType jvmType(); @Override boolean hasInstanceField(String fieldName, Symbol instance); @Override Symbol getInstanceField(String fieldName, Symbol instance); @Override Optional<Invokable> getMethod(String method, boolean staticContext); @Override boolean canBeAssignedTo(TypeUsage type); @Override boolean isOverloaded(); @Override Optional<InternalInvokableDefinition> internalInvokableDefinitionFor(List<ActualParam> actualParams); @Override String describe(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
InvokableReferenceTypeUsage implements TypeUsage, Invokable { @Override public <T extends TypeUsage> TypeUsage replaceTypeVariables(Map<String, T> typeParams) { if (typeParams.isEmpty()) { return this; } List<FormalParameterSymbol> replacedParams = internalInvokableDefinition .getFormalParameters() .stream() .map((fp) -> new FormalParameterSymbol( fp.getType().replaceTypeVariables(typeParams), fp.getName(), fp.hasDefaultValue())) .collect(Collectors.toList()); if (internalInvokableDefinition.isMethod()) { return new InvokableReferenceTypeUsage(new InternalMethodDefinition( internalInvokableDefinition.asMethod().getMethodName(), replacedParams, internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), internalInvokableDefinition.asMethod().getJvmMethodDefinition())); } else if (internalInvokableDefinition.isConstructor()) { return new InvokableReferenceTypeUsage(new InternalConstructorDefinition( internalInvokableDefinition.getReturnType().replaceTypeVariables(typeParams), replacedParams, internalInvokableDefinition.asConstructor().getJvmConstructorDefinition())); } else { throw new UnsupportedOperationException(); } } InvokableReferenceTypeUsage(InternalInvokableDefinition internalInvokableDefinition); @Override TypeUsage replaceTypeVariables(Map<String, T> typeParams); @Override boolean sameType(TypeUsage other); @Override boolean isInvokable(); @Override Invokable asInvokable(); @Override JvmType jvmType(); @Override boolean hasInstanceField(String fieldName, Symbol instance); @Override Symbol getInstanceField(String fieldName, Symbol instance); @Override Optional<Invokable> getMethod(String method, boolean staticContext); @Override boolean canBeAssignedTo(TypeUsage type); @Override boolean isOverloaded(); @Override Optional<InternalInvokableDefinition> internalInvokableDefinitionFor(List<ActualParam> actualParams); @Override String describe(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }