package bluej.parser.entity;

import java.util.Iterator;
import java.util.List;

import bluej.debugger.gentype.GenTypeSolid;
import bluej.debugger.gentype.IntersectionType;
import bluej.debugger.gentype.JavaType;
import bluej.debugger.gentype.Reflective;
import threadchecker.OnThread;
import threadchecker.Tag;


| An entity representing intersection types (such as the bounds for type parameters). | | @author Davin McCall | public class IntersectionTypeEntity extends JavaEntity{ private List<JavaEntity> types;
| Get an entity representing an intersection of the given types. If there are no types, | this yields a "java.lang.Object" entity. If there is only one type, this returns that | * type. */ @OnThread(Tag.FXPlatform) public static JavaEntity getIntersectionEntity(List<JavaEntity> types, EntityResolver resolver) | |
{ | |
if (types.size() == 0) { | | return resolver.resolveQualifiedClass("java.lang.Object"); } if (types.size() == 1) { return types.get(0); } return new IntersectionTypeEntity(types); } private IntersectionTypeEntity(List<JavaEntity> types) | | { | | this.types = types; | | } | | @Override | | public String getName() | | { | | Iterator<JavaEntity> i = types.iterator(); | | String name = i.next().getName(); | | for ( ; i.hasNext(); ) { | | name += "&" + i.next().getName(); } return name; } @Override public JavaEntity getSubentity(String name, Reflective accessSource) { return null; | | } | | @Override | | @OnThread(Tag.FXPlatform) | | public JavaType getType() | | { | | GenTypeSolid [] components = new GenTypeSolid[types.size()]; | | int index = 0; | | for (JavaEntity type : types) { | | TypeEntity tent = type.resolveAsType(); | | if (tent == null) { | | return null; | | } | | components[index] = tent.getType().asSolid(); | | if (components[index++] == null) { | | // Not a "solid" type. return null; } } return IntersectionType.getIntersection(components); } @Override public JavaEntity setTypeArgs(List<TypeArgumentEntity> tparams) | | { | | return null; | | } | | @Override | | public TypeEntity resolveAsType() | | { | | JavaType type = getType(); | | if (type == null) { | | return null; | | } | | return new TypeEntity(type); | | } | | }
top, use, map, class IntersectionTypeEntity




15 neLoCode + 45 LoComm