public static List<SType<?>> listAscendants(SType<?> root, boolean includeRoot) { final List<SType<?>> list = new ArrayList<>(); if (includeRoot) list.add(root); SScope tipo = root.getParentScope(); while (tipo != null) { if (tipo instanceof SType<?>) list.add((SType<?>) tipo); tipo = tipo.getParentScope(); } return list; } }
@Override @Nonnull public String getName() { if (nameFull == null) { this.nameFull = getParentScope().getName() + '.' + nameSimple; } return nameFull; }
private boolean isTypeChildrenOf(STypeComposite<?> composite, SType<?> currentValue) { for (SScope parent = currentValue.getParentScope(); parent != null; parent = parent.getParentScope()) { if (parent == composite) { return true; } } return false; }
public static List<SType<?>> listAscendants(SType<?> root, boolean includeRoot) { final List<SType<?>> list = new ArrayList<>(); if (includeRoot) list.add(root); SScope type = root.getParentScope(); while (type != null) { if (type instanceof SType<?>) list.add((SType<?>) type); type = type.getParentScope(); } return list; }
private boolean isTypeChildrenOf(STypeComposite<?> composite, SType<?> currentValue) { for (SScope parent = currentValue.getParentScope(); parent != null; parent = parent.getParentScope()) { if (parent == composite) { return true; } } return false; }
@Nonnull @Override public final SPackage getPackage() { if (pkg == null) { pkg = getParentScope().getPackage(); } return pkg; }
/*** * Retorna optional empty caso já seja a raiz * * @param root * @return */ public static Optional<SType<?>> findRootAscendant(SType<?> root) { SScope type = root.getParentScope(); SType<?> rootStype = null; while (type != null) { if (type instanceof SType<?>) { rootStype = (SType<?>) type; } type = type.getParentScope(); } return Optional.ofNullable(rootStype); }
/** * Verifica se o tipo é uma extensão de um tipo da mesma classe e que possui uma referência a ele mesmo. Vai * indicar true somente para a referência interna dentro da referência circular, ou seja, o tipo (ou classe) que * contêm o campo não será marcado como referência circular, somente o campo em si. */ private boolean isRecursiveReference(@Nonnull SType<?> type) { for(SScope parent = type.getParentScope(); parent instanceof SType; parent = parent.getParentScope()) { if(parent == type || parent == type.getSuperType()) { return true; } } return false; }
private static void ensureType(ContextArchive ctx, SType<?> type) { while (type.getParentScope() instanceof SType) { type = (SType<?>) type.getParentScope(); } if (!ctx.isNecessaryToArchive(type) || ctx.isAlreadyArchived(type)) { return; } SIPersistenceType pType = ctx.createTypeInPackage(type); writeType(ctx, pType, type); }
/** * Verifica se o tipo é uma extensão de um tipo da mesma classe e que possui uma referência a ele mesmo. Vai * indicar true somente para a referência interna dentro da referência circular, ou seja, o tipo (ou classe) que * contêm o campo não será marcado como referência circular, somente o campo em si. */ private boolean isRecursiveReference(SType<?> type) { for(SScope parent = type.getParentScope(); parent instanceof SType; parent = parent.getParentScope()) { if(parent == type || parent == type.getSuperType()) { return true; } } return false; }
private void debugTypeHeaderAttribute(Appendable appendable) throws IOException { appendable.append("defAtt ").append(getNameSimple()).append('@').append(Integer.toString(getTypeId())); SType<?> owner = getAttrInternalRef().getOwner(); if (owner != null && owner != getParentScope()) { appendable.append(" for "); appendNameAndId(appendable, owner); } if (isSelfReference()) { appendable.append(" (SELF)"); } }
private void debugTypeHeaderAttribute(Appendable appendable) throws IOException { appendable.append("defAtt ").append(getNameSimple()).append('@').append(Integer.toString(getTypeId())); SType<?> owner = getAttributeDefinitionInfo().getOwner(); if (owner != null && owner != getParentScope()) { appendable.append(" for "); appendNameAndId(appendable, owner); } if (isSelfReference()) { appendable.append(" (SELF)"); } }
private static void ensureType(ContextArchive ctx, SType<?> type) { SType<?> currentType = type; for (SScope t = type.getParentScope(); t instanceof SType; t = ((SType<?>) t).getParentScope()) { currentType = (SType<?>) t; } if (!ctx.isNecessaryToArchive(currentType) || ctx.isAlreadyArchived(currentType)) { return; } SIPersistenceType pType = ctx.createTypeInPackage(currentType); writeType(ctx, pType, currentType); }
public SType<?> tableContext(SType<?> type) { SType<?> result = type; while (table(result) == null && !result.getParentScope().equals(result.getPackage())) { result = result.getDictionary().getType(result.getParentScope().getName()); } return result; }
private String suppressPackage(String name, boolean aggressive) { if (isEqualsStart(name, getName())) { return name.substring(getName().length() + 1); } else if (isEqualsStart(name, getParentScope().getName())) { return name.substring(getParentScope().getName().length() + 1); } else if (isEqualsStart(name, SPackageCore.NAME)) { String v = name.substring(SPackageCore.NAME.length() + 1); if (aggressive && isEqualsStart(v, "SType")) { v = v.substring(6); } return v; } else if (aggressive && isEqualsStart(name, SPackageBasic.NAME)) { return name.substring(SPackageBasic.NAME.length() + 1); } return name; }
private String suppressPackage(String name, boolean aggressive) { String thisName = getName(); if (isEqualsStart(name, thisName)) { return name.substring(thisName.length() + 1); } else { String parentScopeName = getParentScope().getName(); if (isEqualsStart(name, parentScopeName)) { return name.substring(parentScopeName.length() + 1); } else if (isEqualsStart(name, SPackageCore.NAME)) { String v = name.substring(SPackageCore.NAME.length() + 1); if (aggressive && isEqualsStart(v, "SType")) { v = v.substring(6); } return v; } else if (aggressive && isEqualsStart(name, SPackageBasic.NAME)) { return name.substring(SPackageBasic.NAME.length() + 1); } else if (isEqualsStart(name, getPackage().getName())) { return name.substring(getPackage().getName().length() + 1); } } return name; }
/** * Veririca se o super tipo do composite pai do campo atual possui um campo de mesmo nome que é o super tipo do * campo atual, ou seja, verifica se o campo atual é uma extensão correta de um tipo que pertencia ao composite * original. */ public AssertionsSType isExtensionOfParentCompositeFieldReference() { Assertions.assertThat(getTarget().getParentScope()).isInstanceOf(STypeComposite.class); STypeComposite parent = (STypeComposite) getTarget().getParentScope(); new AssertionsSType(parent.getSuperType()).isInstanceOf(parent.getClass()); STypeComposite parent2 = (STypeComposite) parent.getSuperType(); SType<?> parentRef = parent2.getField(getTarget().getNameSimple()); return isDirectExtensionOf(parentRef); }
/** Resolve o valor encontrado em referencia ao tipo destino, mesmo se for um sub campo de um sub campo. */ private SType<?> tryToFindInHierarchy(STypeComposite composite, SScope scope, String nextType) { if (!(scope instanceof SType)) { return null; } SType<?> parent = (SType<?>) scope; if (composite.getSuperType() == parent) { return composite.getLocalType(nextType); } SType<?> newParent = tryToFindInHierarchy(composite, parent.getParentScope(), parent.getNameSimple()); return (newParent == null) ? null : newParent.getLocalType(nextType); }
/** Resolve o valor encontrado em referencia ao tipo destino, mesmo se for um sub campo de um sub campo. */ private SType<?> tryToFindInHierarchy(STypeComposite composite, SScope scope, String nextType) { if (!(scope instanceof SType)) { return null; } SType<?> parent = (SType<?>) scope; if (composite.getSuperType() == parent) { return composite.getLocalType(nextType); } SType<?> newParent = tryToFindInHierarchy(composite, parent.getParentScope(), parent.getNameSimple()); return (newParent == null) ? null : newParent.getLocalType(nextType); }
composite.getSuperType() + ", que é a instância pai de " + composite + "")); SType<?> newFieldValue = tryToFindInHierarchy(composite, parentValue.getParentScope(),parentValue.getNameSimple()); if (newFieldValue != null) {