All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cds.reflect.impl.CdsDefinitionBuilder Maven / Gradle / Ivy

/*******************************************************************
 * © 2020 SAP SE or an SAP affiliate company. All rights reserved. *
 *******************************************************************/
package com.sap.cds.reflect.impl;

import java.util.List;
import java.util.function.Predicate;

import com.sap.cds.reflect.CdsAnnotation;
import com.sap.cds.reflect.CdsDefinition;
import com.sap.cds.reflect.CdsModel;

public abstract class CdsDefinitionBuilder extends CdsAnnotableBuilder {

	protected final String qualifiedName;
	protected final String name;

	public CdsDefinitionBuilder(List> annotations, String qualifiedName, String name) {
		super(annotations);
		this.qualifiedName = qualifiedName;
		this.name = name;
	}

	public String getQualifiedName() {
		return qualifiedName;
	}

	public String getName() {
		if (name == null || name.isEmpty()) {
			String qualifiedName = getQualifiedName();
			int lastDotPos = qualifiedName.lastIndexOf('.');
			if (lastDotPos >= 0 && lastDotPos + 1 < qualifiedName.length()) {
				return qualifiedName.substring(lastDotPos + 1);
			}
			return qualifiedName;
		}
		return name;
	}

	static Predicate> byNamespace(String namespace) {
		if (namespace == null || namespace.isEmpty()) {
			return d -> true;
		}
		return d -> d.getQualifiedName().startsWith(namespace + ".");
	}

	public abstract T build();

	public T build(CdsModel model) {
		throw new UnsupportedOperationException();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy