You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2002/03/05 22:03:32 UTC

cvs commit: jakarta-ant/proposal/sandbox/embed ProjectHelperImpl.java

costin      02/03/05 13:03:32

  Modified:    proposal/sandbox/embed ProjectHelperImpl.java
  Log:
  Jikes ( and gcj ) have some problems dealing with internal non-static classes.
  
  The compiler is required to 'rewrite' the code, removing 'private' and
  adding an extra parameter ( try to decompile ProjectHelper and look
  at method signatures ). While standard javac seem to work fine, I had
  problems with many other compilers ( usually gcj, but now jikes is
  complaining as well ).
  
  I manually did what the compiler would do - now it should work
  with any compiler.
  
  ( the runtime exception was a "Verifier error, expecting object/array on stack" )
  
  I'll do the same thing for the SAX2 helper.
  
  Revision  Changes    Path
  1.3       +107 -88   jakarta-ant/proposal/sandbox/embed/ProjectHelperImpl.java
  
  Index: ProjectHelperImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/embed/ProjectHelperImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProjectHelperImpl.java	5 Mar 2002 05:50:09 -0000	1.2
  +++ ProjectHelperImpl.java	5 Mar 2002 21:03:31 -0000	1.3
  @@ -94,22 +94,22 @@
        * SAX 1 style parser used to parse the given file. This may 
        * in fact be a SAX 2 XMLReader wrapped in an XMLReaderAdapter.
        */
  -    private org.xml.sax.Parser parser;
  +    org.xml.sax.Parser parser;
       
       /** The project to configure. */
  -    private Project project;
  +    Project project;
       /** The configuration file to parse. */
  -    private File buildFile;
  +    File buildFile;
       /** 
        * Parent directory of the build file. Used for resolving entities
        * and setting the project's base directory.
        */
  -    private File buildFileParent;
  +    File buildFileParent;
       /** 
        * Locator for the configuration file parser. 
        * Used for giving locations of errors etc.
        */
  -    private Locator locator;
  +    Locator locator;
   
       /**
        * Parses the project file, configuring the project as it goes.
  @@ -145,7 +145,7 @@
               inputSource = new InputSource(inputStream);
               inputSource.setSystemId(uri);
               project.log("parsing buildfile " + buildFile + " with URI = " + uri, Project.MSG_VERBOSE);
  -            HandlerBase hb = new RootHandler();
  +            HandlerBase hb = new RootHandler(this);
               parser.setDocumentHandler(hb);
               parser.setEntityResolver(hb);
               parser.setErrorHandler(hb);
  @@ -207,7 +207,7 @@
        * events from the parent handler and returns
        * control back to the parent in the endElement method.
        */
  -    private class AbstractHandler extends HandlerBase {
  +    static class AbstractHandler extends HandlerBase {
           
           /** 
            * Previous handler for the document. 
  @@ -215,6 +215,13 @@
            * to this handler.
            */
           protected DocumentHandler parentHandler;
  +
  +        /** Helper impl. With non-static internal classes, the compiler will generate
  +            this automatically - but this will fail with some compilers ( reporting
  +            "Expecting to find object/array on stack" ). If we pass it
  +            explicitely it'll work with more compilers.
  +        */
  +        ProjectHelperImpl helperImpl;
           
           /**
            * Creates a handler and sets the parser to use it
  @@ -224,11 +231,12 @@
            *                      parser at the end of the element. 
            *                      Must not be <code>null</code>.
            */
  -        public AbstractHandler(DocumentHandler parentHandler) {
  +        public AbstractHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) {
               this.parentHandler = parentHandler;
  +            this.helperImpl=helperImpl;
   
               // Start handling SAX events
  -            parser.setDocumentHandler(this);
  +            helperImpl.parser.setDocumentHandler(this);
           }
           
           /**
  @@ -244,7 +252,7 @@
            *                              case of error in an overridden version
            */
           public void startElement(String tag, AttributeList attrs) throws SAXParseException {
  -            throw new SAXParseException("Unexpected element \"" + tag + "\"", locator);
  +            throw new SAXParseException("Unexpected element \"" + tag + "\"", helperImpl.locator);
           }
   
           /**
  @@ -263,7 +271,7 @@
               String s = new String(buf, start, count).trim();
   
               if (s.length() > 0) {
  -                throw new SAXParseException("Unexpected text \"" + s + "\"", locator);
  +                throw new SAXParseException("Unexpected text \"" + s + "\"", helperImpl.locator);
               }
           }
   
  @@ -290,15 +298,20 @@
   
               finished();
               // Let parent resume handling SAX events
  -            parser.setDocumentHandler(parentHandler);
  +            helperImpl.parser.setDocumentHandler(parentHandler);
           }
       }
   
       /**
        * Handler for the root element. Its only child must be the "project" element.
        */
  -    private class RootHandler extends HandlerBase {
  -
  +    static class RootHandler extends HandlerBase {
  +        ProjectHelperImpl helperImpl;
  +        
  +        public RootHandler( ProjectHelperImpl helperImpl ) {
  +            this.helperImpl=helperImpl;
  +        }
  +        
           /**
            * Resolves file: URIs relative to the build file.
            * 
  @@ -311,7 +324,7 @@
           public InputSource resolveEntity(String publicId,
                                            String systemId) {
           
  -            project.log("resolving systemId: " + systemId, Project.MSG_VERBOSE);
  +            helperImpl.project.log("resolving systemId: " + systemId, Project.MSG_VERBOSE);
           
               if (systemId.startsWith("file:")) {
                   String path = systemId.substring(5);
  @@ -334,7 +347,7 @@
   
                   File file = new File(path);
                   if (!file.isAbsolute()) {
  -                    file = new File(buildFileParent, path);
  +                    file = new File(helperImpl.buildFileParent, path);
                   }
                   
                   try {
  @@ -342,7 +355,7 @@
                       inputSource.setSystemId("file:" + entitySystemId);
                       return inputSource;
                   } catch (FileNotFoundException fne) {
  -                    project.log(file.getAbsolutePath()+" could not be found", 
  +                    helperImpl.project.log(file.getAbsolutePath()+" could not be found", 
                                   Project.MSG_WARN);
                   }
               }
  @@ -364,9 +377,9 @@
            */
           public void startElement(String tag, AttributeList attrs) throws SAXParseException {
               if (tag.equals("project")) {
  -                new ProjectHandler(this).init(tag, attrs);
  +                new ProjectHandler(helperImpl, this).init(tag, attrs);
               } else {
  -                throw new SAXParseException("Config file is not of expected XML type", locator);
  +                throw new SAXParseException("Config file is not of expected XML type", helperImpl.locator);
               }
           }
   
  @@ -377,14 +390,14 @@
            *                Will not be <code>null</code>.
            */
           public void setDocumentLocator(Locator locator) {
  -            ProjectHelperImpl.this.locator = locator;
  +            helperImpl.locator = locator;
           }
       }
   
       /**
        * Handler for the top level "project" element.
        */
  -    private class ProjectHandler extends AbstractHandler {
  +    static class ProjectHandler extends AbstractHandler {
           
           /**
            * Constructor which just delegates to the superconstructor.
  @@ -393,8 +406,8 @@
            *                      parser at the end of the element. 
            *                      Must not be <code>null</code>.
            */
  -        public ProjectHandler(DocumentHandler parentHandler) {
  -            super(parentHandler);
  +        public ProjectHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) {
  +            super(helperImpl, parentHandler);
           }
           
           /**
  @@ -432,38 +445,40 @@
                   } else if (key.equals("basedir")) {
                       baseDir = value;
                   } else {
  -                    throw new SAXParseException("Unexpected attribute \"" + attrs.getName(i) + "\"", locator);
  +                    throw new SAXParseException("Unexpected attribute \"" + attrs.getName(i) + "\"",
  +                                                helperImpl.locator);
                   }
               }
   
               if (def == null) {
                   throw new SAXParseException("The default attribute of project is required", 
  -                                            locator);
  +                                            helperImpl.locator);
               }
               
   
  -            project.setDefaultTarget(def);
  +            helperImpl.project.setDefaultTarget(def);
   
               if (name != null) {
  -                project.setName(name);
  -                project.addReference(name, project);
  +                helperImpl.project.setName(name);
  +                helperImpl.project.addReference(name, helperImpl.project);
               }
   
               if (id != null) {
  -              project.addReference(id, project);
  +              helperImpl.project.addReference(id, helperImpl.project);
               }
   
  -            if (project.getProperty("basedir") != null) {
  -                project.setBasedir(project.getProperty("basedir"));
  +            if (helperImpl.project.getProperty("basedir") != null) {
  +                helperImpl.project.setBasedir(helperImpl.project.getProperty("basedir"));
               } else {
                   if (baseDir == null) {
  -                    project.setBasedir(buildFileParent.getAbsolutePath());
  +                    helperImpl.project.setBasedir(helperImpl.buildFileParent.getAbsolutePath());
                   } else {
                       // check whether the user has specified an absolute path
                       if ((new File(baseDir)).isAbsolute()) {
  -                        project.setBasedir(baseDir);
  +                        helperImpl.project.setBasedir(baseDir);
                       } else {
  -                        project.setBaseDir(project.resolveFile(baseDir, buildFileParent));
  +                        helperImpl.project.setBaseDir(helperImpl.project.resolveFile(baseDir,
  +                                                                                     helperImpl.buildFileParent));
                       }
                   }
               }
  @@ -494,10 +509,10 @@
                   handleProperty(name, attrs);
               } else if (name.equals("target")) {
                   handleTarget(name, attrs);
  -            } else if (project.getDataTypeDefinitions().get(name) != null) {
  +            } else if (helperImpl.project.getDataTypeDefinitions().get(name) != null) {
                   handleDataType(name, attrs);
               } else {
  -                throw new SAXParseException("Unexpected element \"" + name + "\"", locator);
  +                throw new SAXParseException("Unexpected element \"" + name + "\"", helperImpl.locator);
               }
           }
           
  @@ -515,7 +530,7 @@
            *                          
            */
           private void handleTaskdef(String name, AttributeList attrs) throws SAXParseException {
  -            (new TaskHandler(this, null, null, null)).init(name, attrs);
  +            (new TaskHandler(helperImpl, this, null, null, null)).init(name, attrs);
           }
   
           /**
  @@ -531,7 +546,7 @@
            *                              handler
            */
           private void handleTypedef(String name, AttributeList attrs) throws SAXParseException {
  -            (new TaskHandler(this, null, null, null)).init(name, attrs);
  +            (new TaskHandler(helperImpl, this, null, null, null)).init(name, attrs);
           }
   
           /**
  @@ -547,7 +562,7 @@
            *                              the handler
            */
           private void handleProperty(String name, AttributeList attrs) throws SAXParseException {
  -            (new TaskHandler(this, null, null, null)).init(name, attrs);
  +            (new TaskHandler(helperImpl, this, null, null, null)).init(name, attrs);
           }
   
           /**
  @@ -563,7 +578,7 @@
            *                              the handler
            */
           private void handleTarget(String tag, AttributeList attrs) throws SAXParseException {
  -            new TargetHandler(this).init(tag, attrs);
  +            new TargetHandler(helperImpl, this).init(tag, attrs);
           }
           /**
            * Handles a data type defintion element by creating a data type 
  @@ -578,7 +593,7 @@
            *                              the handler
            */
           private void handleDataType(String name, AttributeList attrs) throws SAXParseException {
  -            new DataTypeHandler(this).init(name, attrs);
  +            new DataTypeHandler(helperImpl, this).init(name, attrs);
           }
   
       }
  @@ -586,7 +601,7 @@
       /**
        * Handler for "target" elements.
        */
  -    private class TargetHandler extends AbstractHandler {
  +    static class TargetHandler extends AbstractHandler {
           private Target target;
   
           /**
  @@ -596,8 +611,8 @@
            *                      parser at the end of the element. 
            *                      Must not be <code>null</code>.
            */
  -        public TargetHandler(DocumentHandler parentHandler) {
  -            super(parentHandler);
  +        public TargetHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) {
  +            super(helperImpl, parentHandler);
           }
   
           /**
  @@ -642,12 +657,13 @@
                   } else if (key.equals("description")) {
                       description = value;
                   } else {
  -                    throw new SAXParseException("Unexpected attribute \"" + key + "\"", locator);
  +                    throw new SAXParseException("Unexpected attribute \"" + key + "\"", helperImpl.locator);
                   }
               }
   
               if (name == null) {
  -                throw new SAXParseException("target element appears without a name attribute", locator);
  +                throw new SAXParseException("target element appears without a name attribute",
  +                                            helperImpl.locator);
               }
   
               target = new Target();
  @@ -655,10 +671,10 @@
               target.setIf(ifCond);
               target.setUnless(unlessCond);
               target.setDescription(description);
  -            project.addTarget(name, target);
  +            helperImpl.project.addTarget(name, target);
   
               if (id != null && !id.equals("")) {
  -                project.addReference(id, target);
  +                helperImpl.project.addReference(id, target);
               }
   
               // take care of dependencies
  @@ -680,10 +696,10 @@
            *                              the appropriate child handler
            */
           public void startElement(String name, AttributeList attrs) throws SAXParseException {
  -            if (project.getDataTypeDefinitions().get(name) != null) {
  -                new DataTypeHandler(this, target).init(name, attrs);
  +            if (helperImpl.project.getDataTypeDefinitions().get(name) != null) {
  +                new DataTypeHandler(helperImpl, this, target).init(name, attrs);
               } else {
  -                new TaskHandler(this, target, null, target).init(name, attrs);
  +                new TaskHandler(helperImpl, this, target, null, target).init(name, attrs);
               }
           }
       }
  @@ -691,7 +707,7 @@
       /**
        * Handler for all task elements.
        */
  -    private class TaskHandler extends AbstractHandler {
  +    static class TaskHandler extends AbstractHandler {
           /** Containing target, if any. */
           private Target target;
           /** 
  @@ -737,8 +753,9 @@
            * @param target        Target this element is part of.
            *                      May be <code>null</code>.
            */
  -        public TaskHandler(DocumentHandler parentHandler, TaskContainer container, RuntimeConfigurable parentWrapper, Target target) {
  -            super(parentHandler);
  +        public TaskHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler,
  +                           TaskContainer container, RuntimeConfigurable parentWrapper, Target target) {
  +            super(helperImpl, parentHandler);
               this.container = container;
               this.parentWrapper = parentWrapper;
               this.target = target;
  @@ -762,7 +779,7 @@
            */
           public void init(String tag, AttributeList attrs) throws SAXParseException {
               try {
  -                task = project.createTask(tag);
  +                task = helperImpl.project.createTask(tag);
               } catch (BuildException e) {
                   // swallow here, will be thrown again in 
                   // UnknownElement.maybeConfigure if the problem persists.
  @@ -770,13 +787,14 @@
   
               if (task == null) {
                   task = new UnknownElement(tag);
  -                task.setProject(project);
  +                task.setProject(helperImpl.project);
                   //XXX task.setTaskType(tag);
                   task.setTaskName(tag);
               }
   
  -            task.setLocation(new Location(buildFile.toString(), locator.getLineNumber(), locator.getColumnNumber()));
  -            configureId(task, attrs);
  +            task.setLocation(new Location(helperImpl.buildFile.toString(), helperImpl.locator.getLineNumber(),
  +                                          helperImpl.locator.getColumnNumber()));
  +            helperImpl.configureId(task, attrs);
   
               // Top level tasks don't have associated targets
               if (target != null) {
  @@ -790,7 +808,7 @@
                   }
               } else {
                   task.init();
  -                configure(task, attrs, project);
  +                configure(task, attrs, helperImpl.project);
               }
           }
   
  @@ -820,9 +838,9 @@
           public void characters(char[] buf, int start, int count) throws SAXParseException {
               if (wrapper == null) {
                   try {
  -                    addText(project, task, buf, start, count);
  +                    ProjectHelper.addText(helperImpl.project, task, buf, start, count);
                   } catch (BuildException exc) {
  -                    throw new SAXParseException(exc.getMessage(), locator, exc);
  +                    throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
                   }
               } else {
                   wrapper.addText(buf, start, count);
  @@ -845,10 +863,10 @@
           public void startElement(String name, AttributeList attrs) throws SAXParseException {
               if (task instanceof TaskContainer) {
                   // task can contain other tasks - no other nested elements possible
  -                new TaskHandler(this, (TaskContainer)task, wrapper, target).init(name, attrs);
  +                new TaskHandler(helperImpl, this, (TaskContainer)task, wrapper, target).init(name, attrs);
               }
               else {
  -                new NestedElementHandler(this, task, wrapper, target).init(name, attrs);
  +                new NestedElementHandler(helperImpl, this, task, wrapper, target).init(name, attrs);
               }
           }
       }
  @@ -856,7 +874,7 @@
       /**
        * Handler for all nested properties.
        */
  -    private class NestedElementHandler extends AbstractHandler {
  +    static class NestedElementHandler extends AbstractHandler {
           /** Parent object (task/data type/etc). */
           private Object parent;
           /** The nested element itself. */
  @@ -892,11 +910,12 @@
            * @param target        Target this element is part of.
            *                      May be <code>null</code>.
            */
  -        public NestedElementHandler(DocumentHandler parentHandler, 
  +        public NestedElementHandler(ProjectHelperImpl helperImpl,
  +                                    DocumentHandler parentHandler, 
                                       Object parent,
                                       RuntimeConfigurable parentWrapper,
                                       Target target) {
  -            super(parentHandler);
  +            super(helperImpl, parentHandler);
   
               if (parent instanceof TaskAdapter) {
                   this.parent = ((TaskAdapter) parent).getProxy();
  @@ -932,25 +951,25 @@
                   String elementName = propType.toLowerCase(Locale.US);
                   if (parent instanceof UnknownElement) {
                       UnknownElement uc = new UnknownElement(elementName);
  -                    uc.setProject(project);
  +                    uc.setProject(helperImpl.project);
                       ((UnknownElement) parent).addChild(uc);
                       child = uc;
                   } else {
  -                    child = ih.createElement(project, parent, elementName);
  +                    child = ih.createElement(helperImpl.project, parent, elementName);
                   }
   
  -                configureId(child, attrs);
  +                helperImpl.configureId(child, attrs);
   
                   if (parentWrapper != null) {
                       childWrapper = new RuntimeConfigurable(child, propType);
                       childWrapper.setAttributes(attrs);
                       parentWrapper.addChild(childWrapper);
                   } else {
  -                    configure(child, attrs, project);
  -                    ih.storeElement(project, parent, child, elementName);
  +                    configure(child, attrs, helperImpl.project);
  +                    ih.storeElement(helperImpl.project, parent, child, elementName);
                   }
               } catch (BuildException exc) {
  -                throw new SAXParseException(exc.getMessage(), locator, exc);
  +                throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
               }
           }
   
  @@ -970,9 +989,9 @@
           public void characters(char[] buf, int start, int count) throws SAXParseException {
               if (parentWrapper == null) {
                   try {
  -                    addText(project, child, buf, start, count);
  +                    ProjectHelper.addText(helperImpl.project, child, buf, start, count);
                   } catch (BuildException exc) {
  -                    throw new SAXParseException(exc.getMessage(), locator, exc);
  +                    throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
                   }
               } else {
                   childWrapper.addText(buf, start, count);
  @@ -996,10 +1015,10 @@
               if (child instanceof TaskContainer) {
                   // taskcontainer nested element can contain other tasks - no other 
                   // nested elements possible
  -                new TaskHandler(this, (TaskContainer)child, childWrapper, target).init(name, attrs);
  +                new TaskHandler(helperImpl, this, (TaskContainer)child, childWrapper, target).init(name, attrs);
               }
               else {
  -                new NestedElementHandler(this, child, childWrapper, target).init(name, attrs);
  +                new NestedElementHandler(helperImpl, this, child, childWrapper, target).init(name, attrs);
               }
           }
       }
  @@ -1007,7 +1026,7 @@
       /**
        * Handler for all data types directly subordinate to project or target.
        */
  -    private class DataTypeHandler extends AbstractHandler {
  +    static class DataTypeHandler extends AbstractHandler {
           /** Parent target, if any. */
           private Target target;
           /** The element being configured. */
  @@ -1022,8 +1041,8 @@
            *                      parser at the end of the element. 
            *                      Must not be <code>null</code>.
            */
  -        public DataTypeHandler(DocumentHandler parentHandler) {
  -            this(parentHandler, null);
  +        public DataTypeHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) {
  +            this(helperImpl, parentHandler, null);
           }
   
           /**
  @@ -1036,8 +1055,8 @@
            * @param target The parent target of this element.
            *               May be <code>null</code>.
            */
  -        public DataTypeHandler(DocumentHandler parentHandler, Target target) {
  -            super(parentHandler);
  +        public DataTypeHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler, Target target) {
  +            super(helperImpl, parentHandler);
               this.target = target;
           }
   
  @@ -1059,7 +1078,7 @@
            */
           public void init(String propType, AttributeList attrs) throws SAXParseException {
               try {
  -                element = project.createDataType(propType);
  +                element = helperImpl.project.createDataType(propType);
                   if (element == null) {
                       throw new BuildException("Unknown data type "+propType);
                   }
  @@ -1069,11 +1088,11 @@
                       wrapper.setAttributes(attrs);
                       target.addDataType(wrapper);
                   } else {
  -                    configure(element, attrs, project);
  -                    configureId(element, attrs);
  +                    configure(element, attrs, helperImpl.project);
  +                    helperImpl.configureId(element, attrs);
                   }
               } catch (BuildException exc) {
  -                throw new SAXParseException(exc.getMessage(), locator, exc);
  +                throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
               }
           }
   
  @@ -1093,9 +1112,9 @@
            */
           public void characters(char[] buf, int start, int count) throws SAXParseException {
               try {
  -                addText(project, element, buf, start, count);
  +                ProjectHelper.addText(helperImpl.project, element, buf, start, count);
               } catch (BuildException exc) {
  -                throw new SAXParseException(exc.getMessage(), locator, exc);
  +                throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);
               }
           }
   
  @@ -1112,7 +1131,7 @@
            *                              the child handler
            */
           public void startElement(String name, AttributeList attrs) throws SAXParseException {
  -            new NestedElementHandler(this, element, wrapper, target).init(name, attrs);
  +            new NestedElementHandler(helperImpl, this, element, wrapper, target).init(name, attrs);
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [OT] Java vector question

Posted by Derek Slager <de...@activate.net>.
On Tue, Mar 05, 2002 at 05:43:16PM -0800, Diane Holt wrote:
> (Sorry to bug the list, but you're the only Java people I know :)

Please consider asking your question (and other Java questions unrelated to
Ant development) in the JDC forums:

 http://forum.java.sun.com/

You might also benefit from the information here:

 http://developer.java.sun.com/developer/infodocs/

Good luck,

-- 
Derek Slager
Software Engineer
Activate
derek@activate.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [OT] Java vector question

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message ----- 
From: "Diane Holt" <ho...@yahoo.com>
To: "Ant Developers List" <an...@jakarta.apache.org>
Sent: Tuesday, March 05, 2002 17:43
Subject: [OT] Java vector question


> (Sorry to bug the list, but you're the only Java people I know :)
> 
> If I have a Vector v, and I stuff some elements into it (I know they get
> in there, because I can print them out with v.firstElement() and
> v.lastElement()), shouldn't I be able to get the total number of elements
> from v.elementCount?
> 

public int size()
  Returns the number of components in this vector.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [OT] Java vector question

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Diane Holt wrote:

> (Sorry to bug the list, but you're the only Java people I know :)
> 
> If I have a Vector v, and I stuff some elements into it (I know they get
> in there, because I can print them out with v.firstElement() and
> v.lastElement()), shouldn't I be able to get the total number of elements
> from v.elementCount?
> 


Only if you are extending Vector because this field is protected (which is a bad idea anyway).


Use the size() method instead.

Conor


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[OT] Java vector question

Posted by Diane Holt <ho...@yahoo.com>.
(Sorry to bug the list, but you're the only Java people I know :)

If I have a Vector v, and I stuff some elements into it (I know they get
in there, because I can print them out with v.firstElement() and
v.lastElement()), shouldn't I be able to get the total number of elements
from v.elementCount?

Thanks!
Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/proposal/sandbox/embed ProjectHelperImpl.java

Posted by co...@covalent.net.
On Wed, 6 Mar 2002, Peter Donald wrote:

> > What happens at compile time to support inner classes is very tricky and
> > unexpected ( by most people ). The compiler removes 'private' and adds
> > parameters to methods  - the first one does have security implications
> > ( not an issue for ant ). I think it is far better to avoid the magic and
> > pass the parameters explicitely - and as a benefit the code will compile
> > and work with more compilers.
> 
> Yep. I generally have have a no-innerclasses policy unless they are static 
> and don't access any variables from parent class. Too many things that people 
> don't understand - I think your only the 4th person who has ever struck me as 
> knowing how inner classes really behave (and 2 of the others were JVM 
> implementors).

Well, thanks - but I never claimed I _understand_ how inner classes 
work :-) ( or why they were designed this way, or why people are using 
them ).

I assume jikes and gcj developers are in the same situation, not 
understanding very well how this is supposed to work ( since both still 
have problems dealing with them :-). That's why it's better to avoid
non static inner classes.

Costin






--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/proposal/sandbox/embed ProjectHelperImpl.java

Posted by Peter Donald <pe...@apache.org>.
On Wed, 6 Mar 2002 10:11, costinm@covalent.net wrote:
> On Wed, 6 Mar 2002, Peter Donald wrote:
> > >   I manually did what the compiler would do - now it should work
> > >   with any compiler.
> > >
> > >   ( the runtime exception was a "Verifier error, expecting object/array
> > > on stack" )
> >
> > Jikes1.15 is completely and utterly busted. I would highly recomend you
> > don't use it as your "reference" compiler.
>
> I had similar problems with gcj. I know jikes1.15 has problems, and I
> assume other compilers will likely be tricked by inner classes.

Maybe.

> What happens at compile time to support inner classes is very tricky and
> unexpected ( by most people ). The compiler removes 'private' and adds
> parameters to methods  - the first one does have security implications
> ( not an issue for ant ). I think it is far better to avoid the magic and
> pass the parameters explicitely - and as a benefit the code will compile
> and work with more compilers.

Yep. I generally have have a no-innerclasses policy unless they are static 
and don't access any variables from parent class. Too many things that people 
don't understand - I think your only the 4th person who has ever struck me as 
knowing how inner classes really behave (and 2 of the others were JVM 
implementors).

-- 
Cheers,

Pete

----------------------------------------------
Money is how people with no talent keep score.
----------------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/proposal/sandbox/embed ProjectHelperImpl.java

Posted by co...@covalent.net.
On Wed, 6 Mar 2002, Peter Donald wrote:

> >   I manually did what the compiler would do - now it should work
> >   with any compiler.
> >
> >   ( the runtime exception was a "Verifier error, expecting object/array on
> > stack" )
> 
> Jikes1.15 is completely and utterly busted. I would highly recomend you don't 
> use it as your "reference" compiler. 

I had similar problems with gcj. I know jikes1.15 has problems, and I 
assume other compilers will likely be tricked by inner classes.

What happens at compile time to support inner classes is very tricky and
unexpected ( by most people ). The compiler removes 'private' and adds
parameters to methods  - the first one does have security implications 
( not an issue for ant ). I think it is far better to avoid the magic and 
pass the parameters explicitely - and as a benefit the code will compile
and work with more compilers.

Of course, I can revert the change if you think it's a bad idea.

Costin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/proposal/sandbox/embed ProjectHelperImpl.java

Posted by Peter Donald <pe...@apache.org>.
On Wed, 6 Mar 2002 08:03, costin@apache.org wrote:
> costin      02/03/05 13:03:32
>
>   Modified:    proposal/sandbox/embed ProjectHelperImpl.java
>   Log:
>   Jikes ( and gcj ) have some problems dealing with internal non-static
> classes.
>
>   The compiler is required to 'rewrite' the code, removing 'private' and
>   adding an extra parameter ( try to decompile ProjectHelper and look
>   at method signatures ). While standard javac seem to work fine, I had
>   problems with many other compilers ( usually gcj, but now jikes is
>   complaining as well ).
>
>   I manually did what the compiler would do - now it should work
>   with any compiler.
>
>   ( the runtime exception was a "Verifier error, expecting object/array on
> stack" )

Jikes1.15 is completely and utterly busted. I would highly recomend you don't 
use it as your "reference" compiler. 

-- 
Cheers,

Pete

"The fact that a believer is happier than a skeptic is no more to the
 point than the fact that a drunken man is happier than a sober one.
 The happiness of credulity is a cheap and dangerous quality."
        -- George Bernard Shaw

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>