From: <lk...@us...> - 2005-03-27 07:32:46
|
Update of /cvsroot/openorb/OpenORB/src/compiler/org/openorb/compiler/generator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10031 Modified Files: IdlToJava.java Log Message: fixed regression reported by Andrew ``Bass'' Shcheglov, see http://marc.theaimsgroup.com/?l=openorb-devel&m=111073137117247&w=2 minor improvements in coding style along the way Index: IdlToJava.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/compiler/org/openorb/compiler/generator/IdlToJava.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- IdlToJava.java 5 May 2004 07:29:08 -0000 1.22 +++ IdlToJava.java 27 Mar 2005 07:32:35 -0000 1.23 @@ -8,14 +8,46 @@ package org.openorb.compiler.generator; -import java.util.*; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import org.openorb.compiler.CompilerProperties; - -import org.openorb.compiler.object.*; -import org.openorb.compiler.parser.*; - +import org.openorb.compiler.object.IdlArray; +import org.openorb.compiler.object.IdlAttribute; +import org.openorb.compiler.object.IdlComment; +import org.openorb.compiler.object.IdlCommentField; +import org.openorb.compiler.object.IdlCommentSection; +import org.openorb.compiler.object.IdlConst; +import org.openorb.compiler.object.IdlContext; +import org.openorb.compiler.object.IdlEnumMember; +import org.openorb.compiler.object.IdlFactoryMember; +import org.openorb.compiler.object.IdlFixed; +import org.openorb.compiler.object.IdlIdent; +import org.openorb.compiler.object.IdlInclude; +import org.openorb.compiler.object.IdlInterface; +import org.openorb.compiler.object.IdlObject; +import org.openorb.compiler.object.IdlOp; +import org.openorb.compiler.object.IdlParam; +import org.openorb.compiler.object.IdlRaises; +import org.openorb.compiler.object.IdlSequence; +import org.openorb.compiler.object.IdlSimple; +import org.openorb.compiler.object.IdlStateMember; +import org.openorb.compiler.object.IdlString; +import org.openorb.compiler.object.IdlStructMember; +import org.openorb.compiler.object.IdlUnion; +import org.openorb.compiler.object.IdlUnionMember; +import org.openorb.compiler.object.IdlValue; +import org.openorb.compiler.object.IdlValueBox; +import org.openorb.compiler.object.IdlValueInheritance; +import org.openorb.compiler.object.IdlWString; +import org.openorb.compiler.parser.IdlType; +import org.openorb.compiler.parser.Token; import org.openorb.util.CharacterCache; /** @@ -94,7 +126,6 @@ * * @param obj native object * @param output file where definition is added - * @return true if a definition exists */ public void printNativeDefinition(IdlObject obj, java.io.PrintWriter output) { @@ -809,8 +840,7 @@ { List v = new ArrayList(); IdlObject obj2 = obj; - String name = new String(""); - String s; + String name = ""; boolean first = false; while (obj2 != null) @@ -848,7 +878,14 @@ } } - obj2 = obj2.upper(); + // IdlStructMembers sometimes have a null name. + // In that case we proceed further towards the root of the tree + // to avoid a NPE in the next loop. See also + // http://marc.theaimsgroup.com/?l=openorb-devel&m=111073137117247&w=2 + do + { + obj2 = obj2.upper(); + } while (obj2.name() == null); first = true; } @@ -857,35 +894,46 @@ { if (!obj.included()) { - if (!m_cp.getM_packageName().equals("")) + if (m_cp.getM_packageName().length() > 0) { if (!((m_cp.getM_packageName().equals("generated")) && (m_cp.getM_use_package() == false))) - name = adaptToDot(m_cp.getM_packageName()); + { + name = adaptToDot(m_cp.getM_packageName()); + } } } } if (m_cp.getM_usePrefix()) + { if (obj.getPrefix() != null) { - if (!name.equals("")) - name = name + "."; + if (name.length() > 0) + { + name = name + "."; + } if (m_cp.getM_reversePrefix()) - name = name + inversedPrefix(obj.getPrefix()); + { + name = name + inversedPrefix(obj.getPrefix()); + } else - name = name + obj.getPrefix(); + { + name = name + obj.getPrefix(); + } } + } for (int i = v.size() - 1; i >= 0; i--) { - s = (String) v.get(i); + String s = (String) v.get(i); if (s != null) { - if (!name.equals("")) + if (name.length() > 0) + { name = name + "."; - + } name = name + s; } } @@ -8604,8 +8652,8 @@ * Check if the operation or the attribute is already in the list * * @param opList operations and attributes list - * @param op the operation or attribute - * @return true if the operation or attribute is included in the list + * @param obj the operation or attribute + * @return true if the operation or attribute is included in the list */ public boolean isInto(List opList, IdlObject obj) { @@ -8701,7 +8749,7 @@ * (incl. the inheritance). * * @param obj the interface object - * @param opList already found operations and attributes list + * @param inList already found operations and attributes list * @return operations and attributes list */ protected List getInheritanceList(IdlObject obj, List inList) @@ -8720,7 +8768,7 @@ for (int i = 0; i < inList.size(); i++) { - if (((String) inList.get(i)).equals(obj.getId())) + if ((inList.get(i)).equals(obj.getId())) { found = true; break; @@ -9604,18 +9652,21 @@ */ public void translate_module(IdlObject obj, java.io.File writeInto, int translateType) { - String old_pkg; + final String name = obj.name(); java.io.File intoModule; - if (translateType == 0) - intoModule = createDirectory(obj.name(), writeInto); + { + intoModule = createDirectory(name, writeInto); + } else - intoModule = getDirectory(obj.name(), writeInto); + { + intoModule = getDirectory(name, writeInto); + } - old_pkg = current_pkg; + String old_pkg = current_pkg; - addToPkg(obj, obj.name()); + addToPkg(obj, name); translate_object(obj, intoModule, translateType); @@ -10591,94 +10642,95 @@ */ public void translate_object_content(IdlObject obj, java.io.File writeInto, int translateType) { - switch (obj.current().kind()) + final IdlObject current = obj.current(); + switch (current.kind()) { case IdlType.e_module : - translate_module(obj.current(), writeInto, translateType); + translate_module(current, writeInto, translateType); break; case IdlType.e_const : if (translateType == 0) - translate_constant(obj.current(), writeInto, null); + translate_constant(current, writeInto, null); break; case IdlType.e_enum : if (translateType == 0) - translate_enum(obj.current(), writeInto); + translate_enum(current, writeInto); break; case IdlType.e_struct : if (translateType == 0) - translate_struct(obj.current(), writeInto); + translate_struct(current, writeInto); break; case IdlType.e_union : if (translateType == 0) - translate_union(obj.current(), writeInto); + translate_union(current, writeInto); break; case IdlType.e_typedef : if (translateType == 0) - translate_typedef(obj.current(), writeInto); + translate_typedef(current, writeInto); break; case IdlType.e_exception : if (translateType == 0) - translate_exception(obj.current(), writeInto); + translate_exception(current, writeInto); break; case IdlType.e_native : if (translateType == 0) - translate_native(obj.current(), writeInto); + translate_native(current, writeInto); break; case IdlType.e_value_box : if (translateType == 0) - translate_value_box(obj.current(), writeInto); + translate_value_box(current, writeInto); break; case IdlType.e_value : if (translateType == 0) - translate_value_type(obj.current(), writeInto); + translate_value_type(current, writeInto); break; case IdlType.e_interface : if (translateType == 0) - translate_interface(obj.current(), writeInto); + translate_interface(current, writeInto); else if (translateType == 1) { - if (((IdlInterface) (obj.current())).local_interface() == false) - translate_interface_stub(obj.current(), writeInto); + if (((IdlInterface) current).local_interface() == false) + translate_interface_stub(current, writeInto); } else if (translateType == 2) { - if (((IdlInterface) (obj.current())).abstract_interface() == false) + if (((IdlInterface) current).abstract_interface() == false) { - if (((IdlInterface) (obj.current())).local_interface() == false) - translate_interface_skel(obj.current(), writeInto); + if (((IdlInterface) current).local_interface() == false) + translate_interface_skel(current, writeInto); } } else { if (translateType == 3) { - if (((IdlInterface) (obj.current())).abstract_interface() == false) + if (((IdlInterface) current).abstract_interface() == false) { - if (((IdlInterface) (obj.current())).local_interface() == false) - translate_interface_tie(obj.current(), writeInto); + if (((IdlInterface) current).local_interface() == false) + translate_interface_tie(current, writeInto); } } } @@ -10703,27 +10755,31 @@ { java.io.File tmpInto = writeInto; - if (obj.current().included() == false) + final IdlObject current = obj.current(); + if (current.included() == false) { String old_pkg = current_pkg; if (m_cp.getM_usePrefix()) - if ((obj.current().getPrefix() != null) && (obj.kind() == IdlType.e_root)) + { + final String prefix = current.getPrefix(); + if ((prefix != null) && (obj.kind() == IdlType.e_root)) { if (translateType == 0) { - tmpInto = createPrefixDirectories(obj.current().getPrefix(), writeInto); + tmpInto = createPrefixDirectories(prefix, writeInto); } else { - tmpInto = getPrefixDirectories(obj.current().getPrefix(), writeInto); + tmpInto = getPrefixDirectories(prefix, writeInto); } if (m_cp.getM_reversePrefix()) - addToPkg(obj, inversedPrefix(obj.current().getPrefix())); + addToPkg(obj, inversedPrefix(prefix)); else - addToPkg(obj, obj.current().getPrefix()); + addToPkg(obj, prefix); } + } translate_object_content(obj, tmpInto, translateType); |