Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
#32 added IT for parameter declarations on inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkMahler committed Jun 4, 2021
1 parent 8c776e6 commit a372290
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.List;

import com.buschmais.xo.api.annotation.ResultOf;
import com.buschmais.xo.api.annotation.ResultOf.Parameter;
import com.buschmais.xo.neo4j.api.annotation.Cypher;
import com.buschmais.xo.neo4j.api.annotation.Label;
import com.buschmais.xo.neo4j.api.annotation.Relation;
import com.buschmais.xo.neo4j.api.annotation.Relation.Outgoing;
Expand All @@ -13,4 +16,7 @@ public interface ParameterizedTypeDescriptor extends BoundDescriptor {
@Relation
List<HasActualTypeArgumentDescriptor> getActualTypeArguments();

@ResultOf
@Cypher("MATCH (parameterizedType),(typeArgument) WHERE id(parameterizedType)=$this and id(typeArgument)=$typeArgument MERGE (parameterizedType)-[:HAS_ACTUAL_TYPE_ARGUMENT{index:$index}]->(typeArgument)")
void addActualTypeArgument(@Parameter("index") int index, @Parameter("typeArgument") BoundDescriptor typeArgument);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.generics.*;
import com.buschmais.jqassistant.plugin.java.api.model.generics.BoundDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.generics.GenericArrayTypeDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.generics.ParameterizedTypeDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.generics.TypeVariableDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.generics.WildcardTypeDescriptor;
import com.buschmais.jqassistant.plugin.java.api.scanner.SignatureHelper;
import com.buschmais.jqassistant.plugin.java.api.scanner.TypeCache;
import com.buschmais.jqassistant.plugin.java.impl.scanner.visitor.VisitorHelper;
Expand Down Expand Up @@ -79,6 +83,7 @@ protected void apply(TypeDescriptor rawTypeBound, BoundDescriptor bound) {

@Override
public final void visitTypeArgument() {
System.out.println("test");
}

@Override
Expand All @@ -88,16 +93,12 @@ public final SignatureVisitor visitTypeArgument(char wildcard) {
return new AbstractBoundVisitor(visitorHelper, containingType) {
@Override
protected void apply(TypeDescriptor rawTypeBound, BoundDescriptor bound) {
HasActualTypeArgumentDescriptor hasActualTypeArgument = visitorHelper.getStore().create(parameterizedType,
HasActualTypeArgumentDescriptor.class, bound);
hasActualTypeArgument.setIndex(currentTypeParameterIndex++);
addActualArgumentType(parameterizedType, bound);
}
};
} else {
WildcardTypeDescriptor wildcardType = visitorHelper.getStore().create(WildcardTypeDescriptor.class);
HasActualTypeArgumentDescriptor hasActualTypeArgument = visitorHelper.getStore().create(parameterizedType, HasActualTypeArgumentDescriptor.class,
wildcardType);
hasActualTypeArgument.setIndex(currentTypeParameterIndex++);
addActualArgumentType(parameterizedType, wildcardType);
return new AbstractBoundVisitor(visitorHelper, containingType) {
@Override
protected void apply(TypeDescriptor rawTypeBound, BoundDescriptor bound) {
Expand All @@ -114,6 +115,10 @@ protected void apply(TypeDescriptor rawTypeBound, BoundDescriptor bound) {
}
}

private void addActualArgumentType(ParameterizedTypeDescriptor parameterizedType, BoundDescriptor argumentType) {
parameterizedType.addActualTypeArgument(currentTypeParameterIndex++, argumentType);
}

private void apply(BoundDescriptor bound) {
TypeDescriptor rawType = getRawTypeBound(bound);
apply(rawType != null ? rawType : visitorHelper.resolveType(DEFAULT_RAW_TYPE_BOUND, containingType).getTypeDescriptor(), bound);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.buschmais.jqassistant.plugin.java.test.scanner.generics;

import java.io.Serializable;
import java.lang.reflect.*;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.AbstractList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,6 +63,30 @@ void outerClassTypeParameters() {
store.commitTransaction();
}

@Test
void innerClassTypeParameters() {
scanClasses(GenericTypeDeclarations.Inner.class);
store.beginTransaction();
List<TypeVariableDescriptor> declaredTypeParameters = query(
"MATCH (:Type:GenericDeclaration{name:'GenericTypeDeclarations$Inner'})-[declares:DECLARES_TYPE_PARAMETER]->(typeParameter:Java:ByteCode:Bound:TypeVariable) "
+ //
"RETURN typeParameter ORDER BY declares.index").getColumn("typeParameter");
assertThat(declaredTypeParameters).hasSize(1);
TypeVariableDescriptor x = declaredTypeParameters.get(0);
assertThat(x.getName().equals("X"));
List<BoundDescriptor> xBounds = x.getBounds();
assertThat(xBounds.size()).isEqualTo(1);
assertThat(xBounds.get(0).getRawType()).is(matching(typeDescriptor(Object.class)));
List<TypeVariableDescriptor> requiredTypeParameters = query(
"MATCH (:Type:GenericDeclaration{name:'GenericTypeDeclarations$Inner'})-[declares:REQUIRES_TYPE_PARAMETER]->(typeParameter:Java:ByteCode:Bound:TypeVariable) "
+ //
"RETURN typeParameter").getColumn("typeParameter");
assertThat(requiredTypeParameters).hasSize(1);
TypeVariableDescriptor y = declaredTypeParameters.get(0);
assertThat(y.getName().equals("Y"));
store.commitTransaction();
}

@Test
void implementsGeneric() {
evaluate("genericInterfaces", ImplementsGeneric.class.getGenericInterfaces(), 0);
Expand Down Expand Up @@ -105,7 +133,6 @@ void fieldOfTypeVariable() {
store.commitTransaction();
}

@TestStore(type = TestStore.Type.REMOTE)
@Test
void fieldOfParameterizedType() {
scanClasses(GenericFields.class);
Expand Down

0 comments on commit a372290

Please sign in to comment.