Source:
<code>static AbstractBrooklynObjectSpec<?, ?> createSpecFromFull(ManagementContext mgmt, RegisteredType item, Class<?> expectedType, Set<String> parentEncounteredTypes, BrooklynClassLoadingContext loaderO) { BrooklynClassLoadingContext loader = CatalogUtils.newClassLoadingContext(mgmt, item, loaderO); Set<String> encounteredTypes; if (item.getSymbolicName() != null) { encounteredTypes = ImmutableSet.<String>builder() .addAll(parentEncounteredTypes) .add(item.getSymbolicName()) .build(); } else { encounteredTypes = parentEncounteredTypes; } AbstractBrooklynObjectSpec<?, ?> spec; String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item); MutableSet<Object> supers = MutableSet.copyOf(item.getSuperTypes()); <START> supers.addIfNotNull(expectedType); <END> if (RegisteredTypes.isSubTypeOf(supers, Policy.class)) { spec = CampInternalUtils.createPolicySpec(planYaml, loader, encounteredTypes); } else if (RegisteredTypes.isSubTypeOf(supers, Location.class)) { spec = CampInternalUtils.createLocationSpec(planYaml, loader, encounteredTypes); } else if (RegisteredTypes.isSubTypeOf(supers, Application.class)) { spec = createEntitySpecFromServicesBlock(planYaml, loader, encounteredTypes, true); } else if (RegisteredTypes.isSubTypeOf(supers, Entity.class)) { spec = createEntitySpecFromServicesBlock(planYaml, loader, encounteredTypes, false); } else { throw new IllegalStateException("Cannot detect spec type from "+item.getSuperTypes()+" for "+item+"\n"+planYaml); } ((AbstractBrooklynObjectSpec<?, ?>)spec).catalogItemId(item.getId()); if (Strings.isBlank( ((AbstractBrooklynObjectSpec<?, ?>)spec).getDisplayName() )) ((AbstractBrooklynObjectSpec<?, ?>)spec).displayName(item.getDisplayName()); return spec; }</code><technical_language>Check item expectedType compatibility</technical_language>

Target:
static AbstractBrooklynObjectSpec<?, ?> createSpecFromFull(ManagementContext mgmt, RegisteredType item, Class<?> expectedType, Set<String> parentEncounteredTypes, BrooklynClassLoadingContext loaderO) { BrooklynClassLoadingContext loader = CatalogUtils.newClassLoadingContext(mgmt, item, loaderO); Set<String> encounteredTypes; if (item.getSymbolicName() != null) { encounteredTypes = ImmutableSet.<String>builder() .addAll(parentEncounteredTypes) .add(item.getSymbolicName()) .build(); } else { encounteredTypes = parentEncounteredTypes; } AbstractBrooklynObjectSpec<?, ?> spec; String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item); MutableSet<Object> supers = MutableSet.copyOf(item.getSuperTypes()); supers.addIfNotNull(expectedType); if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Policy.class)) { spec = CampInternalUtils.createPolicySpec(planYaml, loader, encounteredTypes); } else if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Location.class)) { spec = CampInternalUtils.createLocationSpec(planYaml, loader, encounteredTypes); } else if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Application.class)) { spec = createEntitySpecFromServicesBlock(planYaml, loader, encounteredTypes, true); } else if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Entity.class)) { spec = createEntitySpecFromServicesBlock(planYaml, loader, encounteredTypes, false); } else { throw new IllegalStateException("Cannot detect spec type from "+item.getSuperTypes()+" for "+item+"\n"+planYaml); } if (expectedType!=null && !expectedType.isAssignableFrom(spec.getType())) { throw new IllegalStateException("Creating spec from "+item+", got "+spec.getType()+" which is incompatible with expected "+expectedType); } ((AbstractBrooklynObjectSpec<?, ?>)spec).catalogItemId(item.getId()); if (Strings.isBlank( ((AbstractBrooklynObjectSpec<?, ?>)spec).getDisplayName() )) ((AbstractBrooklynObjectSpec<?, ?>)spec).displayName(item.getDisplayName()); return spec; }