Exemplo n.º 1
0
 /**
  * Creates and returns the detailed error message when a local variable is used as a Squawk
  * primitive as well as some value not of exactly the same type. The message includes information
  * derived from the LocalVariableTable attribute so that the source code can be easily changed.
  *
  * @param index the local variable index that is (mis)used
  * @return the detailed error message
  */
 private String getBadAddressLocalVariableMessage(int index, Klass type1, Klass type2) {
   Assert.that(type1.isSquawkPrimitive() || type2.isSquawkPrimitive());
   if (type2.isSquawkPrimitive()) {
     Klass otherType = type1;
     type1 = type2;
     type2 = otherType;
   }
   StringBuffer buf =
       new StringBuffer(
           "Stack location "
               + index
               + " cannot be used for both a local variable of type "
               + type1.getName()
               + " and of type "
               + type2.getName()
               + ". Try moving the variable of type "
               + type1.getName()
               + " to the top-most scope of the method.");
   Enumeration e = codeParser.getLocalVariableTableEntries();
   if (e != null) {
     buf.append(" (source code usage: ");
     while (e.hasMoreElements()) {
       LocalVariableTableEntry entry = (LocalVariableTableEntry) e.nextElement();
       if (entry.getIndex() == index) {
         int start = codeParser.getSourceLineNumber(entry.getStart().getBytecodeOffset());
         int end = codeParser.getSourceLineNumber(entry.getEnd().getBytecodeOffset());
         buf.append(entry.getType().getName())
             .append(' ')
             .append(entry.getName())
             .append(" from line ")
             .append(start)
             .append(" to line ")
             .append(end)
             .append(';');
       }
     }
   }
   return buf.toString();
 }