/** * Checks if is subtype of string. * * @param item the item * @return true, if is subtype of string */ private boolean isSubtypeOfString(TableTreeItem item) { TypeDescription td = getTypeDescriptionFromTableTreeItem(item); return CAS.TYPE_NAME_STRING.equals(td.getSupertypeName()); }
private boolean isFeatureStructure(String rangeTypeName) { if (rangeTypeName.equals("uima.tcas.Annotation") || rangeTypeName.equals("uima.cas.TOP")) { return true; } TypeDescription type = typeDescriptionMap.get(rangeTypeName); if (type == null) { return false; } String supertypeName = type.getSupertypeName(); if (supertypeName != null) { return isFeatureStructure(supertypeName); } return false; }
/** * Determines whether one type subsumes another. * * @param aType1Name * name of first type * @param aType2Name * name of second type * @param aNameMap * Map from type names to TypeDescriptions * * @return true if and only if the type named <code>aType1Name</code> subsumes the type named * <code>aType2Name</code> according to the information given in the * <code>aNameMap</code>. */ protected static boolean subsumes(String aType1Name, String aType2Name, Map<String, ? extends TypeDescription> aNameMap) { // Top type subsumes everything if (CAS.TYPE_NAME_TOP.equals(aType1Name)) { return true; } // "walk up the tree" from aType2Name until we reach aType1Name or null String current = aType2Name; while (current != null && !current.equals(aType1Name)) { TypeDescription curType = aNameMap.get(current); if (curType == null) current = null; else current = curType.getSupertypeName(); } return (current != null); }
private Set<FeatureDescription> getAllDeclaredFeatures(TypeDescription typeDescription, Map<String, TypeDescription> typeMap) { Set<FeatureDescription> result = new HashSet<FeatureDescription>(); if (typeDescription == null) { return result; } FeatureDescription[] features = typeDescription.getFeatures(); if (features == null) { return result; } result.addAll(Arrays.asList(features)); String supertypeName = typeDescription.getSupertypeName(); if (supertypeName != null) { TypeDescription parent = typeMap.get(supertypeName); result.addAll(getAllDeclaredFeatures(parent, typeMap)); } return result; }
/** * Type requires type. * * @param upstreamType the upstream type * @param typeName the type name * @return true, if successful */ private boolean typeRequiresType(TypeDescription upstreamType, String typeName) { if (null == typeName) return false; if (typeName.equals(upstreamType.getSupertypeName())) { return true; } FeatureDescription[] features = upstreamType.getFeatures(); if (features == null) { return false; } for (int i = 0; i < features.length; i++) { if (typeName.equals(features[i].getRangeTypeName())) { return true; } } return false; }
private void inferFeatureMap(TypeDescription type) { // 1 - Recursively add features of the super type TypeDescription superType = typeSystemDescription.getType(type.getSupertypeName()); if(superType != null) inferFeatureMap(superType); // 2 - Add features of this type for(FeatureDescription feature:type.getFeatures()) { String featureFQN = type.getName() + ":" + feature.getName(); featureMap.put(feature.getName(), featureFQN); featureMap.put(featureFQN, featureFQN); } }
@Override public boolean isValid() { if (typeName.length() == 0) return false; if (typeName.charAt(typeName.length() - 1) == '.') { setErrorMessage("Name cannot end with a period (.)"); return false; } if (!typeName.equals(originalTypeName)) { String errMsg = typeSection.checkDuplTypeName(typeName); if (null != errMsg) { setErrorMessage(errMsg); return false; } } if (!typeContainedInTypeSystemInfoList(supertypeName, allTypesList)) { setErrorMessage("SuperType '" + supertypeName + "' is unknown. If this is intended, please define it first."); return false; } TypeDescription importedType = editor.getImportedTypeSystemDesription().getType(typeName); if (null != importedType) { if (!supertypeName.equals(importedType.getSupertypeName())) { setErrorMessage("The supertype specified must be '" + importedType.getSupertypeName() + "' due to merging with imported types. Please change it to this type."); return false; } } return true; }
/** * gets a feature description for a type, including supertypes. * * @param td the td * @param featureName the feature name * @return a feature description for a type, including supertypes */ public FeatureDescription getFeature(TypeDescription td, String featureName) { FeatureDescription[] features = td.getFeatures(); String supertypeName; if (null != features) for (int i = 0; i < features.length; i++) { if (featureName.equals(features[i].getName())) return features[i]; } if (null != (supertypeName = td.getSupertypeName())) if (!CAS.TYPE_NAME_TOP.equals(supertypeName)) { TypeDescription supertype = getMergedTypeSystemDescription().getType(supertypeName); if (null == supertype) supertype = (TypeDescription) BuiltInTypes.typeDescriptions.get(supertypeName); return getFeature(supertype, featureName); } return null; }
descriptionUI.setText(convertNull(existingTd.getDescription())); typeNameUI.setText(originalTypeName = existingTd.getName()); supertypeNameUI.setText(convertNull(existingTd.getSupertypeName()));
if (type.getSupertypeName() == null) { throw new NoResultException( "No more super-types - no suitable layer definition found for type [" type = tsd.getType(type.getSupertypeName());
if (type.getSupertypeName() == null) { throw new NoResultException( "No more super-types - no suitable layer definition found for type [" type = tsd.getType(type.getSupertypeName());
/** * Update gui type. * * @param item the item * @param td the td */ private void updateGuiType(TableTreeItem item, TypeDescription td) { item.setText(NAME_COL, formatName(td.getName())); item.setText(SUPER_COL, formatName(td.getSupertypeName())); }
if (td.getSupertypeName().equals("uima.cas.String")) continue; if (limitJCasGenToProjectScope &&
Collection collectImports(TypeDescription td, boolean _Type) { if (_Type) _imports.clear(); else imports.clear(); collectImport(td.getName(), _Type); collectImport(td.getSupertypeName(), _Type); if (!_Type) { FeatureDescription[] fds = td.getFeatures(); for (int i = 0; i < fds.length; i++) { FeatureDescription fd = fds[i]; if (null != typeSystem) { String rangeTypeNameCAS = fd.getRangeTypeName(); Type rangeCasType = typeSystem.getType(rangeTypeNameCAS); if (typeSystem.subsumes(casStringType, rangeCasType)) continue; } collectImport(fd.getRangeTypeName(), false); if (hasArrayRange(fd)) { collectImport(getJavaRangeArrayElementType(fd), false); } } } return (_Type) ? _imports.values() : imports.values(); }
imports.clear(); collectImport(td.getName(), _Type); collectImport(td.getSupertypeName(), _Type);
/** * Type update. * * @param td the td * @param dialog the dialog */ private void typeUpdate(TypeDescription td, AddTypeDialog dialog) { td.setName(setValueChanged(dialog.typeName, td.getName())); td.setDescription(setValueChanged(multiLineFix(dialog.description), td.getDescription())); td.setSupertypeName(setValueChanged(dialog.supertypeName, td.getSupertypeName())); }
if (!Objects.equals(tdesc.getSupertypeName(), ts.getParent(t).getName())) { log.info("CAS update required: supertypes of {} do not match: {} <-> {}", tdesc.getName(), tdesc.getSupertypeName(), ts.getParent(t).getName()); upgradeRequired = true; break nextType;
if (!Objects.equals(tdesc.getSupertypeName(), ts.getParent(t).getName())) { log.info("CAS update required: supertypes of {} do not match: {} <-> {}", tdesc.getName(), tdesc.getSupertypeName(), ts.getParent(t).getName()); upgradeRequired = true; break nextType;
private static void addTypeToMergedTypeSystem(Map<String, Set<String>> aOutputMergedTypes, Map<String,TypeDescription> typeNameMap, TypeDescription type) throws ResourceInitializationException { String typeName = type.getName(); String supertypeName = type.getSupertypeName(); TypeDescription existingType = typeNameMap.get(typeName); if (existingType == null) { String existingSupertypeName = existingType.getSupertypeName(); if (!existingSupertypeName.equals(supertypeName)) {
TableTreeItem item = new TableTreeItem(tt, SWT.NONE); item.setText(NAME_COL, formatName(td.getName())); item.setText(SUPER_COL, formatName(td.getSupertypeName())); item.setData(td); setItemColor(item, isLocalType(td));