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

org.umlg.java.metamodel.annotation.OJAnnotatedInterface Maven / Gradle / Ivy

There is a newer version: 2.0.15
Show newest version
package org.umlg.java.metamodel.annotation;

import java.util.*;

import org.umlg.java.metamodel.OJOperation;
import org.umlg.java.metamodel.OJPackage;
import org.umlg.java.metamodel.OJPathName;
import org.umlg.java.metamodel.utilities.JavaStringHelpers;
import org.umlg.java.metamodel.utilities.JavaUtil;
import org.umlg.java.metamodel.utilities.OJOperationComparator;


public class OJAnnotatedInterface extends OJAnnotatedClass {
	private Set superInterfaces = new HashSet();
	public OJAnnotatedInterface(String string) {
		super(string);
	}


	@Override
	public String toJavaString() {
		this.calcImports();
		StringBuilder classInfo = new StringBuilder();
		classInfo.append(getMyPackage().toJavaString());
		classInfo.append("\n");
		classInfo.append(imports());
		classInfo.append("\n");
		addJavaDocComment(classInfo);
		if (getAnnotations().size() > 0) {
			classInfo.append(JavaStringHelpers.indent(JavaUtil.collectionToJavaString(getAnnotations(), "\n"), 0));
			classInfo.append("\n");
		}
		classInfo.append(visToJava(this) + " ");
		classInfo.append("interface " + getName());
		classInfo.append(superInterfaces());
		classInfo.append(" {\n");
		classInfo.append(JavaStringHelpers.indent(operations(), 1));
		classInfo.append("\n");
		classInfo.append(JavaStringHelpers.indent(innerEnums(), 1));
		classInfo.append("\n");
		classInfo.append("}");
		return classInfo.toString();
	}

	private StringBuilder superInterfaces() {
		StringBuilder result = new StringBuilder();
		if (this.getSuperInterfaces().size() > 0) {
			Iterator it = this.getSuperInterfaces().iterator();
			boolean first = true;
			while (it.hasNext()) {
				OJPathName elem = it.next();
				if (first) {
					result.append(" extends ");
					first = false;
				} else {
					result.append(", ");
				}
				result.append(elem.getLast());
			}
		}
		return result;
	}

	@Override
    public StringBuilder operations() {
        List temp = new ArrayList(this.getOperations());
        Collections.sort(temp, new OJOperationComparator());
        StringBuilder result = new StringBuilder();
        result.append(JavaUtil.collectionToJavaString(temp, "\n"));
        return result;
    }

	public Set getSuperInterfaces() {
		return superInterfaces;
	}

	public void addToSuperInterfaces(OJPathName i) {
		superInterfaces.add(i);
	}

	@Override
	public void calcImports() {
		super.calcImports();
		addToImports(getSuperInterfaces());
	}
	public OJAnnotatedInterface getDeepCopy(OJPackage owner) {
		OJAnnotatedInterface copy = new OJAnnotatedInterface(getName());
		copy.setMyPackage(owner);
		copyDeepInfoInto(copy);
		return copy;
	}

	protected void copyDeepInfoInto(OJAnnotatedInterface copy) {
		super.copyDeepInfoInto(copy);
		for (OJPathName superInterfaze : superInterfaces) {
			copy.addToSuperInterfaces(superInterfaze.getDeepCopy());
		}
	}

	public void renameAll(Set renamePathNames, String newName) {
		super.renameAll(renamePathNames, newName);
		Set superInterfaces = getSuperInterfaces();
		for (OJPathName ojPathName : superInterfaces) {
			ojPathName.renameAll(renamePathNames, newName);
		}
	}

	public void removeFromSuperInterfaces(OJPathName toRemove) {
		this.superInterfaces.remove(toRemove);

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy