protected void copyValues(OJOperation result){ result.setComment(getComment()); result.setBody(this.getBody().getCopy()); result.setReturnType(this.getReturnType()); result.setFinal(this.isFinal()); result.setStatic(this.isStatic()); result.setVolatile(this.isVolatile()); result.setName(this.getName()); List<OJParameter> params = new ArrayList<OJParameter>(this.getParameters()); result.setParameters(params); result.setVisibility(this.getVisibility()); } public boolean isEqual(String name,List /* (OJPathName) */types){
public OJOperation getCopy(){ OJOperation result = new OJOperation(); copyValues(result); return result; } public OJOperation getDeepCopy(){
public OJOperation getDeepCopy(){ OJOperation result = new OJOperation(); copyValuesDeep(result); return result; } protected void copyValuesDeep(OJOperation result){
if(!getComment().equals("")){ addJavaDocComment(result); if(this.getNeedsSuppress()){ result.append("@SuppressWarnings(\"unchecked\")\n"); if(this.isAbstract()){ result.append("abstract "); result.append(visToJava(this) + " "); if(this.getGenericTypeParam() != null){ result.append("<" + this.getGenericTypeParam().getLast() + "> "); result.append(getReturnType().getCollectionTypeName()); result.append(" " + getName()); result.append("(" + paramsToJava(this) + ")"); if(!getThrows().isEmpty()) result.append(" throws " + exceptionsToJava(this)); if(getOwner() instanceof OJInterface || this.isAbstract()){ result.append(";\n"); }else{ result.append(" {\n"); StringBuilder bodyStr = new StringBuilder(); String actualBody = getBody().toJavaString();
public void renameAll(Set<OJPathName> renamePathNames,String newName){ getReturnType().renameAll(renamePathNames, newName); for(OJParameter parameter:getParameters()){ parameter.renameAll(renamePathNames, newName); } getBody().renameAll(renamePathNames, newName); } @Override
public void calcImports() { // operations for (OJOperation oper : getOperations()) { addAll(oper.getParamTypes()); this.addToImports(oper.getReturnType()); addImportsRecursively(oper.getBody()); } }
private void addPrimitiveInitVariables(OJAnnotatedClass annotatedClass, Class clazz) { OJOperation initVariables = new OJAnnotatedOperation(INIT_DATE_TYPE_VARIABLES_WITH_DEFAULT_VALUES); if (UmlgClassOperations.hasSupertype(clazz)) { OJSimpleStatement simpleStatement = new OJSimpleStatement("super." + INIT_DATE_TYPE_VARIABLES_WITH_DEFAULT_VALUES + "()"); if (initVariables.getBody().getStatements().isEmpty()) { initVariables.getBody().addToStatements(simpleStatement); } else { initVariables.getBody().getStatements().set(0, simpleStatement); } } annotatedClass.addToOperations(initVariables); }
/** * @param result */ protected void addJavaDocComment(StringBuilder result){ String comment = getComment(); comment = JavaStringHelpers.replaceAllSubstrings(comment, "\n", "\n * "); result.append("/**\n * " + comment); boolean first = true; Iterator it = getParameters().iterator(); while(it.hasNext()){ OJParameter par = (OJParameter) it.next(); String paramStr = "@param " + par.getName() + " " + par.getComment(); if(first){ result.append("\n * "); first = false; } result.append("\n * " + paramStr); } result.append("\n */\n"); } protected StringBuilder paramsToJava(OJOperation op){
public void addParam(String name,String type){ OJPathName path = new OJPathName(type); this.addParam(name, path); } public void addToThrows(String type){
public void addToThrows(String type){ OJPathName path = new OJPathName(type); this.addToThrows(path); } /******************************************************
/****************************************************** * The following operations are the implementations of the operations defined for this classifier. *******************************************************/ public void addParam(String name,OJPathName type){ OJParameter param = new OJParameter(); param.setName(name); param.setType(type); this.addToParameters(param); } public void addParam(String name,String type){
@Override public OJAnnotatedOperation getCopy() { OJAnnotatedOperation oper = new OJAnnotatedOperation(getName()); super.copyValues(oper); oper.removeAllFromParameters(); for (OJParameter f : getParameters()) { oper.addToParameters((OJParameter) f.getCopy()); } for (OJAnnotationValue v : getAnnotations()) { oper.addAnnotationIfNew(v.getCopy()); } // TODO copy exception return oper; }
private void addInitVariables(OJAnnotatedClass annotatedClass, Class clazz) { OJOperation initVariables = new OJAnnotatedOperation(INIT_VARIABLES); if (UmlgClassOperations.hasSupertype(clazz)) { OJSimpleStatement simpleStatement = new OJSimpleStatement("super.initVariables()"); if (initVariables.getBody().getStatements().isEmpty()) { initVariables.getBody().addToStatements(simpleStatement); } else { initVariables.getBody().getStatements().set(0, simpleStatement); } } annotatedClass.addToOperations(initVariables); }
protected void copyValuesDeep(OJOperation result){ result.setComment(getComment()); result.setBody(this.getBody().getDeepCopy()); result.setReturnType(this.getReturnType().getDeepCopy()); result.setFinal(this.isFinal()); result.setStatic(this.isStatic()); result.setVolatile(this.isVolatile()); result.setName(this.getName()); result.setAbstract(isAbstract()); for(OJParameter ojParameter:this.getParameters()){ result.addToParameters(ojParameter.getDeepCopy()); } result.setVisibility(this.getVisibility()); } protected void copyValues(OJOperation result){