bugged
stringlengths
6
599k
fixed
stringlengths
6
40.8M
__index_level_0__
int64
0
3.24M
public ListIterator reverseIterator() { return list == null ? Collections.EMPTY_LIST.listIterator() : list.listIterator(list.size()); }
public ListIterator reverseIterator() { return list == null ? Collections.EMPTY_LIST.listIterator() : list.listIterator(list.size()); }
3,229,877
public String toString() { if (list == null) { return ""; } StringBuffer b = new StringBuffer(); for (int i = 0; i < list.size(); i++) { b.append(list.get(i)); } return b.toString(); }
public String toString() { if (list == null) { return string + ": {}"; } StringBuffer b = new StringBuffer(); for (int i = 0; i < list.size(); i++) { b.append(list.get(i)); } return b.toString(); }
3,229,878
public String toString() { if (list == null) { return ""; } StringBuffer b = new StringBuffer(); for (int i = 0; i < list.size(); i++) { b.append(list.get(i)); } return b.toString(); }
public String toString() { if (list == null) { return ""; } StringBuffer b = new StringBuffer(); for (int i = 0; i < list.size(); i++) { b.append(list.get(i)); } return string + ": {" + b.toString() + "}"; }
3,229,879
public static RubyObject raise(Ruby ruby, RubyObject recv, RubyObject args[]) { switch (args.length) { case 0 : case 1 : throw new RaiseException(RubyException.newInstance(ruby, ruby.getExceptions().getRuntimeError(), args)); case 2 : RubyException excptn = (RubyException) args[0].callMethod("exception", args[1]); throw new RaiseException(excptn); default : throw new ArgumentError(ruby, "wrong # of arguments"); } }
public static RubyObject raise(Ruby ruby, RubyObject recv, RubyObject args[]) { switch (args.length) { case 0 : case 1 : if (args[0] instanceof RubyException) { throw new RaiseException((RubyException) args[0]); } else { throw new RaiseException(RubyException.newInstance(ruby, ruby.getExceptions().getRuntimeError(), args)); } case 2 : RubyException excptn = (RubyException) args[0].callMethod("exception", args[1]); throw new RaiseException(excptn); default : throw new ArgumentError(ruby, "wrong # of arguments"); } }
3,229,880
public void setPlane(byte[] buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getPlaneOffset(z, c, t); Integer size = getPlaneSize(); setRegion(size, offset, buffer); }
public void setPlane(ByteBuffer buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getPlaneOffset(z, c, t); Integer size = getPlaneSize(); setRegion(size, offset, buffer); }
3,229,882
public void setPlane(byte[] buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getPlaneOffset(z, c, t); Integer size = getPlaneSize(); setRegion(size, offset, buffer); }
public void setPlane(byte[] buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getPlaneOffset(z, c, t); Integer size = getPlaneSize(); setRegion(size, offset, buffer); }
3,229,883
public void setStack(byte[] buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getStackOffset(c, t); Integer size = getStackSize(); setRegion(size, offset, buffer); }
public void setStack(ByteBuffer buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getStackOffset(c, t); Integer size = getStackSize(); setRegion(size, offset, buffer); }
3,229,884
public void setStack(byte[] buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getStackOffset(c, t); Integer size = getStackSize(); setRegion(size, offset, buffer); }
public void setStack(byte[] buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getStackOffset(c, t); Integer size = getStackSize(); setRegion(size, offset, buffer); }
3,229,885
public void setTimepoint(byte[] buffer, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getTimepointOffset(t); Integer size = getTimepointSize(); setRegion(size, offset, buffer); }
public void setTimepoint(ByteBuffer buffer, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getTimepointOffset(t); Integer size = getTimepointSize(); setRegion(size, offset, buffer); }
3,229,886
public void setTimepoint(byte[] buffer, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getTimepointOffset(t); Integer size = getTimepointSize(); setRegion(size, offset, buffer); }
public void setTimepoint(byte[] buffer, Integer t) throws IOException, DimensionsOutOfBoundsException, BufferOverflowException { Long offset = getTimepointOffset(t); Integer size = getTimepointSize(); setRegion(size, offset, buffer); }
3,229,887
public DatasetBrowserCanvas(MainWindow mainWindow) { super(); this.mainWindow = mainWindow; layer = getLayer(); setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setBackground(PConstants.CANVAS_BACKGROUND_COLOR); setPreferredSize(new Dimension(PConstants.BROWSER_SIDE, PConstants.BROWSER_SIDE)); // remove handlers removeInputEventListener(getZoomEventHandler()); removeInputEventListener(getPanEventHandler()); }
public DatasetBrowserCanvas(MainWindow mainWindow) { super(); this.mainWindow = mainWindow; layer = getLayer(); setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setBackground(PConstants.CANVAS_BACKGROUND_COLOR); setPreferredSize(new Dimension(PConstants.BROWSER_SIDE, PConstants.BROWSER_SIDE)); // remove handlers removeInputEventListener(getZoomEventHandler()); removeInputEventListener(getPanEventHandler()); }
3,229,889
private void arrangeDisplay(Collection datasets) { // initialize and find clear out the layer layer.removeAllChildren(); if (datasets == null) { return; } // calculate the total area, adding nodes to the layer // as we go. totalArea = 0; Iterator iter = datasets.iterator(); while (iter.hasNext()) { BrowserDatasetSummary d = (BrowserDatasetSummary) iter.next(); double area = getArea(d); totalArea += area; } screenHeight = getHeight(); screenWidth = getWidth(); screenArea = screenHeight*screenWidth; // scale the width and height by the total area scaleFactor = Math.sqrt(screenArea/totalArea); screenHeight /= scaleFactor; screenWidth /= scaleFactor; // build the treemap. strips = doTreeMap(datasets); }
private void arrangeDisplay(Collection datasets) { // initialize and find clear out the layer layer.removeAllChildren(); if (datasets == null) { return; } // calculate the total area, adding nodes to the layer // as we go. totalArea = 0; Iterator iter = datasets.iterator(); while (iter.hasNext()) { BrowserDatasetSummary d = (BrowserDatasetSummary) iter.next(); double area = getArea(d); totalArea += area; } screenHeight = getHeight(); screenWidth = getWidth(); screenArea = screenHeight*screenWidth; // scale the width and height by the total area scaleFactor = Math.sqrt(screenArea/totalArea); screenHeight /= scaleFactor; screenWidth /= scaleFactor; // build the treemap. strips = doTreeMap(datasets); }
3,229,890
public void completeInitialization() { // set up listeners addInputEventListener(eventHandler); final PCamera camera = getCamera(); camera.addInputEventListener(new DatasetBrowserToolTipHandler(camera)); // center view eventHandler.animateToBounds(getBufferedBounds()); }
public void completeInitialization() { // set up listeners addInputEventListener(eventHandler); final PCamera camera = getCamera(); camera.addInputEventListener(new DatasetBrowserToolTipHandler(camera)); // center view eventHandler.animateToBounds(getBufferedBounds()); }
3,229,891
private void displayDatasets(Collection datasets) { doLayout(datasets); System.err.println("displaying datasets. animating to "+getBufferedBounds()); eventHandler.animateToBounds(getBufferedBounds()); }
private void displayDatasets(Collection datasets) { doLayout(datasets); System.err.println("displaying datasets. animating to "+getBufferedBounds()); eventHandler.animateToBounds(getBufferedBounds()); }
3,229,892
private void doLayout(Collection datasets) { if (datasets == null) return; layer.setScale(1.0); x = HGAP; y = 0; // strips is a vector of vectors. Each element in strips is a vector // that contains items from a given strip, as calculated by //arrangeDisplay() Iterator iter = strips.iterator(); double maxHeight = 0; while (iter.hasNext()) { // For each strip... Vector strip = (Vector)iter.next(); Iterator iter2 = strip.iterator(); maxHeight = 0; // iterate over items in the strip while (iter2.hasNext()) { // for each dataset DatasetNode node = (DatasetNode) iter2.next(); if (containsDataset(datasets,node.getDataset())) { // position it if it's being displayed if (node.getParent() != layer) layer.addChild(node); node.setOffset(x,y); //move to next horizontal position. Adjust height of row. x+= node.getGlobalFullBounds().getWidth(); double height = node.getGlobalFullBounds().getHeight(); if (height > maxHeight) maxHeight = height; } else { // not showing this node. remove it. // this way, it's not included in bounds. if (node.getParent() == layer) layer.removeChild(node); } } x =HGAP; y +=maxHeight; } }
private void doLayout(Collection datasets) { if (datasets == null) return; layer.setScale(1.0); x = HGAP; y = 0; // strips is a vector of vectors. Each element in strips is a vector // that contains items from a given strip, as calculated by //arrangeDisplay() Iterator iter = strips.iterator(); double maxHeight = 0; while (iter.hasNext()) { // For each strip... Vector strip = (Vector)iter.next(); Iterator iter2 = strip.iterator(); maxHeight = 0; // iterate over items in the strip while (iter2.hasNext()) { // for each dataset DatasetNode node = (DatasetNode) iter2.next(); if (containsDataset(datasets,node.getDataset())) { // position it if it's being displayed if (node.getParent() != layer) layer.addChild(node); node.setOffset(x,y); //move to next horizontal position. Adjust height of row. x+= node.getGlobalFullBounds().getWidth(); double height = node.getGlobalFullBounds().getHeight(); if (height > maxHeight) maxHeight = height; } else { // not showing this node. remove it. // this way, it's not included in bounds. if (node.getParent() == layer) layer.removeChild(node); } } x =HGAP; y +=maxHeight; } }
3,229,893
public void setSelectedProject(BrowserProjectSummary proj) { System.err.println("dataset browser ..set selected project to ..."+proj); if (proj == selectedProject) // no change return; selectedProject = proj; Collection datasetsToDisplay; // ok. what to do now? // cases: if (proj == null) { if (selectedDataset == null) //1) project is null and selected dataset is null we display all datasetsToDisplay = allDatasets; else { //2) project is null, selected dataset isn't. display it. datasetsToDisplay = new Vector(); datasetsToDisplay.add(selectedDataset); } } else { if (selectedDataset == null) { // 3)project is not null. and selected is null display //all for project datasetsToDisplay = proj.getDatasets(); } else { // selected is not null if (!proj.hasDataset(selectedDataset)) { // 4) project is not null, selected is not null, and selected // is not in project. display all for project and clear selected datasetsToDisplay = proj.getDatasets(); selectedDataset = null; } else { // 5) project is not null and selected is not null and selected // is in project display selected datasetsToDisplay = new Vector(); datasetsToDisplay.add(selectedDataset); } } } displayDatasets(datasetsToDisplay); }
public void setSelectedProject(BrowserProjectSummary proj) { System.err.println("dataset browser ..set selected project to ..."+proj); if (proj == selectedProject) // no change return; selectedProject = proj; Collection datasetsToDisplay; // ok. what to do now? // cases: if (proj == null) { if (selectedDataset == null) //1) project is null and selected dataset is null we display all datasetsToDisplay = allDatasets; else { //2) project is null, selected dataset isn't. display it. datasetsToDisplay = new Vector(); datasetsToDisplay.add(selectedDataset); } } else { if (selectedDataset == null) { // 3)project is not null. and selected is null display //all for project datasetsToDisplay = proj.getDatasets(); } else { // selected is not null if (!proj.hasDataset(selectedDataset)) { // 4) project is not null, selected is not null, and selected // is not in project. display all for project and clear selected datasetsToDisplay = proj.getDatasets(); selectedDataset = null; } else { // 5) project is not null and selected is not null and selected // is in project display selected datasetsToDisplay = new Vector(); datasetsToDisplay.add(selectedDataset); } } } displayDatasets(datasetsToDisplay); }
3,229,896
public void showService(String service) { if (serviceMap.containsKey(service)) { cardLayout.show(cardPanel, service); } else { // Create new Form SearchForm searchForm = new SearchForm(service); cardPanel.add(searchForm, service); serviceMap.put(service, searchForm); cardLayout.show(cardPanel, service); } SearchForm searchForm = (SearchForm)serviceMap.get(service); Form form = searchForm.getSearchForm(); String title = form.getTitle(); String description = form.getInstructions(); titlePanel.setTitle(title); titlePanel.setDescription(description); }
public void showService(String service) { if (serviceMap.containsKey(service)) { cardLayout.show(cardPanel, service); } else { // Create new Form SearchForm searchForm = new SearchForm(service); cardPanel.add(searchForm, service); serviceMap.put(service, searchForm); cardLayout.show(cardPanel, service); } SearchForm searchForm = (SearchForm)serviceMap.get(service); Form form = searchForm.getSearchForm(); String title = form.getTitle(); String description = form.getInstructions(); titlePanel.setTitle(Res.getString("title.person.search")); titlePanel.setDescription(description); }
3,229,897
public void performSearch() { searchResults.clearTable(); SwingWorker worker = new SwingWorker() { ReportedData data; public Object construct() { try { Form answerForm = questionForm.getFilledForm(); data = searchManager.getSearchResults(answerForm, serviceName); } catch (XMPPException e) { Log.error("Unable to load search service.", e); } return data; } public void finished() { if (data != null) { searchResults.showUsersFound(data); } else { JOptionPane.showMessageDialog(searchResults, Res.getString("message.no.results.found"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE); } } }; worker.start(); searchResults.invalidate(); searchResults.validate(); searchResults.repaint(); }
publicvoidperformSearch(){searchResults.clearTable();SwingWorkerworker=newSwingWorker(){ReportedDatadata;publicObjectconstruct(){try{FormanswerForm=questionForm.getFilledForm();data=searchManager.getSearchResults(answerForm,serviceName);}catch(XMPPExceptione){Log.error("Unabletoloadsearchservice.",e);}returndata;}publicvoidfinished(){if(data!=null){searchResults.showUsersFound(data);}else{JOptionPane.showMessageDialog(searchResults,Res.getString("message.no.results.found"),Res.getString("title.notification"),JOptionPane.ERROR_MESSAGE);}}};worker.start();searchResults.invalidate();searchResults.validate();searchResults.repaint();}
3,229,898
public void performSearch() { searchResults.clearTable(); SwingWorker worker = new SwingWorker() { ReportedData data; public Object construct() { try { Form answerForm = questionForm.getFilledForm(); data = searchManager.getSearchResults(answerForm, serviceName); } catch (XMPPException e) { Log.error("Unable to load search service.", e); } return data; } public void finished() { if (data != null) { searchResults.showUsersFound(data); } else { JOptionPane.showMessageDialog(searchResults, Res.getString("message.no.results.found"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE); } } }; worker.start(); searchResults.invalidate(); searchResults.validate(); searchResults.repaint(); }
public void performSearch() { searchResults.clearTable(); SwingWorker worker = new SwingWorker() { ReportedData data; public Object construct() { try { Form answerForm = questionForm.getFilledForm(); data = searchManager.getSearchResults(answerForm, serviceName); } catch (XMPPException e) { Log.error("Unable to load search service.", e); } return data; } public void finished() { if (data != null) { searchResults.showUsersFound(data); } else { JOptionPane.showMessageDialog(searchResults, Res.getString("message.no.results.found"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE); } } }; worker.start(); searchResults.invalidate(); searchResults.validate(); searchResults.repaint(); }
3,229,899
public Object doInHibernate(Session session) throws HibernateException { OMEModel o = (OMEModel) session.load(klazz,id); BaseModelUtils u = o.getUtils(); return o; }
public Object doInHibernate(Session session) throws HibernateException { OMEModel o = (OMEModel) session.load(klazz,id); BaseModelUtils u = o.getUtils(); return o; }
3,229,900
public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klazz); c.add(Expression.ilike("name",name,MatchMode.ANYWHERE)); return c.uniqueResult(); }
public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klazz); c.add(Expression.ilike("name",name,MatchMode.ANYWHERE)); return c.uniqueResult(); }
3,229,901
public Object doInHibernate(Session session) throws HibernateException { for (Object o : objects){ session.saveOrUpdate(o); } return null; }
public Object doInHibernate(Session session) throws HibernateException { for (Object o : objects){ session.saveOrUpdate(o); } return null; }
3,229,902
public static RubyBignum unmarshalFrom(UnmarshalStream input) throws IOException { int signum = (input.readUnsignedByte() == '+' ? 1 : -1); int shortLength = input.unmarshalInt(); byte[] digits = new byte[shortLength * 2]; for (int i = digits.length - 1; i >= 0; i--) { digits[i] = input.readSignedByte(); } BigInteger value = new BigInteger(digits); if (signum == -1) { value = value.negate(); } return newBignum(input.getRuby(), value); }
public static RubyBignum unmarshalFrom(UnmarshalStream input) throws IOException { int signum = (input.readUnsignedByte() == '+' ? 1 : -1); int shortLength = input.unmarshalInt(); byte[] digits = new byte[shortLength * 2]; for (int i = digits.length - 1; i >= 0; i--) { digits[i] = input.readSignedByte(); } BigInteger value = new BigInteger(digits); if (signum == -1) { value = value.negate(); } return newBignum(input.getRuntime(), value); }
3,229,903
public List childNodes() { return Collections.EMPTY_LIST; }
public List childNodes() { return EMPTY_LIST; }
3,229,904
final public Object evaluate(Context context) throws ContextException { try { ByteArrayOutputStream os = new ByteArrayOutputStream(256); FastWriter fw = new FastWriter(os, "UTF8"); write(fw,context); fw.flush(); return os.toString("UTF8"); } catch(IOException e) { Engine.log.exception(e); Engine.log.warning( "Include: evaluate got IO exception on write to StringWriter"); return ""; } }
final public Object evaluate(Context context) throws ContextException { try { ByteArrayOutputStream os = new ByteArrayOutputStream(256); FastWriter fw = new FastWriter(os, context.getEncoding()); write(fw,context); fw.flush(); return os.toString("UTF8"); } catch(IOException e) { Engine.log.exception(e); Engine.log.warning( "Include: evaluate got IO exception on write to StringWriter"); return ""; } }
3,229,905
final public Object evaluate(Context context) throws ContextException { try { ByteArrayOutputStream os = new ByteArrayOutputStream(256); FastWriter fw = new FastWriter(os, "UTF8"); write(fw,context); fw.flush(); return os.toString("UTF8"); } catch(IOException e) { Engine.log.exception(e); Engine.log.warning( "Include: evaluate got IO exception on write to StringWriter"); return ""; } }
final public Object evaluate(Context context) throws ContextException { try { ByteArrayOutputStream os = new ByteArrayOutputStream(256); FastWriter fw = new FastWriter(os, "UTF8"); write(fw,context); fw.flush(); return os.toString(context.getEncoding()); } catch(IOException e) { Engine.log.exception(e); Engine.log.warning( "Include: evaluate got IO exception on write to StringWriter"); return ""; } }
3,229,906
public void setColumnNames(String[] colNames){ _colNames = colNames; }
public void setColumnNames(String[] colNames){ _colNames = colNames; }
3,229,907
public PixelsDimensions(int sizeX, int sizeY, int sizeZ, int sizeW, int sizeT, double pixelSizeX, double pixelSizeY, double pixelSizeZ) { if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) throw new IllegalArgumentException( "Spatial dimensions must be positive."); if (sizeW < 1) throw new IllegalArgumentException( "At least one wavelength is required."); if (sizeT < 1) throw new IllegalArgumentException("Timepoints must be positive."); if (pixelSizeX <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeY <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeZ <= 0) throw new IllegalArgumentException("Pixel size must be positive."); this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; this.sizeW = sizeW; this.sizeT = sizeT; this.pixelSizeX = pixelSizeX; this.pixelSizeY = pixelSizeY; this.pixelSizeZ = pixelSizeZ; }
public PixelsDimensions(int sizeX, int sizeY, int sizeZ, int sizeW, int sizeT, double pixelSizeX, double pixelSizeY, double pixelSizeZ) { if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) throw new IllegalArgumentException( "Spatial dimensions must be positive."); if (sizeW < 1) throw new IllegalArgumentException( "At least one wavelength is required."); if (sizeT < 1) throw new IllegalArgumentException("Timepoints must be positive."); if (pixelSizeX < 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeY <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeZ <= 0) throw new IllegalArgumentException("Pixel size must be positive."); this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; this.sizeW = sizeW; this.sizeT = sizeT; this.pixelSizeX = pixelSizeX; this.pixelSizeY = pixelSizeY; this.pixelSizeZ = pixelSizeZ; }
3,229,910
public PixelsDimensions(int sizeX, int sizeY, int sizeZ, int sizeW, int sizeT, double pixelSizeX, double pixelSizeY, double pixelSizeZ) { if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) throw new IllegalArgumentException( "Spatial dimensions must be positive."); if (sizeW < 1) throw new IllegalArgumentException( "At least one wavelength is required."); if (sizeT < 1) throw new IllegalArgumentException("Timepoints must be positive."); if (pixelSizeX <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeY <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeZ <= 0) throw new IllegalArgumentException("Pixel size must be positive."); this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; this.sizeW = sizeW; this.sizeT = sizeT; this.pixelSizeX = pixelSizeX; this.pixelSizeY = pixelSizeY; this.pixelSizeZ = pixelSizeZ; }
public PixelsDimensions(int sizeX, int sizeY, int sizeZ, int sizeW, int sizeT, double pixelSizeX, double pixelSizeY, double pixelSizeZ) { if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) throw new IllegalArgumentException( "Spatial dimensions must be positive."); if (sizeW < 1) throw new IllegalArgumentException( "At least one wavelength is required."); if (sizeT < 1) throw new IllegalArgumentException("Timepoints must be positive."); if (pixelSizeX <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeY < 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeZ <= 0) throw new IllegalArgumentException("Pixel size must be positive."); this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; this.sizeW = sizeW; this.sizeT = sizeT; this.pixelSizeX = pixelSizeX; this.pixelSizeY = pixelSizeY; this.pixelSizeZ = pixelSizeZ; }
3,229,911
public PixelsDimensions(int sizeX, int sizeY, int sizeZ, int sizeW, int sizeT, double pixelSizeX, double pixelSizeY, double pixelSizeZ) { if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) throw new IllegalArgumentException( "Spatial dimensions must be positive."); if (sizeW < 1) throw new IllegalArgumentException( "At least one wavelength is required."); if (sizeT < 1) throw new IllegalArgumentException("Timepoints must be positive."); if (pixelSizeX <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeY <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeZ <= 0) throw new IllegalArgumentException("Pixel size must be positive."); this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; this.sizeW = sizeW; this.sizeT = sizeT; this.pixelSizeX = pixelSizeX; this.pixelSizeY = pixelSizeY; this.pixelSizeZ = pixelSizeZ; }
public PixelsDimensions(int sizeX, int sizeY, int sizeZ, int sizeW, int sizeT, double pixelSizeX, double pixelSizeY, double pixelSizeZ) { if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) throw new IllegalArgumentException( "Spatial dimensions must be positive."); if (sizeW < 1) throw new IllegalArgumentException( "At least one wavelength is required."); if (sizeT < 1) throw new IllegalArgumentException("Timepoints must be positive."); if (pixelSizeX <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeY <= 0) throw new IllegalArgumentException("Pixel size must be positive."); if (pixelSizeZ < 0) throw new IllegalArgumentException("Pixel size must be positive."); this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; this.sizeW = sizeW; this.sizeT = sizeT; this.pixelSizeX = pixelSizeX; this.pixelSizeY = pixelSizeY; this.pixelSizeZ = pixelSizeZ; }
3,229,912
public GatewayButton(final Transport transport) { setLayout(new GridBagLayout()); setOpaque(false); this.transport = transport; final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); button.setIcon(transport.getInactiveIcon()); button.setToolTipText(transport.getInstructions()); commandPanel.add(button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); button.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { handlePopup(mouseEvent); } }); // Send directed presence if registered with this transport. final boolean isRegistered = TransportUtils.isRegistered(SparkManager.getConnection(), transport); if (isRegistered) { // Check if auto login is set. boolean autoJoin = TransportUtils.autoJoinService(transport.getServiceName()); if (autoJoin) { Presence presence = statusBar.getPresence(); presence.setTo(transport.getServiceName()); SparkManager.getConnection().sendPacket(presence); } } }
public GatewayButton(final Transport transport) { setLayout(new GridBagLayout()); setOpaque(false); this.transport = transport; final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); button.setIcon(transport.getInactiveIcon()); button.setToolTipText(transport.getInstructions()); commandPanel.add(button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); button.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { handlePopup(mouseEvent); } }); // Send directed presence if registered with this transport. final boolean isRegistered = TransportUtils.isRegistered(SparkManager.getConnection(), transport); if (isRegistered) { // Check if auto login is set. boolean autoJoin = TransportUtils.autoJoinService(transport.getServiceName()); if (autoJoin) { Presence oldPresence = statusBar.getPresence(); Presence presence = new Presence(oldPresence.getType(), oldPresence.getStatus(), oldPresence.getPriority(), oldPresence.getMode()); presence.setTo(transport.getServiceName()); SparkManager.getConnection().sendPacket(presence); } } }
3,229,914
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,915
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
try { try { private LoadServiceResource findFile(String name) {try { try { try { try { //try { try { try { try { try {try { try { try { try { try { try { if (name.startsWith("jar:")) {try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(new URL(name), name);try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { //try { try { try { try { try { try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader();try { try { try { try { try { try { JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name);try { try { try { try { try { try { if(file.isFile() && file.isAbsolute()) {try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(file.toURL(),name);try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader();try { try { try { try { try { try { String xname = name.replace('\\', '/');try { try { try { try { try { try { try { try { try { try { try { try { // Look in classpath next (we do not use File as a test since UNC names will match)try { try { try { try { try { try { // Note: Jar resources must always begin with an '/'.try { try { try { try { try { try { if (xname.charAt(0) == '/') {try { try { try { try { try { try { try { try { URL loc = classLoader.getResource(xname);try { try { try { try { try { try { try { try { // Make sure this is not a directory or unavailable in some waytry { try { try { try { try { try { try { try { if (isRequireable(loc)) {try { try { try { try { try { try { try { try { return new LoadServiceResource(loc, loc.getPath());try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { try { try { for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) {try { try { try { try { try { try { try { try { String entry = pathIter.next().toString();try { try { try { try { try { try { try { try { if (entry.startsWith("jar:")) {try { try { try { try { try { try { try { try { try { try { JarFile current = (JarFile)jarFiles.get(entry);try { try { try { try { try { try { try { try { try { try { if(null == current) {try { try { try { try { try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { try { try { try { try { current = new JarFile(entry.substring(4));try { try { try { try { try { try { try { try { try { try { try { try { try { try { jarFiles.put(entry,current);try { try { try { try { try { try { try { try { try { try { try { try { } catch (FileNotFoundException ignored) {try { try { try { try { try { try { try { try { try { try { try { try { } catch (IOException e) {try { try { try { try { try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { if (current.getJarEntry(name) != null) {try { try { try { try { try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(new URL(entry + name), entry + name);try { try { try { try { try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { //try { try { try { try { try { try { try { // Load from local filesystemtry { try { try { try { try { try { try { try { //try { try { try { try { try { try { try { try { NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile();try { try { try { try { try { try { try { try { JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name);try { try { try { try { try { try { try { try { if (current.isFile()) {try { try { try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(current.toURL(), current.getPath());try { try { try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { // otherwise, try to load from classpath (Note: Jar resources always uses '/')try { try { try { try { try { try { try { try { URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname);try { try { try { try { try { try { try { try { // Make sure this is not a directory or unavailable in some waytry { try { try { try { try { try { try { try { if (isRequireable(loc)) {try { try { try { try { try { try { try { try { return new LoadServiceResource(loc, loc.getPath());try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { // Try to load from classpath without prefix. "A/b.rb" will not load astry { try { try { try { try { try { // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/')try { try { try { try { try { try { URL loc = classLoader.getResource(xname);try { try { try { try { try { try { return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null;try { try { try { try { try { try { //try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { //try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { //try { try { try { try { }try { try { }
3,229,916
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,917
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,918
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,919
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,920
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
try { try { private LoadServiceResource findFile(String name) {try { try { try { try { //try { try { try { try { try {try { try { try { try { try { try { if (name.startsWith("jar:")) {try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(new URL(name), name);try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { //try { try { try { try { try { try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader();try { try { try { try { try { try { JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name);try { try { try { try { try { try { if(file.isFile() && file.isAbsolute()) {try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(file.toURL(),name);try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader();try { try { try { try { try { try { String xname = name.replace('\\', '/');try { try { try { try { try { try { try { try { try { try { try { try { // Look in classpath next (we do not use File as a test since UNC names will match)try { try { try { try { try { try { // Note: Jar resources must always begin with an '/'.try { try { try { try { try { try { if (xname.charAt(0) == '/') {try { try { try { try { try { try { try { try { URL loc = classLoader.getResource(xname);try { try { try { try { try { try { try { try { // Make sure this is not a directory or unavailable in some waytry { try { try { try { try { try { try { try { if (isRequireable(loc)) {try { try { try { try { try { try { try { try { return new LoadServiceResource(loc, loc.getPath());try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { try { try { for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) {try { try { try { try { try { try { try { try { String entry = pathIter.next().toString();try { try { try { try { try { try { try { try { if (entry.startsWith("jar:")) {try { try { try { try { try { try { try { try { try { try { JarFile current = (JarFile)jarFiles.get(entry);try { try { try { try { try { try { try { try { try { try { if(null == current) {try { try { try { try { try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { try { try { try { try { current = new JarFile(entry.substring(4));try { try { try { try { try { try { try { try { try { try { try { try { try { try { jarFiles.put(entry,current);try { try { try { try { try { try { try { try { try { try { try { try { } catch (FileNotFoundException ignored) {try { try { try { try { try { try { try { try { try { try { try { try { } catch (IOException e) {try { try { try { try { try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { if (current.getJarEntry(name) != null) {try { try { try { try { try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(new URL(entry + name), entry + name);try { try { try { try { try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { //try { try { try { try { try { try { try { // Load from local filesystemtry { try { try { try { try { try { try { try { //try { try { try { try { try { try { try { try { NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile();try { try { try { try { try { try { try { try { JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name);try { try { try { try { try { try { try { try { if (current.isFile()) {try { try { try { try { try { try { try { try { try { try { try {try { try { try { try { try { try { try { try { try { try { try { try { return new LoadServiceResource(current.toURL(), current.getPath());try { try { try { try { try { try { try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { }try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { try { // otherwise, try to load from classpath (Note: Jar resources always uses '/')try { try { try { try { try { try { try { try { URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname);try { try { try { try { try { try { try { try { // Make sure this is not a directory or unavailable in some waytry { try { try { try { try { try { try { try { if (isRequireable(loc)) {try { try { try { try { try { try { try { try { return new LoadServiceResource(loc, loc.getPath());try { try { try { try { try { try { try { try { }try { try { try { try { try { try { }try { try { try { try { try { try { // Try to load from classpath without prefix. "A/b.rb" will not load astry { try { try { try { try { try { // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/')try { try { try { try { try { try { URL loc = classLoader.getResource(xname);try { try { try { try { try { try { return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null;try { try { try { try { try { try { //try { try { try { try { } catch (MalformedURLException e) {try { try { try { try { try { try { //try { try { try { try { try { try { throw runtime.newIOErrorFromException(e);try { try { try { try { try { try { //try { try { try { try { }try { try { }
3,229,921
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,922
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,923
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
private LoadServiceResource findFile(String name) { // try { if (name.startsWith("jar:")) { try { return new LoadServiceResource(new URL(name), name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(),name); if(file.isFile() && file.isAbsolute()) { try { return new LoadServiceResource(file.toURL(),name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } ClassLoader classLoader = runtime.getJavaSupport().getJavaClassLoader(); String xname = name.replace('\\', '/'); // Look in classpath next (we do not use File as a test since UNC names will match) // Note: Jar resources must always begin with an '/'. if (xname.charAt(0) == '/') { URL loc = classLoader.getResource(xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } for (Iterator pathIter = loadPath.iterator(); pathIter.hasNext();) { String entry = pathIter.next().toString(); if (entry.startsWith("jar:")) { JarFile current = (JarFile)jarFiles.get(entry); if(null == current) { try { current = new JarFile(entry.substring(4)); jarFiles.put(entry,current); } catch (FileNotFoundException ignored) { } catch (IOException e) { throw runtime.newIOErrorFromException(e); } } if (current.getJarEntry(name) != null) { try { return new LoadServiceResource(new URL(entry + name), entry + name); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } } // // Load from local filesystem // NormalizedFile current = (NormalizedFile)new NormalizedFile(entry, name).getAbsoluteFile(); JRubyFile current = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(),entry).getAbsolutePath(), name); if (current.isFile()) { try { return new LoadServiceResource(current.toURL(), current.getPath()); } catch (MalformedURLException e) { throw runtime.newIOErrorFromException(e); } } // otherwise, try to load from classpath (Note: Jar resources always uses '/') URL loc = classLoader.getResource(entry.replace('\\', '/') + "/" + xname); // Make sure this is not a directory or unavailable in some way if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } // Try to load from classpath without prefix. "A/b.rb" will not load as // "./A/b.rb" in a jar file. (Note: Jar resources always uses '/') URL loc = classLoader.getResource(xname); if (isRequireable(loc)) { return new LoadServiceResource(loc, loc.getPath()); } } URL loc = classLoader.getResource(xname); return isRequireable(loc) ? new LoadServiceResource(loc, loc.getPath()) : null; // } catch (MalformedURLException e) { // throw runtime.newIOErrorFromException(e); // } }
3,229,924
public void init(List additionalDirectories) { for (Iterator iter = additionalDirectories.iterator(); iter.hasNext();) { addPath((String) iter.next()); } if (runtime.getSafeLevel() == 0) { String jrubyLib = System.getProperty("jruby.lib"); if (jrubyLib != null) { addPath(jrubyLib); } } String jrubyHome = System.getProperty("jruby.home"); if (jrubyHome != null) { char sep = '/'; String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep; addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION + sep + "java"); addPath(rubyDir + "site_ruby"); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION + sep + "java"); // Added to make sure we find default distribution files within jar file. // TODO: Either make jrubyHome become the jar file or allow "classpath-only" paths addPath("lib" + sep + "ruby" + sep + Constants.RUBY_MAJOR_VERSION); } if (runtime.getSafeLevel() == 0) { addPath("."); } }
public void init(List additionalDirectories) { for (Iterator iter = additionalDirectories.iterator(); iter.hasNext();) { addPath((String) iter.next()); } if (runtime.getSafeLevel() == 0) { String jrubyLib = System.getProperty("jruby.lib"); if (jrubyLib != null) { addPath(jrubyLib); } } String jrubyHome = System.getProperty("jruby.home"); if (jrubyHome != null) { char sep = '/'; String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep; addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION + sep + "java"); addPath(rubyDir + "site_ruby"); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION + sep + "java"); // Added to make sure we find default distribution files within jar file. // TODO: Either make jrubyHome become the jar file or allow "classpath-only" paths addPath("lib" + sep + "ruby" + sep + Constants.RUBY_MAJOR_VERSION); } if (runtime.getSafeLevel() == 0) { addPath("."); } }
3,229,925
public void init(List additionalDirectories) { for (Iterator iter = additionalDirectories.iterator(); iter.hasNext();) { addPath((String) iter.next()); } if (runtime.getSafeLevel() == 0) { String jrubyLib = System.getProperty("jruby.lib"); if (jrubyLib != null) { addPath(jrubyLib); } } String jrubyHome = System.getProperty("jruby.home"); if (jrubyHome != null) { char sep = '/'; String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep; addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION + sep + "java"); addPath(rubyDir + "site_ruby"); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION + sep + "java"); // Added to make sure we find default distribution files within jar file. // TODO: Either make jrubyHome become the jar file or allow "classpath-only" paths addPath("lib" + sep + "ruby" + sep + Constants.RUBY_MAJOR_VERSION); } if (runtime.getSafeLevel() == 0) { addPath("."); } }
public void init(List additionalDirectories) { for (Iterator iter = additionalDirectories.iterator(); iter.hasNext();) { addPath((String) iter.next()); } if (runtime.getSafeLevel() == 0) { String jrubyLib = System.getProperty("jruby.lib"); if (jrubyLib != null) { addPath(jrubyLib); } } String jrubyHome = System.getProperty("jruby.home"); if (jrubyHome != null) { char sep = '/'; String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep; addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION + sep + "java"); addPath(rubyDir + "site_ruby"); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION); addPath(rubyDir + Constants.RUBY_MAJOR_VERSION + sep + "java"); // Added to make sure we find default distribution files within jar file. // TODO: Either make jrubyHome become the jar file or allow "classpath-only" paths addPath("lib" + sep + "ruby" + sep + Constants.RUBY_MAJOR_VERSION); } if (runtime.getSafeLevel() == 0) { addPath("."); } }
3,229,926
private boolean isRequireable(URL loc) { if (loc != null) { if (loc.getProtocol().equals("file") && new java.io.File(loc.getFile()).isDirectory()) { return false; } try { loc.openConnection(); return true; } catch (Exception e) {} } return false; }
private boolean isRequireable(URL loc) { if (loc != null) { if (loc.getProtocol().equals("file") && new java.io.File(loc.getFile()).isDirectory()) { return false; } try { loc.openConnection(); return true; } catch (Exception e) {} } return false; }
3,229,927
private static NormalizedFile newFile(RubyString path) { NormalizedFile file = new NormalizedFile(path.getValue()); if (!file.isAbsolute()) { file = new NormalizedFile(path.getRuntime().getCurrentDirectory(), path.getValue()); } try { file = (NormalizedFile)file.getCanonicalFile(); } catch (IOException e) { file = (NormalizedFile)file.getAbsoluteFile(); } return file; }
private static NormalizedFile newFile(RubyString path) { NormalizedFile file = new NormalizedFile(path.toString()); if (!file.isAbsolute()) { file = new NormalizedFile(path.getRuntime().getCurrentDirectory(), path.getValue()); } try { file = (NormalizedFile)file.getCanonicalFile(); } catch (IOException e) { file = (NormalizedFile)file.getAbsoluteFile(); } return file; }
3,229,928
private static NormalizedFile newFile(RubyString path) { NormalizedFile file = new NormalizedFile(path.getValue()); if (!file.isAbsolute()) { file = new NormalizedFile(path.getRuntime().getCurrentDirectory(), path.getValue()); } try { file = (NormalizedFile)file.getCanonicalFile(); } catch (IOException e) { file = (NormalizedFile)file.getAbsoluteFile(); } return file; }
private static NormalizedFile newFile(RubyString path) { NormalizedFile file = new NormalizedFile(path.getValue()); if (!file.isAbsolute()) { file = new NormalizedFile(path.getRuntime().getCurrentDirectory(), path.toString()); } try { file = (NormalizedFile)file.getCanonicalFile(); } catch (IOException e) { file = (NormalizedFile)file.getAbsoluteFile(); } return file; }
3,229,929
public static IRubyObject size(IRubyObject recv, RubyString filename) { NormalizedFile file = newFile(filename); if (!file.exists()) { throw recv.getRuntime().newErrnoENOENTError("No such file: " + filename.getValue()); } return filename.getRuntime().newFixnum(file.length()); }
public static IRubyObject size(IRubyObject recv, RubyString filename) { NormalizedFile file = newFile(filename); if (!file.exists()) { throw recv.getRuntime().newErrnoENOENTError("No such file: " + filename); } return filename.getRuntime().newFixnum(file.length()); }
3,229,930
public static XmlBeanDefinitionReader createBeanDefinitionReader( SpringApplicationContext applicationContext, BeanDefinitionRegistry registry, List xmlPreprocessors) { String version = SpringVersion.getVersion(); String className = "org.apache.xbean.spring.context.v" + version.charAt(0) + ".XBeanXmlBeanDefinitionReader"; try { Class cl = Class.forName(className); Constructor cstr = cl.getConstructor(new Class[] { SpringApplicationContext.class, BeanDefinitionRegistry.class, List.class }); return (XmlBeanDefinitionReader) cstr.newInstance(new Object[] { applicationContext, registry, xmlPreprocessors }); } catch (Exception e) { throw (IllegalStateException) new IllegalStateException("Could not find valid implementation for: " + version).initCause(e); } }
public static XmlBeanDefinitionReader createBeanDefinitionReader( SpringApplicationContext applicationContext, BeanDefinitionRegistry registry, List xmlPreprocessors) { String version = "2.0"; try { Class spring20Clazz = Class.forName("org.springframework.core.AttributeAccessorSupport"); version = "2.0"; } catch(ClassNotFoundException e) { version = "1.2.8"; } String className = "org.apache.xbean.spring.context.v" + version.charAt(0) + ".XBeanXmlBeanDefinitionReader"; try { Class cl = Class.forName(className); Constructor cstr = cl.getConstructor(new Class[] { SpringApplicationContext.class, BeanDefinitionRegistry.class, List.class }); return (XmlBeanDefinitionReader) cstr.newInstance(new Object[] { applicationContext, registry, xmlPreprocessors }); } catch (Exception e) { throw (IllegalStateException) new IllegalStateException("Could not find valid implementation for: " + version).initCause(e); } }
3,229,931
public static void createGlobals(IRuby runtime) { // Version information: IRubyObject version = runtime.newString(Constants.RUBY_VERSION).freeze(); IRubyObject release = runtime.newString(Constants.COMPILE_DATE).freeze(); IRubyObject platform = runtime.newString(Constants.PLATFORM).freeze(); runtime.defineGlobalConstant("RUBY_VERSION", version); runtime.defineGlobalConstant("RUBY_RELEASE_DATE", release); runtime.defineGlobalConstant("RUBY_PLATFORM", platform); runtime.defineGlobalConstant("VERSION", version); runtime.defineGlobalConstant("RELEASE_DATE", release); runtime.defineGlobalConstant("PLATFORM", platform); // FIXME: ENV Not really a RubyHash (but close) // FIXME: ENV Should not copy system properties, but should reference them instead HashMap envs = new HashMap(); envs.put(runtime.newString("HOME"), runtime.newString(System.getProperty("user.home"))); runtime.defineGlobalConstant("ENV", RubyHash.newHash(runtime, envs, null)); runtime.defineVariable(new StringGlobalVariable(runtime, "$KCODE", runtime.newString("UTF8"))); runtime.defineVariable(new StringGlobalVariable(runtime, "$/", runtime.newString("\n"))); runtime.defineVariable(new StringGlobalVariable(runtime, "$\\", runtime.getNil())); runtime.defineVariable(new StringGlobalVariable(runtime, "$,", runtime.getNil())); runtime.defineVariable(new LineNumberGlobalVariable(runtime, "$.", RubyFixnum.one(runtime))); runtime.defineVariable(new LastlineGlobalVariable(runtime, "$_")); runtime.defineVariable(new ErrorInfoGlobalVariable(runtime, "$!", runtime.getNil())); runtime.defineVariable(new SafeGlobalVariable(runtime, "$SAFE")); runtime.defineVariable(new BacktraceGlobalVariable(runtime, "$@")); IRubyObject stdin = RubyIO.fdOpen(runtime, RubyIO.STDIN); IRubyObject stdout = RubyIO.fdOpen(runtime, RubyIO.STDOUT); IRubyObject stderr = RubyIO.fdOpen(runtime, RubyIO.STDERR); runtime.defineVariable(new InputGlobalVariable(runtime, "$stdin", stdin)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", stdout)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", stderr)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$>", stdout)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$defout", stdout)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$deferr", stderr)); runtime.defineGlobalConstant("STDIN", stdin); runtime.defineGlobalConstant("STDOUT", stdout); runtime.defineGlobalConstant("STDERR", stderr); runtime.defineVariable(new LoadedFeatures(runtime, "$\"")); runtime.defineVariable(new LoadPath(runtime, "$:")); runtime.defineVariable(new LoadPath(runtime, "$-I")); runtime.defineVariable(new LoadPath(runtime, "$LOAD_PATH")); // ARGF, $< object RubyArgsFile argsFile = new RubyArgsFile(runtime); argsFile.initArgsFile(); }
public static void createGlobals(IRuby runtime) { // Version information: IRubyObject version = runtime.newString(Constants.RUBY_VERSION).freeze(); IRubyObject release = runtime.newString(Constants.COMPILE_DATE).freeze(); IRubyObject platform = runtime.newString(Constants.PLATFORM).freeze(); runtime.defineGlobalConstant("RUBY_VERSION", version); runtime.defineGlobalConstant("RUBY_RELEASE_DATE", release); runtime.defineGlobalConstant("RUBY_PLATFORM", platform); runtime.defineGlobalConstant("VERSION", version); runtime.defineGlobalConstant("RELEASE_DATE", release); runtime.defineGlobalConstant("PLATFORM", platform); // FIXME: ENV Not really a RubyHash (but close) // FIXME: ENV Should not copy system properties, but should reference them instead HashMap envs = new HashMap(); envs.put(runtime.newString("HOME"), runtime.newString(System.getProperty("user.home"))); runtime.defineGlobalConstant("ENV", RubyHash.newHash(runtime, envs, runtime.getNil())); runtime.defineVariable(new StringGlobalVariable(runtime, "$KCODE", runtime.newString("UTF8"))); runtime.defineVariable(new StringGlobalVariable(runtime, "$/", runtime.newString("\n"))); runtime.defineVariable(new StringGlobalVariable(runtime, "$\\", runtime.getNil())); runtime.defineVariable(new StringGlobalVariable(runtime, "$,", runtime.getNil())); runtime.defineVariable(new LineNumberGlobalVariable(runtime, "$.", RubyFixnum.one(runtime))); runtime.defineVariable(new LastlineGlobalVariable(runtime, "$_")); runtime.defineVariable(new ErrorInfoGlobalVariable(runtime, "$!", runtime.getNil())); runtime.defineVariable(new SafeGlobalVariable(runtime, "$SAFE")); runtime.defineVariable(new BacktraceGlobalVariable(runtime, "$@")); IRubyObject stdin = RubyIO.fdOpen(runtime, RubyIO.STDIN); IRubyObject stdout = RubyIO.fdOpen(runtime, RubyIO.STDOUT); IRubyObject stderr = RubyIO.fdOpen(runtime, RubyIO.STDERR); runtime.defineVariable(new InputGlobalVariable(runtime, "$stdin", stdin)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", stdout)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", stderr)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$>", stdout)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$defout", stdout)); runtime.defineVariable(new OutputGlobalVariable(runtime, "$deferr", stderr)); runtime.defineGlobalConstant("STDIN", stdin); runtime.defineGlobalConstant("STDOUT", stdout); runtime.defineGlobalConstant("STDERR", stderr); runtime.defineVariable(new LoadedFeatures(runtime, "$\"")); runtime.defineVariable(new LoadPath(runtime, "$:")); runtime.defineVariable(new LoadPath(runtime, "$-I")); runtime.defineVariable(new LoadPath(runtime, "$LOAD_PATH")); // ARGF, $< object RubyArgsFile argsFile = new RubyArgsFile(runtime); argsFile.initArgsFile(); }
3,229,932
private void initComponents() { createMenuBar(); createLeftMenuBar(); caseSensitive = new JCheckBox("Match case"); caseSensitive.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JCheckBox source = (JCheckBox) e.getSource(); model.setCaseSensitive(source.isSelected()); } }); infoComponent = new JPanel(); findArea = new JTextField(); findArea.setBorder(BorderFactory.createBevelBorder( BevelBorder.LOWERED)); findArea.setBackground(Color.WHITE); findArea.setOpaque(true); findArea.setEditable(true); int h = getFontMetrics(getFont()).getHeight()+4; findArea.setPreferredSize(new Dimension(WIDTH, h)); findArea.addKeyListener(new KeyAdapter() { /** Finds the phrase. */ public void keyPressed(KeyEvent e) { if ((e.getKeyCode() == KeyEvent.VK_ENTER)) { Object source = e.getSource(); if (source instanceof JTextField) { JTextField field = (JTextField) source; if (field.getText() != null && field.getText().length() > 0) finder.find(); } } } }); findArea.getDocument().addDocumentListener(new DocumentListener() { /** * Sets the finder's controls enabled if no phrase entered. * @see DocumentListener#removeUpdate(DocumentEvent) */ public void insertUpdate(DocumentEvent de) { Document d = de.getDocument(); try { finder.setTextUpdate(d.getText(0, d.getLength())); } catch (Exception e) {} } /** * Sets the finder's controls enabled if no phrase entered. * @see DocumentListener#removeUpdate(DocumentEvent) */ public void removeUpdate(DocumentEvent de) { Document d = de.getDocument(); try { finder.setTextUpdate(d.getText(0, d.getLength())); } catch (Exception e) {} } /** * Required by I/F but no-op implementation in our case. * @see DocumentListener#changedUpdate(DocumentEvent) */ public void changedUpdate(DocumentEvent de) {} }); }
private void initComponents() { createMenuBar(); createLeftMenuBar(); caseSensitive = new JCheckBox("Match case"); caseSensitive.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JCheckBox source = (JCheckBox) e.getSource(); finder.setCaseSensitive(source.isSelected()); } }); infoComponent = new JPanel(); findArea = new JTextField(); findArea.setBorder(BorderFactory.createBevelBorder( BevelBorder.LOWERED)); findArea.setBackground(Color.WHITE); findArea.setOpaque(true); findArea.setEditable(true); int h = getFontMetrics(getFont()).getHeight()+4; findArea.setPreferredSize(new Dimension(WIDTH, h)); findArea.addKeyListener(new KeyAdapter() { /** Finds the phrase. */ public void keyPressed(KeyEvent e) { if ((e.getKeyCode() == KeyEvent.VK_ENTER)) { Object source = e.getSource(); if (source instanceof JTextField) { JTextField field = (JTextField) source; if (field.getText() != null && field.getText().length() > 0) finder.find(); } } } }); findArea.getDocument().addDocumentListener(new DocumentListener() { /** * Sets the finder's controls enabled if no phrase entered. * @see DocumentListener#removeUpdate(DocumentEvent) */ public void insertUpdate(DocumentEvent de) { Document d = de.getDocument(); try { finder.setTextUpdate(d.getText(0, d.getLength())); } catch (Exception e) {} } /** * Sets the finder's controls enabled if no phrase entered. * @see DocumentListener#removeUpdate(DocumentEvent) */ public void removeUpdate(DocumentEvent de) { Document d = de.getDocument(); try { finder.setTextUpdate(d.getText(0, d.getLength())); } catch (Exception e) {} } /** * Required by I/F but no-op implementation in our case. * @see DocumentListener#changedUpdate(DocumentEvent) */ public void changedUpdate(DocumentEvent de) {} }); }
3,229,933
public void stateChanged(ChangeEvent e) { JCheckBox source = (JCheckBox) e.getSource(); model.setCaseSensitive(source.isSelected()); }
public void stateChanged(ChangeEvent e) { JCheckBox source = (JCheckBox) e.getSource(); finder.setCaseSensitive(source.isSelected()); }
3,229,934
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
3,229,936
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
3,229,937
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
3,229,938
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
3,229,939
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
public Main(String[] args) { File dataFile = CoverageDataFileHandler.getDefaultDataFile(); String baseDir = "."; Vector filesToMerge = new Vector(); // Go through all the parameters for (int i = 0; i < args.length; i++) { if (args[i].equals("--datafile")) dataFile = new File(args[++i]); else if (args[i].equals("--basedir")) baseDir = args[++i]; else filesToMerge.add(baseDir + File.separator + args[i]); } // Load coverage data ProjectData projectData = null; if (dataFile.isFile()) projectData = CoverageDataFileHandler.loadCoverageData(dataFile); if (projectData == null) projectData = new ProjectData(); if (filesToMerge.size() == 0) { System.err.println("Error: No files were specified for merging."); System.exit(1); } // Merge everything Iterator iter = filesToMerge.iterator(); while (iter.hasNext()) { String newDataFileName = (String)iter.next(); File newDataFile = new File(newDataFileName); ProjectData projectDataNew = CoverageDataFileHandler .loadCoverageData(newDataFile); if (projectDataNew != null) projectData.merge(projectDataNew); } // Save the combined data file CoverageDataFileHandler.saveCoverageData(projectData, dataFile); }
3,229,940
public void close() throws IOException { if (bufferedIO) { /* flush output buffer before close */ if (outBuffer.position() > 0) { outBuffer.flip(); flushOutBuffer(); } } channel.close(); }
public void close() throws IOException { if (bufferedIO) { /* flush output buffer before close */ if (outBuffer.position() > 0) { outBuffer.flip(); flushOutBuffer(); } } channel.close(); }
3,229,942
public void putc(int c) throws IOException, BadDescriptorException { checkWritable(); setupBufferedIO(); if (!outBuffer.hasRemaining()) { outBuffer.flip(); flushOutBuffer(); } outBuffer.put((byte) (c & 0xff)); }
public void putc(int c) throws IOException, BadDescriptorException { checkWritable(); if (!outBuffer.hasRemaining()) { outBuffer.flip(); flushOutBuffer(); } outBuffer.put((byte) (c & 0xff)); }
3,229,943
private void setupBufferedIO() { if (bufferedIO) { return; } outBuffer = ByteBuffer.allocate(BLOCK_SIZE); inBuffer = ByteBuffer.allocate(BLOCK_SIZE); flushInBuffer(); bufferedIO = true; }
private void setupBufferedIO() { if (bufferedIO) { return; } inBuffer = ByteBuffer.allocate(BLOCK_SIZE); flushInBuffer(); bufferedIO = true; }
3,229,944
public int syswrite(String string) throws BadDescriptorException, IOException { checkWritable(); checkBuffered(); ByteBuffer buffer = ByteBuffer.wrap(RubyString.stringToBytes(string)); while (buffer.hasRemaining()) { if (((WritableByteChannel) channel).write(buffer) < 0) { // does this ever happen?? throw new IOException("write returned less than zero"); } } return buffer.capacity(); }
public int syswrite(String string) throws BadDescriptorException, IOException { checkWritable(); checkBuffered(); ByteBuffer buffer = ByteBuffer.wrap(RubyString.stringToBytes(string)); while (buffer.hasRemaining()) { if (((WritableByteChannel) channel).write(buffer) < 0) { // does this ever happen?? throw new IOException("write returned less than zero"); } } return buffer.capacity(); }
3,229,945
public int write(String string) throws IOException, BadDescriptorException { setupBufferedIO(); checkWritable(); ByteBuffer buffer = ByteBuffer.wrap(RubyString.stringToBytes(string)); byte[] trigger; IRubyObject dollar_backslash = getRuntime().getGlobalVariables().get("$\\"); if (dollar_backslash instanceof RubyString) { trigger = ((RubyString) dollar_backslash).toByteArray(); } else { trigger = RubyString.stringToBytes("\n"); } loop: while (buffer.hasRemaining()) { /* append data */ while (buffer.hasRemaining() && outBuffer.hasRemaining()) { outBuffer.put(buffer.get()); } int idx; outBuffer.flip(); if (!outBuffer.hasRemaining() || isSync()) { flushOutBuffer(); } else if ((idx = buffer_rindex(outBuffer, trigger)) >= 0) { int oldLimit = outBuffer.limit(); outBuffer.limit(idx + trigger.length); flushOutBuffer(); outBuffer.position(idx + trigger.length); outBuffer.limit(oldLimit); int i; for (i = 0; outBuffer.hasRemaining(); i++) { outBuffer.put(i, outBuffer.get()); } outBuffer.position(i); outBuffer.limit(outBuffer.capacity()); } else { // unflip outBuffer.position(outBuffer.limit()); outBuffer.limit(outBuffer.capacity()); } } return buffer.capacity(); }
public int write(String string) throws IOException, BadDescriptorException { checkWritable(); ByteBuffer buffer = ByteBuffer.wrap(RubyString.stringToBytes(string)); byte[] trigger; IRubyObject dollar_backslash = getRuntime().getGlobalVariables().get("$\\"); if (dollar_backslash instanceof RubyString) { trigger = ((RubyString) dollar_backslash).toByteArray(); } else { trigger = RubyString.stringToBytes("\n"); } loop: while (buffer.hasRemaining()) { /* append data */ while (buffer.hasRemaining() && outBuffer.hasRemaining()) { outBuffer.put(buffer.get()); } int idx; outBuffer.flip(); if (!outBuffer.hasRemaining() || isSync()) { flushOutBuffer(); } else if ((idx = buffer_rindex(outBuffer, trigger)) >= 0) { int oldLimit = outBuffer.limit(); outBuffer.limit(idx + trigger.length); flushOutBuffer(); outBuffer.position(idx + trigger.length); outBuffer.limit(oldLimit); int i; for (i = 0; outBuffer.hasRemaining(); i++) { outBuffer.put(i, outBuffer.get()); } outBuffer.position(i); outBuffer.limit(outBuffer.capacity()); } else { // unflip outBuffer.position(outBuffer.limit()); outBuffer.limit(outBuffer.capacity()); } } return buffer.capacity(); }
3,229,947
public EnumType(Properties attrs){super(attrs);}
public EnumType(Properties attrs){super(attrs);}
3,229,948
private JComponent buildCenterComponent() { switch (model.getEditorType()) { case Editor.CREATE_EDITOR: return doBasic; case Editor.PROPERTIES_EDITOR: IconManager im = IconManager.getInstance(); JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); tabs.setAlignmentX(LEFT_ALIGNMENT); tabs.addTab(PROPERTIES_TITLE, im.getIcon(IconManager.PROPERTIES), doBasic); ExperimenterData exp = model.getExperimenterData(); Map details = EditorUtil.transformExperimenterData(exp); tabs.addTab(OWNER_TITLE, im.getIcon(IconManager.OWNER), new DOInfo(details, model)); DataObject hierarchyObject = model.getHierarchyObject(); if (hierarchyObject instanceof ImageData) { details = EditorUtil.transformPixelsData( ((ImageData) hierarchyObject).getDefaultPixels()); tabs.addTab(INFO_TITLE, im.getIcon(IconManager.IMAGE), new DOInfo(details, null)); } return tabs; } return null; }
private JComponent buildCenterComponent() { switch (model.getEditorType()) { case Editor.CREATE_EDITOR: return doBasic; case Editor.PROPERTIES_EDITOR: IconManager im = IconManager.getInstance(); JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); tabs.setAlignmentX(LEFT_ALIGNMENT); tabs.addTab(PROPERTIES_TITLE, im.getIcon(IconManager.PROPERTIES), doBasic); ExperimenterData exp = model.getExperimenterData(); Map details = EditorUtil.transformExperimenterData(exp); tabs.addTab(OWNER_TITLE, im.getIcon(IconManager.OWNER), new DOInfo(details, model, true)); DataObject hierarchyObject = model.getHierarchyObject(); if (hierarchyObject instanceof ImageData) { details = EditorUtil.transformPixelsData( ((ImageData) hierarchyObject).getDefaultPixels()); tabs.addTab(INFO_TITLE, im.getIcon(IconManager.IMAGE), new DOInfo(details, null)); } return tabs; } return null; }
3,229,949
private JComponent buildCenterComponent() { switch (model.getEditorType()) { case Editor.CREATE_EDITOR: return doBasic; case Editor.PROPERTIES_EDITOR: IconManager im = IconManager.getInstance(); JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); tabs.setAlignmentX(LEFT_ALIGNMENT); tabs.addTab(PROPERTIES_TITLE, im.getIcon(IconManager.PROPERTIES), doBasic); ExperimenterData exp = model.getExperimenterData(); Map details = EditorUtil.transformExperimenterData(exp); tabs.addTab(OWNER_TITLE, im.getIcon(IconManager.OWNER), new DOInfo(details, model)); DataObject hierarchyObject = model.getHierarchyObject(); if (hierarchyObject instanceof ImageData) { details = EditorUtil.transformPixelsData( ((ImageData) hierarchyObject).getDefaultPixels()); tabs.addTab(INFO_TITLE, im.getIcon(IconManager.IMAGE), new DOInfo(details, null)); } return tabs; } return null; }
private JComponent buildCenterComponent() { switch (model.getEditorType()) { case Editor.CREATE_EDITOR: return doBasic; case Editor.PROPERTIES_EDITOR: IconManager im = IconManager.getInstance(); JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); tabs.setAlignmentX(LEFT_ALIGNMENT); tabs.addTab(PROPERTIES_TITLE, im.getIcon(IconManager.PROPERTIES), doBasic); ExperimenterData exp = model.getExperimenterData(); Map details = EditorUtil.transformExperimenterData(exp); tabs.addTab(OWNER_TITLE, im.getIcon(IconManager.OWNER), new DOInfo(details, model)); DataObject hierarchyObject = model.getHierarchyObject(); if (hierarchyObject instanceof ImageData) { details = EditorUtil.transformPixelsData( ((ImageData) hierarchyObject).getDefaultPixels()); tabs.addTab(INFO_TITLE, im.getIcon(IconManager.IMAGE), new DOInfo(details, model, false)); } return tabs; } return null; }
3,229,950
ZoomWindowUI(JFrame parent, LensComponent lensComponent) { super(parent); this.lensComponent = lensComponent; setTitle("Zoom Window"); setSize(300,300); setLocation(900,200); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { close(); } }); zoomPanel = new ZoomPanel(); scrollPanel = new JScrollPane(zoomPanel); statusPanel = new StatusPanel(); this.setLayout(new BorderLayout()); this.add(scrollPanel, BorderLayout.CENTER); this.add(statusPanel, BorderLayout.SOUTH); lensMenu = LensMenu.getMenu(lensComponent); menu = lensMenu.getMenubar(); this.setJMenuBar(menu); }
ZoomWindowUI(JFrame parent, LensComponent lensComponent) { super(parent); this.lensComponent = lensComponent; setTitle("Zoom Window"); setSize(300,300); setLocation(900,200); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { close(); } }); zoomPanel = new ZoomPanel(); scrollPanel = new JScrollPane(zoomPanel); statusPanel = new StatusPanel(); this.setLayout(new BorderLayout()); this.add(scrollPanel, BorderLayout.CENTER); this.add(statusPanel, BorderLayout.SOUTH); lensMenu = LensMenu.getMenu(lensComponent); menu = lensMenu.getMenubar(); this.setJMenuBar(menu); }
3,229,951
public void test_multi_txs() throws Exception { ReadWriteLock rwl = null; fail(); }
public void test_multi_txs() throws Exception { ReadWriteLock rwl = null; }
3,229,952
protected void buildQuery(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria((Class) value(CLASS)); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); c.add(Restrictions.in("id",(Collection) value(IDS))); Hierarchy.fetchChildren(c,(Class) value(CLASS),Integer.MAX_VALUE); setCriteria( c ); }
protected void buildQuery(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(Image.class); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); c.add(Restrictions.in("id",(Collection) value(IDS))); Hierarchy.fetchChildren(c,(Class) value(CLASS),Integer.MAX_VALUE); setCriteria( c ); }
3,229,953
protected void buildQuery(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria((Class) value(CLASS)); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); c.add(Restrictions.in("id",(Collection) value(IDS))); Hierarchy.fetchChildren(c,(Class) value(CLASS),Integer.MAX_VALUE); setCriteria( c ); }
protected void buildQuery(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria((Class) value(CLASS)); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); c.add(Restrictions.in("id",(Collection) value(IDS))); Hierarchy.fetchChildren(c,(Class) value(CLASS),Integer.MAX_VALUE); setCriteria( c ); }
3,229,954
public static IRubyObject newInstance(IRubyObject recv, IRubyObject[] args) { Cipher result = new Cipher(recv.getRuntime(), (RubyClass)recv); result.callMethod(recv.getRuntime().getCurrentContext(),"initialize",args); return result; }
public static IRubyObject newInstance(IRubyObject recv, IRubyObject[] args) { Cipher result = new Cipher(recv.getRuntime(), (RubyClass)recv); result.callInit(args); return result; }
3,229,955
public void showInspector() { if (imageInspector == null) imageInspector = new ImageInspector(this, presentation.getCanvas(), magFactor); presentation.getCanvas().getManager().setClick(true); UIUtilities.centerAndShow(imageInspector); if (roiOnOff) imageInspector.getManager().setLensEnabled(false); }
public void showInspector() { if (imageInspector == null) imageInspector = new ImageInspector(this, presentation.getCanvas(), magFactor, abstraction.getImageWidth(), abstraction.getImageHeight()); presentation.getCanvas().getManager().setClick(true); UIUtilities.centerAndShow(imageInspector); if (roiOnOff) imageInspector.getManager().setLensEnabled(false); }
3,229,956
private void prepareArguments(ThreadContext context, IRuby runtime, Scope scope, IRubyObject receiver, IRubyObject[] args) { int expectedArgsCount = argsNode.getArgsCount(); int restArg = argsNode.getRestArg(); boolean hasOptArgs = argsNode.getOptArgs() != null; // FIXME: This seems redundant with the arity check in internalCall...is it actually different? if (expectedArgsCount > args.length) { throw runtime.newArgumentError("Wrong # of arguments(" + args.length + " for " + expectedArgsCount + ")"); } if (scope.hasLocalVariables() && expectedArgsCount > 0) { scope.setValues(args, false); } // optArgs and restArgs require more work, so isolate them and ArrayList creation here if (hasOptArgs || restArg != -1) { args = prepareOptOrRestArgs(context, runtime, scope, args, expectedArgsCount, restArg, hasOptArgs); } context.setFrameArgs(args); }
private void prepareArguments(ThreadContext context, IRuby runtime, Scope scope, IRubyObject receiver, IRubyObject[] args) { int expectedArgsCount = argsNode.getArgsCount(); int restArg = argsNode.getRestArg(); boolean hasOptArgs = argsNode.getOptArgs() != null; // FIXME: This seems redundant with the arity check in internalCall...is it actually different? if (expectedArgsCount > args.length) { throw runtime.newArgumentError("Wrong # of arguments(" + args.length + " for " + expectedArgsCount + ")"); } if (scope.hasLocalVariables() && expectedArgsCount > 0) { scope.setValues(args, expectedArgsCount, false); } // optArgs and restArgs require more work, so isolate them and ArrayList creation here if (hasOptArgs || restArg != -1) { args = prepareOptOrRestArgs(context, runtime, scope, args, expectedArgsCount, restArg, hasOptArgs); } context.setFrameArgs(args); }
3,229,957
private String handleError( Variable variable, Context context, Exception problem ) { String strError; ArrayList arlErrors = null; PropertyException propEx = null; if (problem instanceof PropertyException) propEx = (PropertyException)problem; else { propEx = new PropertyException( "Error expanding $" + variable.getVariableName()); propEx.setContextLocation(context.getCurrentLocation()); } strError = propEx.getMessage(); if ( context.containsKey( "WMERROR" ) ) { arlErrors = ( ArrayList ) context.get( "WMERROR" ); } else { arlErrors = new ArrayList(); context.put( "WMERROR", arlErrors ); } arlErrors.add( strError ); if ( _log != null ) { _log.warning( strError, problem ); } return errorString( strError ); }
private String handleError( Variable variable, Context context, Exception problem ) { String strError; ArrayList arlErrors = null; PropertyException propEx = null; if (problem instanceof PropertyException) propEx = (PropertyException)problem; else propEx = new PropertyException( "Error expanding $" + variable.getVariableName()); propEx.setContextLocation(context.getCurrentLocation()); } strError = propEx.getMessage(); if ( context.containsKey( "WMERROR" ) ) { arlErrors = ( ArrayList ) context.get( "WMERROR" ); } else { arlErrors = new ArrayList(); context.put( "WMERROR", arlErrors ); } arlErrors.add( strError ); if ( _log != null ) { _log.warning( strError, problem ); } return errorString( strError ); }
3,229,958
private String handleError( Variable variable, Context context, Exception problem ) { String strError; ArrayList arlErrors = null; PropertyException propEx = null; if (problem instanceof PropertyException) propEx = (PropertyException)problem; else { propEx = new PropertyException( "Error expanding $" + variable.getVariableName()); propEx.setContextLocation(context.getCurrentLocation()); } strError = propEx.getMessage(); if ( context.containsKey( "WMERROR" ) ) { arlErrors = ( ArrayList ) context.get( "WMERROR" ); } else { arlErrors = new ArrayList(); context.put( "WMERROR", arlErrors ); } arlErrors.add( strError ); if ( _log != null ) { _log.warning( strError, problem ); } return errorString( strError ); }
private String handleError( Variable variable, Context context, Exception problem ) { String strError; ArrayList arlErrors = null; PropertyException propEx = null; if (problem instanceof PropertyException) propEx = (PropertyException)problem; else { propEx = new PropertyException( "Error expanding $" + variable.getVariableName()); propEx.setContextLocation(context.getCurrentLocation()); } strError = propEx.getMessage(); if ( context.containsKey( "WMERROR" ) ) { arlErrors = ( ArrayList ) context.get( "WMERROR" ); } else { arlErrors = new ArrayList(); context.put( "WMERROR", arlErrors ); } arlErrors.add( strError ); if ( _log != null ) { _log.warning( strError, problem ); } return errorString( strError ); }
3,229,959
public List getList() { return list; }
public ArrayList getList() { return list; }
3,229,960
public void testExperimenterShouldAlwaysExist() throws Exception { Experimenter root = (Experimenter) iQuery.findByQuery(Experimenter.class.getName(), new Parameters().addId(0L)); assertNotNull("Root has to be define.",root); // FIXME assertNotNull("And it should have details",root.getDetails()); List<Experimenter> l = iQuery.findAllByQuery("from Experimenter",null); assertTrue("If root is defined, can't be empty",l.size()>0); }
public void testExperimenterShouldAlwaysExist() throws Exception { Experimenter root = (Experimenter) iQuery.findByQuery(Experimenter.class.getName(), new Parameters().addId(0L)); assertNotNull("Root has to be defined.",root); // FIXME assertNotNull("And it should have details",root.getDetails()); List<Experimenter> l = iQuery.findAllByQuery("from Experimenter",null); assertTrue("If root is defined, can't be empty",l.size()>0); }
3,229,961
public void setEnabled(boolean enabled) { if (this.enabled != enabled) { this.enabled = enabled; if (headingItem != null) headingItem.setEnabled(enabled); } }
public void setEnabled(boolean enabled) { if (this.enabled != enabled) { this.enabled = enabled; if (headingItem != null) headingItem.setEnabled(enabled); } }
3,229,962
public void update() { super.update(); if (headingItem != null && headingItem.isEnabled() != enabled) { headingItem.setEnabled(enabled); } }
public void update() { super.update(); if (headingItem != null && headingItem.isEnabled() != enabled) { headingItem.setEnabled(enabled); } }
3,229,963
public void updateAll(boolean arg0) { super.updateAll(arg0); if (headingItem != null && headingItem.isEnabled() != enabled) { headingItem.setEnabled(enabled); } }
public void updateAll(boolean arg0) { super.updateAll(arg0); if (headingItem != null && headingItem.isEnabled() != enabled) { headingItem.setEnabled(enabled); } }
3,229,964
public IRubyObject unmarshalObject() throws IOException { int type = readUnsignedByte(); IRubyObject result; if (type == '@') { result = cache.linkedByIndex(unmarshalInt()); } else if (type == ';') { result = cache.symbolByIndex(unmarshalInt()); } else { result = unmarshalObjectDirectly(type); } cache.register(result); return result; }
public IRubyObject unmarshalObject() throws IOException { int type = readUnsignedByte(); IRubyObject result; if (type == '@') { result = cache.linkedByIndex(unmarshalInt()); } else if (type == ';') { result = cache.symbolByIndex(unmarshalInt()); } else { result = unmarshalObjectDirectly(type); } return result; }
3,229,966
private IRubyObject userUnmarshal() throws IOException { String className = ((RubySymbol) unmarshalObject()).toId(); String marshaled = unmarshalString(); RubyModule classInstance = runtime.getRubyModule(className); return classInstance.callMethod( "_load", RubyString.newString(runtime, marshaled)); }
private IRubyObject userUnmarshal() throws IOException { String className = ((RubySymbol) unmarshalObject()).toId(); String marshaled = unmarshalString(); RubyModule classInstance = runtime.getRubyModule(className); IRubyObject result = classInstance.callMethod( "_load", RubyString.newString(runtime, marshaled)); }
3,229,967
private static IRubyObject evalInternal(ThreadContext context, Node node, IRubyObject self) { IRuby runtime = context.getRuntime(); bigloop: do { if (node == null) return runtime.getNil(); switch (node.nodeId) { case NodeTypes.ALIASNODE: { AliasNode iVisited = (AliasNode) node; if (context.getRubyClass() == null) { throw runtime.newTypeError("no class to make alias"); } context.getRubyClass().defineAlias(iVisited.getNewName(), iVisited.getOldName()); context.getRubyClass().callMethod(context, "method_added", runtime.newSymbol(iVisited.getNewName())); return runtime.getNil(); } case NodeTypes.ANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.ARGSCATNODE: { ArgsCatNode iVisited = (ArgsCatNode) node; IRubyObject args = evalInternal(context, iVisited.getFirstNode(), self); IRubyObject secondArgs = splatValue(evalInternal(context, iVisited.getSecondNode(), self)); RubyArray list = args instanceof RubyArray ? (RubyArray) args : runtime.newArray(args); return list.concat(secondArgs); } // case NodeTypes.ARGSNODE: // EvaluateVisitor.argsNodeVisitor.execute(this, node); // break; // case NodeTypes.ARGUMENTNODE: // EvaluateVisitor.argumentNodeVisitor.execute(this, node); // break; case NodeTypes.ARRAYNODE: { ArrayNode iVisited = (ArrayNode) node; IRubyObject[] array = new IRubyObject[iVisited.size()]; int i = 0; for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node next = (Node) iterator.next(); array[i++] = evalInternal(context, next, self); } return runtime.newArray(array); } // case NodeTypes.ASSIGNABLENODE: // EvaluateVisitor.assignableNodeVisitor.execute(this, node); // break; case NodeTypes.BACKREFNODE: { BackRefNode iVisited = (BackRefNode) node; IRubyObject backref = context.getBackref(); switch (iVisited.getType()) { case '~': return backref; case '&': return RubyRegexp.last_match(backref); case '`': return RubyRegexp.match_pre(backref); case '\'': return RubyRegexp.match_post(backref); case '+': return RubyRegexp.match_last(backref); } break; } case NodeTypes.BEGINNODE: { BeginNode iVisited = (BeginNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.BIGNUMNODE: { BignumNode iVisited = (BignumNode) node; return RubyBignum.newBignum(runtime, iVisited.getValue()); } // case NodeTypes.BINARYOPERATORNODE: // EvaluateVisitor.binaryOperatorNodeVisitor.execute(this, node); // break; // case NodeTypes.BLOCKARGNODE: // EvaluateVisitor.blockArgNodeVisitor.execute(this, node); // break; case NodeTypes.BLOCKNODE: { BlockNode iVisited = (BlockNode) node; IRubyObject result = runtime.getNil(); for (Iterator iter = iVisited.iterator(); iter.hasNext();) { result = evalInternal(context, (Node) iter.next(), self); } return result; } case NodeTypes.BLOCKPASSNODE: { BlockPassNode iVisited = (BlockPassNode) node; IRubyObject proc = evalInternal(context, iVisited.getBodyNode(), self); if (proc.isNil()) { context.setNoBlock(); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearNoBlock(); } } // If not already a proc then we should try and make it one. if (!(proc instanceof RubyProc)) { proc = proc.convertToType("Proc", "to_proc", false); if (!(proc instanceof RubyProc)) { throw runtime.newTypeError("wrong argument type " + proc.getMetaClass().getName() + " (expected Proc)"); } } // TODO: Add safety check for taintedness Block block = (Block) context.getCurrentBlock(); if (block != null) { IRubyObject blockObject = block.getBlockObject(); // The current block is already associated with the proc. No need to create new // block for it. Just eval! if (blockObject != null && blockObject == proc) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearBlockAvailable(); } } } context.preBlockPassEval(((RubyProc) proc).getBlock()); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.postBlockPassEval(); } } case NodeTypes.BREAKNODE: { BreakNode iVisited = (BreakNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.BreakJump); je.setPrimaryData(result); je.setSecondaryData(node); throw je; } case NodeTypes.CALLNODE: { CallNode iVisited = (CallNode) node; context.beginCallArgs(); IRubyObject receiver = null; IRubyObject[] args = null; try { receiver = evalInternal(context, iVisited.getReceiverNode(), self); args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } assert receiver.getMetaClass() != null : receiver.getClass().getName(); // If reciever is self then we do the call the same way as vcall CallType callType = (receiver == self ? CallType.VARIABLE : CallType.NORMAL); return receiver.callMethod(context, iVisited.getName(), args, callType); } case NodeTypes.CASENODE: { CaseNode iVisited = (CaseNode) node; IRubyObject expression = null; if (iVisited.getCaseNode() != null) { expression = evalInternal(context, iVisited.getCaseNode(), self); } context.pollThreadEvents(); IRubyObject result = runtime.getNil(); Node firstWhenNode = iVisited.getFirstWhenNode(); while (firstWhenNode != null) { if (!(firstWhenNode instanceof WhenNode)) { node = firstWhenNode; continue bigloop; } WhenNode whenNode = (WhenNode) firstWhenNode; if (whenNode.getExpressionNodes() instanceof ArrayNode) { for (Iterator iter = ((ArrayNode) whenNode.getExpressionNodes()).iterator(); iter .hasNext();) { Node tag = (Node) iter.next(); context.setPosition(tag.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // Ruby grammar has nested whens in a case body because of // productions case_body and when_args. if (tag instanceof WhenNode) { RubyArray expressions = (RubyArray) evalInternal(context, ((WhenNode) tag) .getExpressionNodes(), self); for (int j = 0; j < expressions.getLength(); j++) { IRubyObject condition = expressions.entry(j); if ((expression != null && condition.callMethod(context, "===", expression) .isTrue()) || (expression == null && condition.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } continue; } result = evalInternal(context, tag, self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = whenNode.getBodyNode(); continue bigloop; } } } else { result = evalInternal(context, whenNode.getExpressionNodes(), self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } context.pollThreadEvents(); firstWhenNode = whenNode.getNextCase(); } return runtime.getNil(); } case NodeTypes.CLASSNODE: { ClassNode iVisited = (ClassNode) node; Node superNode = iVisited.getSuperNode(); RubyClass superClass = superNode == null ? null : (RubyClass) evalInternal(context, superNode, self); Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingClass = getEnclosingModule(context, classNameNode, self); RubyClass rubyClass = enclosingClass.defineOrGetClassUnder(name, superClass); if (context.getWrapper() != null) { rubyClass.extendObject(context.getWrapper()); rubyClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), rubyClass, self); } case NodeTypes.CLASSVARASGNNODE: { ClassVarAsgnNode iVisited = (ClassVarAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule) rubyClass.getInstanceVariable("__attached__"); } rubyClass.setClassVar(iVisited.getName(), result); return result; } case NodeTypes.CLASSVARDECLNODE: { ClassVarDeclNode iVisited = (ClassVarDeclNode) node; // FIXME: shouldn't we use cref here? if (context.getRubyClass() == null) { throw runtime.newTypeError("no class/module to define class variable"); } IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); ((RubyModule) context.peekCRef().getValue()).setClassVar(iVisited.getName(), result); return runtime.getNil(); } case NodeTypes.CLASSVARNODE: { ClassVarNode iVisited = (ClassVarNode) node; RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule)rubyClass.getInstanceVariable("__attached__"); } return rubyClass.getClassVar(iVisited.getName()); } case NodeTypes.COLON2NODE: { Colon2Node iVisited = (Colon2Node) node; Node leftNode = iVisited.getLeftNode(); // TODO: Made this more colon3 friendly because of cpath production // rule in grammar (it is convenient to think of them as the same thing // at a grammar level even though evaluation is). if (leftNode == null) { return runtime.getObject().getConstantFrom(iVisited.getName()); } else { IRubyObject result = evalInternal(context, iVisited.getLeftNode(), self); if (result instanceof RubyModule) { return ((RubyModule) result).getConstantFrom(iVisited.getName()); } else { return result.callMethod(context, iVisited.getName()); } } } case NodeTypes.COLON3NODE: { Colon3Node iVisited = (Colon3Node) node; return runtime.getObject().getConstantFrom(iVisited.getName()); } case NodeTypes.CONSTDECLNODE: { ConstDeclNode iVisited = (ConstDeclNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); IRubyObject module; if (iVisited.getPathNode() != null) { module = evalInternal(context, iVisited.getPathNode(), self); } else { // FIXME: why do we check RubyClass and then use CRef? if (context.getRubyClass() == null) { // TODO: wire into new exception handling mechanism throw runtime.newTypeError("no class/module to define constant"); } module = (RubyModule) context.peekCRef().getValue(); } // FIXME: shouldn't we use the result of this set in setResult? ((RubyModule) module).setConstant(iVisited.getName(), result); return result; } case NodeTypes.CONSTNODE: { ConstNode iVisited = (ConstNode) node; return context.getConstant(iVisited.getName()); } case NodeTypes.DASGNNODE: { DAsgnNode iVisited = (DAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("DSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.DEFINEDNODE: { DefinedNode iVisited = (DefinedNode) node; String definition = getDefinition(context, iVisited.getExpressionNode(), self); if (definition != null) { return runtime.newString(definition); } else { return runtime.getNil(); } } case NodeTypes.DEFNNODE: { DefnNode iVisited = (DefnNode) node; RubyModule containingClass = context.getRubyClass(); if (containingClass == null) { throw runtime.newTypeError("No class to add method."); } String name = iVisited.getName(); if (containingClass == runtime.getObject() && name.equals("initialize")) { runtime.getWarnings().warn("redefining Object#initialize may cause infinite loop"); } Visibility visibility = context.getCurrentVisibility(); if (name.equals("initialize") || visibility.isModuleFunction()) { visibility = Visibility.PRIVATE; } DefaultMethod newMethod = new DefaultMethod(containingClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), visibility, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } containingClass.addMethod(name, newMethod); if (context.getCurrentVisibility().isModuleFunction()) { containingClass.getSingletonClass().addMethod( name, new WrapperCallable(containingClass.getSingletonClass(), newMethod, Visibility.PUBLIC)); containingClass.callMethod(context, "singleton_method_added", runtime.newSymbol(name)); } // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { ((MetaClass) containingClass).getAttachedObject().callMethod( context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); } else { containingClass.callMethod(context, "method_added", runtime.newSymbol(name)); } return runtime.getNil(); } case NodeTypes.DEFSNODE: { DefsNode iVisited = (DefsNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure; can't define singleton method."); } if (receiver.isFrozen()) { throw runtime.newFrozenError("object"); } if (!receiver.singletonMethodsAllowed()) { throw runtime.newTypeError("can't define singleton method \"" + iVisited.getName() + "\" for " + receiver.getType()); } RubyClass rubyClass = receiver.getSingletonClass(); if (runtime.getSafeLevel() >= 4) { ICallable method = (ICallable) rubyClass.getMethods().get(iVisited.getName()); if (method != null) { throw runtime.newSecurityError("Redefining method prohibited."); } } DefaultMethod newMethod = new DefaultMethod(rubyClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), Visibility.PUBLIC, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } rubyClass.addMethod(iVisited.getName(), newMethod); receiver.callMethod(context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); return runtime.getNil(); } case NodeTypes.DOTNODE: { DotNode iVisited = (DotNode) node; return RubyRange.newRange(runtime, evalInternal(context, iVisited.getBeginNode(), self), evalInternal(context, iVisited .getEndNode(), self), iVisited.isExclusive()); } case NodeTypes.DREGEXPNODE: { DRegexpNode iVisited = (DRegexpNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return RubyRegexp.newRegexp(runtime, sb.toString(), iVisited.getOptions(), null); } case NodeTypes.DSTRNODE: { DStrNode iVisited = (DStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newString(sb.toString()); } case NodeTypes.DSYMBOLNODE: { DSymbolNode iVisited = (DSymbolNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.getNode().iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newSymbol(sb.toString()); } case NodeTypes.DVARNODE: { DVarNode iVisited = (DVarNode) node; // System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject obj = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); // FIXME: null check is removable once we figure out how to assign to unset named block args return obj == null ? runtime.getNil() : obj; } case NodeTypes.DXSTRNODE: { DXStrNode iVisited = (DXStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return self.callMethod(context, "`", runtime.newString(sb.toString())); } case NodeTypes.ENSURENODE: { EnsureNode iVisited = (EnsureNode) node; // save entering the try if there's nothing to ensure if (iVisited.getEnsureNode() != null) { IRubyObject result = runtime.getNil(); try { result = evalInternal(context, iVisited.getBodyNode(), self); } finally { evalInternal(context, iVisited.getEnsureNode(), self); } return result; } node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.EVSTRNODE: { EvStrNode iVisited = (EvStrNode) node; node = iVisited.getBody(); continue bigloop; } case NodeTypes.FALSENODE: { context.pollThreadEvents(); return runtime.getFalse(); } case NodeTypes.FCALLNODE: { FCallNode iVisited = (FCallNode) node; context.beginCallArgs(); IRubyObject[] args; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return self.callMethod(context, iVisited.getName(), args, CallType.FUNCTIONAL); } case NodeTypes.FIXNUMNODE: { FixnumNode iVisited = (FixnumNode) node; return runtime.newFixnum(iVisited.getValue()); } case NodeTypes.FLIPNODE: { FlipNode iVisited = (FlipNode) node; IRubyObject result = runtime.getNil(); if (iVisited.isExclusive()) { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { result = evalInternal(context, iVisited.getBeginNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } else { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { if (evalInternal(context, iVisited.getBeginNode(), self).isTrue()) { context.getCurrentScope().setValue( iVisited.getIndex(), evalInternal(context, iVisited.getEndNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(), iVisited.getDepth()); return runtime.getTrue(); } else { return runtime.getFalse(); } } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } } case NodeTypes.FLOATNODE: { FloatNode iVisited = (FloatNode) node; return RubyFloat.newFloat(runtime, iVisited.getValue()); } case NodeTypes.FORNODE: { ForNode iVisited = (ForNode) node; // For nodes do not have to create an addition scope so we just pass null context.preForLoopEval(Block.createBlock(iVisited.getVarNode(), null, iVisited.getCallable(), self)); try { while (true) { try { ISourcePosition position = context.getPosition(); context.beginCallArgs(); IRubyObject recv = null; try { recv = evalInternal(context, iVisited.getIterNode(), self); } finally { context.setPosition(position); context.endCallArgs(); } return recv.callMethod(context, "each", IRubyObject.NULL_ARRAY, CallType.NORMAL); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // do nothing, allow loop to retry break; default: throw je; } } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postForLoopEval(); } } case NodeTypes.GLOBALASGNNODE: { GlobalAsgnNode iVisited = (GlobalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); runtime.getGlobalVariables().set(iVisited.getName(), result); return result; } case NodeTypes.GLOBALVARNODE: { GlobalVarNode iVisited = (GlobalVarNode) node; return runtime.getGlobalVariables().get(iVisited.getName()); } case NodeTypes.HASHNODE: { HashNode iVisited = (HashNode) node; Map hash = null; if (iVisited.getListNode() != null) { hash = new HashMap(iVisited.getListNode().size() / 2); for (Iterator iterator = iVisited.getListNode().iterator(); iterator.hasNext();) { // insert all nodes in sequence, hash them in the final instruction // KEY IRubyObject key = evalInternal(context, (Node) iterator.next(), self); IRubyObject value = evalInternal(context, (Node) iterator.next(), self); hash.put(key, value); } } if (hash == null) { return RubyHash.newHash(runtime); } return RubyHash.newHash(runtime, hash, runtime.getNil()); } case NodeTypes.IFNODE: { IfNode iVisited = (IfNode) node; IRubyObject result = evalInternal(context, iVisited.getCondition(), self); if (result.isTrue()) { node = iVisited.getThenBody(); continue bigloop; } else { node = iVisited.getElseBody(); continue bigloop; } } case NodeTypes.INSTASGNNODE: { InstAsgnNode iVisited = (InstAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); self.setInstanceVariable(iVisited.getName(), result); return result; } case NodeTypes.INSTVARNODE: { InstVarNode iVisited = (InstVarNode) node; IRubyObject variable = self.getInstanceVariable(iVisited.getName()); return variable == null ? runtime.getNil() : variable; } // case NodeTypes.ISCOPINGNODE: // EvaluateVisitor.iScopingNodeVisitor.execute(this, node); // break; case NodeTypes.ITERNODE: { IterNode iVisited = (IterNode) node; context.preIterEval(Block.createBlock(iVisited.getVarNode(), new DynamicScope(iVisited.getScope(), context.getCurrentScope()), iVisited.getCallable(), self)); try { while (true) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // allow loop to retry break; default: throw je; } } finally { context.clearBlockAvailable(); } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postIterEval(); } } case NodeTypes.LOCALASGNNODE: { LocalAsgnNode iVisited = (LocalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("LSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.LOCALVARNODE: { LocalVarNode iVisited = (LocalVarNode) node; //System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject result = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); return result == null ? runtime.getNil() : result; } case NodeTypes.MATCH2NODE: { Match2Node iVisited = (Match2Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); return ((RubyRegexp) recv).match(value); } case NodeTypes.MATCH3NODE: { Match3Node iVisited = (Match3Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); if (value instanceof RubyString) { return ((RubyRegexp) recv).match(value); } else { return value.callMethod(context, "=~", recv); } } case NodeTypes.MATCHNODE: { MatchNode iVisited = (MatchNode) node; return ((RubyRegexp) evalInternal(context, iVisited.getRegexpNode(), self)).match2(); } case NodeTypes.MODULENODE: { ModuleNode iVisited = (ModuleNode) node; Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingModule = getEnclosingModule(context, classNameNode, self); if (enclosingModule == null) { throw runtime.newTypeError("no outer class/module"); } RubyModule module; if (enclosingModule == runtime.getObject()) { module = runtime.getOrCreateModule(name); } else { module = enclosingModule.defineModuleUnder(name); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), module, self); } case NodeTypes.MULTIPLEASGNNODE: { MultipleAsgnNode iVisited = (MultipleAsgnNode) node; return AssignmentVisitor.assign(context, self, iVisited, evalInternal(context, iVisited.getValueNode(), self), false); } case NodeTypes.NEWLINENODE: { NewlineNode iVisited = (NewlineNode) node; // something in here is used to build up ruby stack trace... context.setPosition(iVisited.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // TODO: do above but not below for additional newline nodes node = iVisited.getNextNode(); continue bigloop; } case NodeTypes.NEXTNODE: { NextNode iVisited = (NextNode) node; context.pollThreadEvents(); IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.NextJump); je.setPrimaryData(result); je.setSecondaryData(iVisited); //state.setCurrentException(je); throw je; } case NodeTypes.NILNODE: return runtime.getNil(); case NodeTypes.NOTNODE: { NotNode iVisited = (NotNode) node; IRubyObject result = evalInternal(context, iVisited.getConditionNode(), self); return result.isTrue() ? runtime.getFalse() : runtime.getTrue(); } case NodeTypes.NTHREFNODE: { NthRefNode iVisited = (NthRefNode) node; return RubyRegexp.nth_match(iVisited.getMatchNumber(), context.getBackref()); } case NodeTypes.OPASGNANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; // add in reverse order IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.OPASGNNODE: { OpAsgnNode iVisited = (OpAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = receiver.callMethod(context, iVisited.getVariableName()); if (iVisited.getOperatorName().equals("||")) { if (value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else { value = value.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited.getValueNode(), self)); } receiver.callMethod(context, iVisited.getVariableName() + "=", value); context.pollThreadEvents(); return value; } case NodeTypes.OPASGNORNODE: { OpAsgnOrNode iVisited = (OpAsgnOrNode) node; String def = getDefinition(context, iVisited.getFirstNode(), self); IRubyObject result = runtime.getNil(); if (def != null) { result = evalInternal(context, iVisited.getFirstNode(), self); } if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } case NodeTypes.OPELEMENTASGNNODE: { OpElementAsgnNode iVisited = (OpElementAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject[] args = setupArgs(context, iVisited.getArgsNode(), self); IRubyObject firstValue = receiver.callMethod(context, "[]", args); if (iVisited.getOperatorName().equals("||")) { if (firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else { firstValue = firstValue.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited .getValueNode(), self)); } IRubyObject[] expandedArgs = new IRubyObject[args.length + 1]; System.arraycopy(args, 0, expandedArgs, 0, args.length); expandedArgs[expandedArgs.length - 1] = firstValue; return receiver.callMethod(context, "[]=", expandedArgs); } case NodeTypes.OPTNNODE: { OptNNode iVisited = (OptNNode) node; IRubyObject result = runtime.getNil(); while (RubyKernel.gets(runtime.getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: // do nothing, this iteration restarts break; case JumpType.NEXT: // recheck condition break loop; case JumpType.BREAK: // end loop return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.ORNODE: { OrNode iVisited = (OrNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } // case NodeTypes.POSTEXENODE: // EvaluateVisitor.postExeNodeVisitor.execute(this, node); // break; case NodeTypes.REDONODE: { context.pollThreadEvents(); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.RedoJump); je.setSecondaryData(node); throw je; } case NodeTypes.REGEXPNODE: { RegexpNode iVisited = (RegexpNode) node; // FIXME: don't pass null return RubyRegexp.newRegexp(runtime, iVisited.getPattern(), null); } case NodeTypes.RESCUEBODYNODE: { RescueBodyNode iVisited = (RescueBodyNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.RESCUENODE: { RescueNode iVisited = (RescueNode)node; RescuedBlock : while (true) { try { // Execute rescue block IRubyObject result = evalInternal(context, iVisited.getBodyNode(), self); // If no exception is thrown execute else block if (iVisited.getElseNode() != null) { if (iVisited.getRescueNode() == null) { runtime.getWarnings().warn(iVisited.getElseNode().getPosition(), "else without rescue is useless"); } result = evalInternal(context, iVisited.getElseNode(), self); } return result; } catch (RaiseException raiseJump) { RubyException raisedException = raiseJump.getException(); // TODO: Rubicon TestKernel dies without this line. A cursory glance implies we // falsely set $! to nil and this sets it back to something valid. This should // get fixed at the same time we address bug #1296484. runtime.getGlobalVariables().set("$!", raisedException); RescueBodyNode rescueNode = iVisited.getRescueNode(); while (rescueNode != null) { Node exceptionNodes = rescueNode.getExceptionNodes(); ListNode exceptionNodesList; if (exceptionNodes instanceof SplatNode) { exceptionNodesList = (ListNode) evalInternal(context, exceptionNodes, self); } else { exceptionNodesList = (ListNode) exceptionNodes; } if (isRescueHandled(context, raisedException, exceptionNodesList, self)) { try { return evalInternal(context, rescueNode, self); } catch (JumpException je) { if (je.getJumpType() == JumpException.JumpType.RetryJump) { // should be handled in the finally block below //state.runtime.getGlobalVariables().set("$!", state.runtime.getNil()); //state.threadContext.setRaisedException(null); continue RescuedBlock; } else { throw je; } } } rescueNode = rescueNode.getOptRescueNode(); } // no takers; bubble up throw raiseJump; } finally { // clear exception when handled or retried runtime.getGlobalVariables().set("$!", runtime.getNil()); } } } case NodeTypes.RETRYNODE: { context.pollThreadEvents(); JumpException je = new JumpException(JumpException.JumpType.RetryJump); throw je; } case NodeTypes.RETURNNODE: { ReturnNode iVisited = (ReturnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.ReturnJump); je.setPrimaryData(iVisited.getTarget()); je.setSecondaryData(result); je.setTertiaryData(iVisited); throw je; } case NodeTypes.ROOTNODE: { RootNode iVisited = (RootNode) node; DynamicScope scope = iVisited.getScope(); // Serialization killed our dynamic scope. We can just create an empty one // since serialization cannot serialize an eval (which is the only thing // which is capable of having a non-empty dynamic scope). if (scope == null) { scope = new DynamicScope(iVisited.getStaticScope(), null); } // Each root node has a top-level scope that we need to push context.preRootNode(scope); // FIXME: Wire up BEGIN and END nodes try { return eval(context, iVisited.getBodyNode(), self); } finally { context.postRootNode(); } } case NodeTypes.SCLASSNODE: { SClassNode iVisited = (SClassNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); RubyClass singletonClass; if (receiver.isNil()) { singletonClass = runtime.getNilClass(); } else if (receiver == runtime.getTrue()) { singletonClass = runtime.getClass("TrueClass"); } else if (receiver == runtime.getFalse()) { singletonClass = runtime.getClass("FalseClass"); } else { if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure: can't extend object."); } singletonClass = receiver.getSingletonClass(); } if (context.getWrapper() != null) { singletonClass.extendObject(context.getWrapper()); singletonClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), singletonClass, self); } case NodeTypes.SELFNODE: return self; case NodeTypes.SPLATNODE: { SplatNode iVisited = (SplatNode) node; return splatValue(evalInternal(context, iVisited.getValue(), self)); } //// case NodeTypes.STARNODE: //// EvaluateVisitor.starNodeVisitor.execute(this, node); //// break; case NodeTypes.STRNODE: { StrNode iVisited = (StrNode) node; return runtime.newString(iVisited.getValue()); } case NodeTypes.SUPERNODE: { SuperNode iVisited = (SuperNode) node; if (context.getFrameLastClass() == null) { throw runtime.newNameError("Superclass method '" + context.getFrameLastFunc() + "' disabled."); } context.beginCallArgs(); IRubyObject[] args = null; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return context.callSuper(args); } case NodeTypes.SVALUENODE: { SValueNode iVisited = (SValueNode) node; return aValueSplat(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.SYMBOLNODE: { SymbolNode iVisited = (SymbolNode) node; return runtime.newSymbol(iVisited.getName()); } case NodeTypes.TOARYNODE: { ToAryNode iVisited = (ToAryNode) node; return aryToAry(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.TRUENODE: { context.pollThreadEvents(); return runtime.getTrue(); } case NodeTypes.UNDEFNODE: { UndefNode iVisited = (UndefNode) node; if (context.getRubyClass() == null) { throw runtime .newTypeError("No class to undef method '" + iVisited.getName() + "'."); } context.getRubyClass().undef(iVisited.getName()); return runtime.getNil(); } case NodeTypes.UNTILNODE: { UntilNode iVisited = (UntilNode) node; IRubyObject result = runtime.getNil(); while (!(result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.VALIASNODE: { VAliasNode iVisited = (VAliasNode) node; runtime.getGlobalVariables().alias(iVisited.getNewName(), iVisited.getOldName()); return runtime.getNil(); } case NodeTypes.VCALLNODE: { VCallNode iVisited = (VCallNode) node; return self.callMethod(context, iVisited.getName(), IRubyObject.NULL_ARRAY, CallType.VARIABLE); } case NodeTypes.WHENNODE: assert false; return null; case NodeTypes.WHILENODE: { WhileNode iVisited = (WhileNode) node; IRubyObject result = runtime.getNil(); boolean firstTest = iVisited.evaluateAtStart(); while (!firstTest || (result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { firstTest = true; loop: while (true) { // Used for the 'redo' command try { evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return result; default: throw je; } } } } return result; } case NodeTypes.XSTRNODE: { XStrNode iVisited = (XStrNode) node; return self.callMethod(context, "`", runtime.newString(iVisited.getValue())); } case NodeTypes.YIELDNODE: { YieldNode iVisited = (YieldNode) node; IRubyObject result = evalInternal(context, iVisited.getArgsNode(), self); if (iVisited.getArgsNode() == null) { result = null; } return context.yieldCurrentBlock(result, null, null, iVisited.getCheckState()); } case NodeTypes.ZARRAYNODE: { return runtime.newArray(); } case NodeTypes.ZSUPERNODE: { if (context.getFrameLastClass() == null) { throw runtime.newNameError("superclass method '" + context.getFrameLastFunc() + "' disabled"); } return context.callSuper(context.getFrameArgs()); } } } while (true); }
private static IRubyObject evalInternal(ThreadContext context, Node node, IRubyObject self) { IRuby runtime = context.getRuntime(); bigloop: do { if (node == null) return runtime.getNil(); switch (node.nodeId) { case NodeTypes.ALIASNODE: { AliasNode iVisited = (AliasNode) node; if (context.getRubyClass() == null) { throw runtime.newTypeError("no class to make alias"); } context.getRubyClass().defineAlias(iVisited.getNewName(), iVisited.getOldName()); context.getRubyClass().callMethod(context, "method_added", runtime.newSymbol(iVisited.getNewName())); return runtime.getNil(); } case NodeTypes.ANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.ARGSCATNODE: { ArgsCatNode iVisited = (ArgsCatNode) node; IRubyObject args = evalInternal(context, iVisited.getFirstNode(), self); IRubyObject secondArgs = splatValue(evalInternal(context, iVisited.getSecondNode(), self)); RubyArray list = args instanceof RubyArray ? (RubyArray) args : runtime.newArray(args); return list.concat(secondArgs); } // case NodeTypes.ARGSNODE: // EvaluateVisitor.argsNodeVisitor.execute(this, node); // break; // case NodeTypes.ARGUMENTNODE: // EvaluateVisitor.argumentNodeVisitor.execute(this, node); // break; case NodeTypes.ARRAYNODE: { ArrayNode iVisited = (ArrayNode) node; IRubyObject[] array = new IRubyObject[iVisited.size()]; int i = 0; for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node next = (Node) iterator.next(); array[i++] = evalInternal(context, next, self); } return runtime.newArray(array); } // case NodeTypes.ASSIGNABLENODE: // EvaluateVisitor.assignableNodeVisitor.execute(this, node); // break; case NodeTypes.BACKREFNODE: { BackRefNode iVisited = (BackRefNode) node; IRubyObject backref = context.getBackref(); switch (iVisited.getType()) { case '~': return backref; case '&': return RubyRegexp.last_match(backref); case '`': return RubyRegexp.match_pre(backref); case '\'': return RubyRegexp.match_post(backref); case '+': return RubyRegexp.match_last(backref); } break; } case NodeTypes.BEGINNODE: { BeginNode iVisited = (BeginNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.BIGNUMNODE: { BignumNode iVisited = (BignumNode) node; return RubyBignum.newBignum(runtime, iVisited.getValue()); } // case NodeTypes.BINARYOPERATORNODE: // EvaluateVisitor.binaryOperatorNodeVisitor.execute(this, node); // break; // case NodeTypes.BLOCKARGNODE: // EvaluateVisitor.blockArgNodeVisitor.execute(this, node); // break; case NodeTypes.BLOCKNODE: { BlockNode iVisited = (BlockNode) node; IRubyObject result = runtime.getNil(); for (Iterator iter = iVisited.iterator(); iter.hasNext();) { result = evalInternal(context, (Node) iter.next(), self); } return result; } case NodeTypes.BLOCKPASSNODE: { BlockPassNode iVisited = (BlockPassNode) node; IRubyObject proc = evalInternal(context, iVisited.getBodyNode(), self); if (proc.isNil()) { context.setNoBlock(); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearNoBlock(); } } // If not already a proc then we should try and make it one. if (!(proc instanceof RubyProc)) { proc = proc.convertToType("Proc", "to_proc", false); if (!(proc instanceof RubyProc)) { throw runtime.newTypeError("wrong argument type " + proc.getMetaClass().getName() + " (expected Proc)"); } } // TODO: Add safety check for taintedness Block block = (Block) context.getCurrentBlock(); if (block != null) { IRubyObject blockObject = block.getBlockObject(); // The current block is already associated with the proc. No need to create new // block for it. Just eval! if (blockObject != null && blockObject == proc) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearBlockAvailable(); } } } context.preBlockPassEval(((RubyProc) proc).getBlock()); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.postBlockPassEval(); } } case NodeTypes.BREAKNODE: { BreakNode iVisited = (BreakNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.BreakJump); je.setPrimaryData(result); je.setSecondaryData(node); throw je; } case NodeTypes.CALLNODE: { CallNode iVisited = (CallNode) node; context.beginCallArgs(); IRubyObject receiver = null; IRubyObject[] args = null; try { receiver = evalInternal(context, iVisited.getReceiverNode(), self); args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } assert receiver.getMetaClass() != null : receiver.getClass().getName(); // If reciever is self then we do the call the same way as vcall CallType callType = (receiver == self ? CallType.VARIABLE : CallType.NORMAL); return receiver.callMethod(context, iVisited.getName(), args, callType); } case NodeTypes.CASENODE: { CaseNode iVisited = (CaseNode) node; IRubyObject expression = null; if (iVisited.getCaseNode() != null) { expression = evalInternal(context, iVisited.getCaseNode(), self); } context.pollThreadEvents(); IRubyObject result = runtime.getNil(); Node firstWhenNode = iVisited.getFirstWhenNode(); while (firstWhenNode != null) { if (!(firstWhenNode instanceof WhenNode)) { node = firstWhenNode; continue bigloop; } WhenNode whenNode = (WhenNode) firstWhenNode; if (whenNode.getExpressionNodes() instanceof ArrayNode) { for (Iterator iter = ((ArrayNode) whenNode.getExpressionNodes()).iterator(); iter .hasNext();) { Node tag = (Node) iter.next(); context.setPosition(tag.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // Ruby grammar has nested whens in a case body because of // productions case_body and when_args. if (tag instanceof WhenNode) { RubyArray expressions = (RubyArray) evalInternal(context, ((WhenNode) tag) .getExpressionNodes(), self); for (int j = 0; j < expressions.getLength(); j++) { IRubyObject condition = expressions.entry(j); if ((expression != null && condition.callMethod(context, "===", expression) .isTrue()) || (expression == null && condition.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } continue; } result = evalInternal(context, tag, self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = whenNode.getBodyNode(); continue bigloop; } } } else { result = evalInternal(context, whenNode.getExpressionNodes(), self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } context.pollThreadEvents(); firstWhenNode = whenNode.getNextCase(); } return runtime.getNil(); } case NodeTypes.CLASSNODE: { ClassNode iVisited = (ClassNode) node; Node superNode = iVisited.getSuperNode(); RubyClass superClass = superNode == null ? null : (RubyClass) evalInternal(context, superNode, self); Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingClass = getEnclosingModule(context, classNameNode, self); RubyClass rubyClass = enclosingClass.defineOrGetClassUnder(name, superClass); if (context.getWrapper() != null) { rubyClass.extendObject(context.getWrapper()); rubyClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), rubyClass, self); } case NodeTypes.CLASSVARASGNNODE: { ClassVarAsgnNode iVisited = (ClassVarAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule) rubyClass.getInstanceVariable("__attached__"); } rubyClass.setClassVar(iVisited.getName(), result); return result; } case NodeTypes.CLASSVARDECLNODE: { ClassVarDeclNode iVisited = (ClassVarDeclNode) node; // FIXME: shouldn't we use cref here? if (context.getRubyClass() == null) { throw runtime.newTypeError("no class/module to define class variable"); } IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); ((RubyModule) context.peekCRef().getValue()).setClassVar(iVisited.getName(), result); return runtime.getNil(); } case NodeTypes.CLASSVARNODE: { ClassVarNode iVisited = (ClassVarNode) node; RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule)rubyClass.getInstanceVariable("__attached__"); } return rubyClass.getClassVar(iVisited.getName()); } case NodeTypes.COLON2NODE: { Colon2Node iVisited = (Colon2Node) node; Node leftNode = iVisited.getLeftNode(); // TODO: Made this more colon3 friendly because of cpath production // rule in grammar (it is convenient to think of them as the same thing // at a grammar level even though evaluation is). if (leftNode == null) { return runtime.getObject().getConstantFrom(iVisited.getName()); } else { IRubyObject result = evalInternal(context, iVisited.getLeftNode(), self); if (result instanceof RubyModule) { return ((RubyModule) result).getConstantFrom(iVisited.getName()); } else { return result.callMethod(context, iVisited.getName()); } } } case NodeTypes.COLON3NODE: { Colon3Node iVisited = (Colon3Node) node; return runtime.getObject().getConstantFrom(iVisited.getName()); } case NodeTypes.CONSTDECLNODE: { ConstDeclNode iVisited = (ConstDeclNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); IRubyObject module; if (iVisited.getPathNode() != null) { module = evalInternal(context, iVisited.getPathNode(), self); } else { // FIXME: why do we check RubyClass and then use CRef? if (context.getRubyClass() == null) { // TODO: wire into new exception handling mechanism throw runtime.newTypeError("no class/module to define constant"); } module = (RubyModule) context.peekCRef().getValue(); } // FIXME: shouldn't we use the result of this set in setResult? ((RubyModule) module).setConstant(iVisited.getName(), result); return result; } case NodeTypes.CONSTNODE: { ConstNode iVisited = (ConstNode) node; return context.getConstant(iVisited.getName()); } case NodeTypes.DASGNNODE: { DAsgnNode iVisited = (DAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("DSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.DEFINEDNODE: { DefinedNode iVisited = (DefinedNode) node; String definition = getDefinition(context, iVisited.getExpressionNode(), self); if (definition != null) { return runtime.newString(definition); } else { return runtime.getNil(); } } case NodeTypes.DEFNNODE: { DefnNode iVisited = (DefnNode) node; RubyModule containingClass = context.getRubyClass(); if (containingClass == null) { throw runtime.newTypeError("No class to add method."); } String name = iVisited.getName(); if (containingClass == runtime.getObject() && name.equals("initialize")) { runtime.getWarnings().warn("redefining Object#initialize may cause infinite loop"); } Visibility visibility = context.getCurrentVisibility(); if (name.equals("initialize") || visibility.isModuleFunction()) { visibility = Visibility.PRIVATE; } DefaultMethod newMethod = new DefaultMethod(containingClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), visibility, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } containingClass.addMethod(name, newMethod); if (context.getCurrentVisibility().isModuleFunction()) { containingClass.getSingletonClass().addMethod( name, new WrapperCallable(containingClass.getSingletonClass(), newMethod, Visibility.PUBLIC)); containingClass.callMethod(context, "singleton_method_added", runtime.newSymbol(name)); } // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { ((MetaClass) containingClass).getAttachedObject().callMethod( context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); } else { containingClass.callMethod(context, "method_added", runtime.newSymbol(name)); } return runtime.getNil(); } case NodeTypes.DEFSNODE: { DefsNode iVisited = (DefsNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure; can't define singleton method."); } if (receiver.isFrozen()) { throw runtime.newFrozenError("object"); } if (!receiver.singletonMethodsAllowed()) { throw runtime.newTypeError("can't define singleton method \"" + iVisited.getName() + "\" for " + receiver.getType()); } RubyClass rubyClass = receiver.getSingletonClass(); if (runtime.getSafeLevel() >= 4) { ICallable method = (ICallable) rubyClass.getMethods().get(iVisited.getName()); if (method != null) { throw runtime.newSecurityError("Redefining method prohibited."); } } DefaultMethod newMethod = new DefaultMethod(rubyClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), Visibility.PUBLIC, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } rubyClass.addMethod(iVisited.getName(), newMethod); receiver.callMethod(context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); return runtime.getNil(); } case NodeTypes.DOTNODE: { DotNode iVisited = (DotNode) node; return RubyRange.newRange(runtime, evalInternal(context, iVisited.getBeginNode(), self), evalInternal(context, iVisited .getEndNode(), self), iVisited.isExclusive()); } case NodeTypes.DREGEXPNODE: { DRegexpNode iVisited = (DRegexpNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } String lang = null; int opts = iVisited.getOptions(); if((opts & 16) != 0) { lang = "n"; } else if((opts & 48) != 0) { lang = "s"; } else if((opts & 64) != 0) { lang = "u"; } return RubyRegexp.newRegexp(runtime, sb.toString(), iVisited.getOptions(), lang); } case NodeTypes.DSTRNODE: { DStrNode iVisited = (DStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newString(sb.toString()); } case NodeTypes.DSYMBOLNODE: { DSymbolNode iVisited = (DSymbolNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.getNode().iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newSymbol(sb.toString()); } case NodeTypes.DVARNODE: { DVarNode iVisited = (DVarNode) node; // System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject obj = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); // FIXME: null check is removable once we figure out how to assign to unset named block args return obj == null ? runtime.getNil() : obj; } case NodeTypes.DXSTRNODE: { DXStrNode iVisited = (DXStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return self.callMethod(context, "`", runtime.newString(sb.toString())); } case NodeTypes.ENSURENODE: { EnsureNode iVisited = (EnsureNode) node; // save entering the try if there's nothing to ensure if (iVisited.getEnsureNode() != null) { IRubyObject result = runtime.getNil(); try { result = evalInternal(context, iVisited.getBodyNode(), self); } finally { evalInternal(context, iVisited.getEnsureNode(), self); } return result; } node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.EVSTRNODE: { EvStrNode iVisited = (EvStrNode) node; node = iVisited.getBody(); continue bigloop; } case NodeTypes.FALSENODE: { context.pollThreadEvents(); return runtime.getFalse(); } case NodeTypes.FCALLNODE: { FCallNode iVisited = (FCallNode) node; context.beginCallArgs(); IRubyObject[] args; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return self.callMethod(context, iVisited.getName(), args, CallType.FUNCTIONAL); } case NodeTypes.FIXNUMNODE: { FixnumNode iVisited = (FixnumNode) node; return runtime.newFixnum(iVisited.getValue()); } case NodeTypes.FLIPNODE: { FlipNode iVisited = (FlipNode) node; IRubyObject result = runtime.getNil(); if (iVisited.isExclusive()) { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { result = evalInternal(context, iVisited.getBeginNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } else { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { if (evalInternal(context, iVisited.getBeginNode(), self).isTrue()) { context.getCurrentScope().setValue( iVisited.getIndex(), evalInternal(context, iVisited.getEndNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(), iVisited.getDepth()); return runtime.getTrue(); } else { return runtime.getFalse(); } } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } } case NodeTypes.FLOATNODE: { FloatNode iVisited = (FloatNode) node; return RubyFloat.newFloat(runtime, iVisited.getValue()); } case NodeTypes.FORNODE: { ForNode iVisited = (ForNode) node; // For nodes do not have to create an addition scope so we just pass null context.preForLoopEval(Block.createBlock(iVisited.getVarNode(), null, iVisited.getCallable(), self)); try { while (true) { try { ISourcePosition position = context.getPosition(); context.beginCallArgs(); IRubyObject recv = null; try { recv = evalInternal(context, iVisited.getIterNode(), self); } finally { context.setPosition(position); context.endCallArgs(); } return recv.callMethod(context, "each", IRubyObject.NULL_ARRAY, CallType.NORMAL); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // do nothing, allow loop to retry break; default: throw je; } } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postForLoopEval(); } } case NodeTypes.GLOBALASGNNODE: { GlobalAsgnNode iVisited = (GlobalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); runtime.getGlobalVariables().set(iVisited.getName(), result); return result; } case NodeTypes.GLOBALVARNODE: { GlobalVarNode iVisited = (GlobalVarNode) node; return runtime.getGlobalVariables().get(iVisited.getName()); } case NodeTypes.HASHNODE: { HashNode iVisited = (HashNode) node; Map hash = null; if (iVisited.getListNode() != null) { hash = new HashMap(iVisited.getListNode().size() / 2); for (Iterator iterator = iVisited.getListNode().iterator(); iterator.hasNext();) { // insert all nodes in sequence, hash them in the final instruction // KEY IRubyObject key = evalInternal(context, (Node) iterator.next(), self); IRubyObject value = evalInternal(context, (Node) iterator.next(), self); hash.put(key, value); } } if (hash == null) { return RubyHash.newHash(runtime); } return RubyHash.newHash(runtime, hash, runtime.getNil()); } case NodeTypes.IFNODE: { IfNode iVisited = (IfNode) node; IRubyObject result = evalInternal(context, iVisited.getCondition(), self); if (result.isTrue()) { node = iVisited.getThenBody(); continue bigloop; } else { node = iVisited.getElseBody(); continue bigloop; } } case NodeTypes.INSTASGNNODE: { InstAsgnNode iVisited = (InstAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); self.setInstanceVariable(iVisited.getName(), result); return result; } case NodeTypes.INSTVARNODE: { InstVarNode iVisited = (InstVarNode) node; IRubyObject variable = self.getInstanceVariable(iVisited.getName()); return variable == null ? runtime.getNil() : variable; } // case NodeTypes.ISCOPINGNODE: // EvaluateVisitor.iScopingNodeVisitor.execute(this, node); // break; case NodeTypes.ITERNODE: { IterNode iVisited = (IterNode) node; context.preIterEval(Block.createBlock(iVisited.getVarNode(), new DynamicScope(iVisited.getScope(), context.getCurrentScope()), iVisited.getCallable(), self)); try { while (true) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // allow loop to retry break; default: throw je; } } finally { context.clearBlockAvailable(); } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postIterEval(); } } case NodeTypes.LOCALASGNNODE: { LocalAsgnNode iVisited = (LocalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("LSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.LOCALVARNODE: { LocalVarNode iVisited = (LocalVarNode) node; //System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject result = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); return result == null ? runtime.getNil() : result; } case NodeTypes.MATCH2NODE: { Match2Node iVisited = (Match2Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); return ((RubyRegexp) recv).match(value); } case NodeTypes.MATCH3NODE: { Match3Node iVisited = (Match3Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); if (value instanceof RubyString) { return ((RubyRegexp) recv).match(value); } else { return value.callMethod(context, "=~", recv); } } case NodeTypes.MATCHNODE: { MatchNode iVisited = (MatchNode) node; return ((RubyRegexp) evalInternal(context, iVisited.getRegexpNode(), self)).match2(); } case NodeTypes.MODULENODE: { ModuleNode iVisited = (ModuleNode) node; Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingModule = getEnclosingModule(context, classNameNode, self); if (enclosingModule == null) { throw runtime.newTypeError("no outer class/module"); } RubyModule module; if (enclosingModule == runtime.getObject()) { module = runtime.getOrCreateModule(name); } else { module = enclosingModule.defineModuleUnder(name); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), module, self); } case NodeTypes.MULTIPLEASGNNODE: { MultipleAsgnNode iVisited = (MultipleAsgnNode) node; return AssignmentVisitor.assign(context, self, iVisited, evalInternal(context, iVisited.getValueNode(), self), false); } case NodeTypes.NEWLINENODE: { NewlineNode iVisited = (NewlineNode) node; // something in here is used to build up ruby stack trace... context.setPosition(iVisited.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // TODO: do above but not below for additional newline nodes node = iVisited.getNextNode(); continue bigloop; } case NodeTypes.NEXTNODE: { NextNode iVisited = (NextNode) node; context.pollThreadEvents(); IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.NextJump); je.setPrimaryData(result); je.setSecondaryData(iVisited); //state.setCurrentException(je); throw je; } case NodeTypes.NILNODE: return runtime.getNil(); case NodeTypes.NOTNODE: { NotNode iVisited = (NotNode) node; IRubyObject result = evalInternal(context, iVisited.getConditionNode(), self); return result.isTrue() ? runtime.getFalse() : runtime.getTrue(); } case NodeTypes.NTHREFNODE: { NthRefNode iVisited = (NthRefNode) node; return RubyRegexp.nth_match(iVisited.getMatchNumber(), context.getBackref()); } case NodeTypes.OPASGNANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; // add in reverse order IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.OPASGNNODE: { OpAsgnNode iVisited = (OpAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = receiver.callMethod(context, iVisited.getVariableName()); if (iVisited.getOperatorName().equals("||")) { if (value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else { value = value.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited.getValueNode(), self)); } receiver.callMethod(context, iVisited.getVariableName() + "=", value); context.pollThreadEvents(); return value; } case NodeTypes.OPASGNORNODE: { OpAsgnOrNode iVisited = (OpAsgnOrNode) node; String def = getDefinition(context, iVisited.getFirstNode(), self); IRubyObject result = runtime.getNil(); if (def != null) { result = evalInternal(context, iVisited.getFirstNode(), self); } if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } case NodeTypes.OPELEMENTASGNNODE: { OpElementAsgnNode iVisited = (OpElementAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject[] args = setupArgs(context, iVisited.getArgsNode(), self); IRubyObject firstValue = receiver.callMethod(context, "[]", args); if (iVisited.getOperatorName().equals("||")) { if (firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else { firstValue = firstValue.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited .getValueNode(), self)); } IRubyObject[] expandedArgs = new IRubyObject[args.length + 1]; System.arraycopy(args, 0, expandedArgs, 0, args.length); expandedArgs[expandedArgs.length - 1] = firstValue; return receiver.callMethod(context, "[]=", expandedArgs); } case NodeTypes.OPTNNODE: { OptNNode iVisited = (OptNNode) node; IRubyObject result = runtime.getNil(); while (RubyKernel.gets(runtime.getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: // do nothing, this iteration restarts break; case JumpType.NEXT: // recheck condition break loop; case JumpType.BREAK: // end loop return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.ORNODE: { OrNode iVisited = (OrNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } // case NodeTypes.POSTEXENODE: // EvaluateVisitor.postExeNodeVisitor.execute(this, node); // break; case NodeTypes.REDONODE: { context.pollThreadEvents(); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.RedoJump); je.setSecondaryData(node); throw je; } case NodeTypes.REGEXPNODE: { RegexpNode iVisited = (RegexpNode) node; // FIXME: don't pass null return RubyRegexp.newRegexp(runtime, iVisited.getPattern(), null); } case NodeTypes.RESCUEBODYNODE: { RescueBodyNode iVisited = (RescueBodyNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.RESCUENODE: { RescueNode iVisited = (RescueNode)node; RescuedBlock : while (true) { try { // Execute rescue block IRubyObject result = evalInternal(context, iVisited.getBodyNode(), self); // If no exception is thrown execute else block if (iVisited.getElseNode() != null) { if (iVisited.getRescueNode() == null) { runtime.getWarnings().warn(iVisited.getElseNode().getPosition(), "else without rescue is useless"); } result = evalInternal(context, iVisited.getElseNode(), self); } return result; } catch (RaiseException raiseJump) { RubyException raisedException = raiseJump.getException(); // TODO: Rubicon TestKernel dies without this line. A cursory glance implies we // falsely set $! to nil and this sets it back to something valid. This should // get fixed at the same time we address bug #1296484. runtime.getGlobalVariables().set("$!", raisedException); RescueBodyNode rescueNode = iVisited.getRescueNode(); while (rescueNode != null) { Node exceptionNodes = rescueNode.getExceptionNodes(); ListNode exceptionNodesList; if (exceptionNodes instanceof SplatNode) { exceptionNodesList = (ListNode) evalInternal(context, exceptionNodes, self); } else { exceptionNodesList = (ListNode) exceptionNodes; } if (isRescueHandled(context, raisedException, exceptionNodesList, self)) { try { return evalInternal(context, rescueNode, self); } catch (JumpException je) { if (je.getJumpType() == JumpException.JumpType.RetryJump) { // should be handled in the finally block below //state.runtime.getGlobalVariables().set("$!", state.runtime.getNil()); //state.threadContext.setRaisedException(null); continue RescuedBlock; } else { throw je; } } } rescueNode = rescueNode.getOptRescueNode(); } // no takers; bubble up throw raiseJump; } finally { // clear exception when handled or retried runtime.getGlobalVariables().set("$!", runtime.getNil()); } } } case NodeTypes.RETRYNODE: { context.pollThreadEvents(); JumpException je = new JumpException(JumpException.JumpType.RetryJump); throw je; } case NodeTypes.RETURNNODE: { ReturnNode iVisited = (ReturnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.ReturnJump); je.setPrimaryData(iVisited.getTarget()); je.setSecondaryData(result); je.setTertiaryData(iVisited); throw je; } case NodeTypes.ROOTNODE: { RootNode iVisited = (RootNode) node; DynamicScope scope = iVisited.getScope(); // Serialization killed our dynamic scope. We can just create an empty one // since serialization cannot serialize an eval (which is the only thing // which is capable of having a non-empty dynamic scope). if (scope == null) { scope = new DynamicScope(iVisited.getStaticScope(), null); } // Each root node has a top-level scope that we need to push context.preRootNode(scope); // FIXME: Wire up BEGIN and END nodes try { return eval(context, iVisited.getBodyNode(), self); } finally { context.postRootNode(); } } case NodeTypes.SCLASSNODE: { SClassNode iVisited = (SClassNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); RubyClass singletonClass; if (receiver.isNil()) { singletonClass = runtime.getNilClass(); } else if (receiver == runtime.getTrue()) { singletonClass = runtime.getClass("TrueClass"); } else if (receiver == runtime.getFalse()) { singletonClass = runtime.getClass("FalseClass"); } else { if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure: can't extend object."); } singletonClass = receiver.getSingletonClass(); } if (context.getWrapper() != null) { singletonClass.extendObject(context.getWrapper()); singletonClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), singletonClass, self); } case NodeTypes.SELFNODE: return self; case NodeTypes.SPLATNODE: { SplatNode iVisited = (SplatNode) node; return splatValue(evalInternal(context, iVisited.getValue(), self)); } //// case NodeTypes.STARNODE: //// EvaluateVisitor.starNodeVisitor.execute(this, node); //// break; case NodeTypes.STRNODE: { StrNode iVisited = (StrNode) node; return runtime.newString(iVisited.getValue()); } case NodeTypes.SUPERNODE: { SuperNode iVisited = (SuperNode) node; if (context.getFrameLastClass() == null) { throw runtime.newNameError("Superclass method '" + context.getFrameLastFunc() + "' disabled."); } context.beginCallArgs(); IRubyObject[] args = null; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return context.callSuper(args); } case NodeTypes.SVALUENODE: { SValueNode iVisited = (SValueNode) node; return aValueSplat(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.SYMBOLNODE: { SymbolNode iVisited = (SymbolNode) node; return runtime.newSymbol(iVisited.getName()); } case NodeTypes.TOARYNODE: { ToAryNode iVisited = (ToAryNode) node; return aryToAry(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.TRUENODE: { context.pollThreadEvents(); return runtime.getTrue(); } case NodeTypes.UNDEFNODE: { UndefNode iVisited = (UndefNode) node; if (context.getRubyClass() == null) { throw runtime .newTypeError("No class to undef method '" + iVisited.getName() + "'."); } context.getRubyClass().undef(iVisited.getName()); return runtime.getNil(); } case NodeTypes.UNTILNODE: { UntilNode iVisited = (UntilNode) node; IRubyObject result = runtime.getNil(); while (!(result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.VALIASNODE: { VAliasNode iVisited = (VAliasNode) node; runtime.getGlobalVariables().alias(iVisited.getNewName(), iVisited.getOldName()); return runtime.getNil(); } case NodeTypes.VCALLNODE: { VCallNode iVisited = (VCallNode) node; return self.callMethod(context, iVisited.getName(), IRubyObject.NULL_ARRAY, CallType.VARIABLE); } case NodeTypes.WHENNODE: assert false; return null; case NodeTypes.WHILENODE: { WhileNode iVisited = (WhileNode) node; IRubyObject result = runtime.getNil(); boolean firstTest = iVisited.evaluateAtStart(); while (!firstTest || (result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { firstTest = true; loop: while (true) { // Used for the 'redo' command try { evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return result; default: throw je; } } } } return result; } case NodeTypes.XSTRNODE: { XStrNode iVisited = (XStrNode) node; return self.callMethod(context, "`", runtime.newString(iVisited.getValue())); } case NodeTypes.YIELDNODE: { YieldNode iVisited = (YieldNode) node; IRubyObject result = evalInternal(context, iVisited.getArgsNode(), self); if (iVisited.getArgsNode() == null) { result = null; } return context.yieldCurrentBlock(result, null, null, iVisited.getCheckState()); } case NodeTypes.ZARRAYNODE: { return runtime.newArray(); } case NodeTypes.ZSUPERNODE: { if (context.getFrameLastClass() == null) { throw runtime.newNameError("superclass method '" + context.getFrameLastFunc() + "' disabled"); } return context.callSuper(context.getFrameArgs()); } } } while (true); }
3,229,969
private static IRubyObject evalInternal(ThreadContext context, Node node, IRubyObject self) { IRuby runtime = context.getRuntime(); bigloop: do { if (node == null) return runtime.getNil(); switch (node.nodeId) { case NodeTypes.ALIASNODE: { AliasNode iVisited = (AliasNode) node; if (context.getRubyClass() == null) { throw runtime.newTypeError("no class to make alias"); } context.getRubyClass().defineAlias(iVisited.getNewName(), iVisited.getOldName()); context.getRubyClass().callMethod(context, "method_added", runtime.newSymbol(iVisited.getNewName())); return runtime.getNil(); } case NodeTypes.ANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.ARGSCATNODE: { ArgsCatNode iVisited = (ArgsCatNode) node; IRubyObject args = evalInternal(context, iVisited.getFirstNode(), self); IRubyObject secondArgs = splatValue(evalInternal(context, iVisited.getSecondNode(), self)); RubyArray list = args instanceof RubyArray ? (RubyArray) args : runtime.newArray(args); return list.concat(secondArgs); } // case NodeTypes.ARGSNODE: // EvaluateVisitor.argsNodeVisitor.execute(this, node); // break; // case NodeTypes.ARGUMENTNODE: // EvaluateVisitor.argumentNodeVisitor.execute(this, node); // break; case NodeTypes.ARRAYNODE: { ArrayNode iVisited = (ArrayNode) node; IRubyObject[] array = new IRubyObject[iVisited.size()]; int i = 0; for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node next = (Node) iterator.next(); array[i++] = evalInternal(context, next, self); } return runtime.newArray(array); } // case NodeTypes.ASSIGNABLENODE: // EvaluateVisitor.assignableNodeVisitor.execute(this, node); // break; case NodeTypes.BACKREFNODE: { BackRefNode iVisited = (BackRefNode) node; IRubyObject backref = context.getBackref(); switch (iVisited.getType()) { case '~': return backref; case '&': return RubyRegexp.last_match(backref); case '`': return RubyRegexp.match_pre(backref); case '\'': return RubyRegexp.match_post(backref); case '+': return RubyRegexp.match_last(backref); } break; } case NodeTypes.BEGINNODE: { BeginNode iVisited = (BeginNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.BIGNUMNODE: { BignumNode iVisited = (BignumNode) node; return RubyBignum.newBignum(runtime, iVisited.getValue()); } // case NodeTypes.BINARYOPERATORNODE: // EvaluateVisitor.binaryOperatorNodeVisitor.execute(this, node); // break; // case NodeTypes.BLOCKARGNODE: // EvaluateVisitor.blockArgNodeVisitor.execute(this, node); // break; case NodeTypes.BLOCKNODE: { BlockNode iVisited = (BlockNode) node; IRubyObject result = runtime.getNil(); for (Iterator iter = iVisited.iterator(); iter.hasNext();) { result = evalInternal(context, (Node) iter.next(), self); } return result; } case NodeTypes.BLOCKPASSNODE: { BlockPassNode iVisited = (BlockPassNode) node; IRubyObject proc = evalInternal(context, iVisited.getBodyNode(), self); if (proc.isNil()) { context.setNoBlock(); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearNoBlock(); } } // If not already a proc then we should try and make it one. if (!(proc instanceof RubyProc)) { proc = proc.convertToType("Proc", "to_proc", false); if (!(proc instanceof RubyProc)) { throw runtime.newTypeError("wrong argument type " + proc.getMetaClass().getName() + " (expected Proc)"); } } // TODO: Add safety check for taintedness Block block = (Block) context.getCurrentBlock(); if (block != null) { IRubyObject blockObject = block.getBlockObject(); // The current block is already associated with the proc. No need to create new // block for it. Just eval! if (blockObject != null && blockObject == proc) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearBlockAvailable(); } } } context.preBlockPassEval(((RubyProc) proc).getBlock()); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.postBlockPassEval(); } } case NodeTypes.BREAKNODE: { BreakNode iVisited = (BreakNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.BreakJump); je.setPrimaryData(result); je.setSecondaryData(node); throw je; } case NodeTypes.CALLNODE: { CallNode iVisited = (CallNode) node; context.beginCallArgs(); IRubyObject receiver = null; IRubyObject[] args = null; try { receiver = evalInternal(context, iVisited.getReceiverNode(), self); args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } assert receiver.getMetaClass() != null : receiver.getClass().getName(); // If reciever is self then we do the call the same way as vcall CallType callType = (receiver == self ? CallType.VARIABLE : CallType.NORMAL); return receiver.callMethod(context, iVisited.getName(), args, callType); } case NodeTypes.CASENODE: { CaseNode iVisited = (CaseNode) node; IRubyObject expression = null; if (iVisited.getCaseNode() != null) { expression = evalInternal(context, iVisited.getCaseNode(), self); } context.pollThreadEvents(); IRubyObject result = runtime.getNil(); Node firstWhenNode = iVisited.getFirstWhenNode(); while (firstWhenNode != null) { if (!(firstWhenNode instanceof WhenNode)) { node = firstWhenNode; continue bigloop; } WhenNode whenNode = (WhenNode) firstWhenNode; if (whenNode.getExpressionNodes() instanceof ArrayNode) { for (Iterator iter = ((ArrayNode) whenNode.getExpressionNodes()).iterator(); iter .hasNext();) { Node tag = (Node) iter.next(); context.setPosition(tag.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // Ruby grammar has nested whens in a case body because of // productions case_body and when_args. if (tag instanceof WhenNode) { RubyArray expressions = (RubyArray) evalInternal(context, ((WhenNode) tag) .getExpressionNodes(), self); for (int j = 0; j < expressions.getLength(); j++) { IRubyObject condition = expressions.entry(j); if ((expression != null && condition.callMethod(context, "===", expression) .isTrue()) || (expression == null && condition.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } continue; } result = evalInternal(context, tag, self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = whenNode.getBodyNode(); continue bigloop; } } } else { result = evalInternal(context, whenNode.getExpressionNodes(), self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } context.pollThreadEvents(); firstWhenNode = whenNode.getNextCase(); } return runtime.getNil(); } case NodeTypes.CLASSNODE: { ClassNode iVisited = (ClassNode) node; Node superNode = iVisited.getSuperNode(); RubyClass superClass = superNode == null ? null : (RubyClass) evalInternal(context, superNode, self); Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingClass = getEnclosingModule(context, classNameNode, self); RubyClass rubyClass = enclosingClass.defineOrGetClassUnder(name, superClass); if (context.getWrapper() != null) { rubyClass.extendObject(context.getWrapper()); rubyClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), rubyClass, self); } case NodeTypes.CLASSVARASGNNODE: { ClassVarAsgnNode iVisited = (ClassVarAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule) rubyClass.getInstanceVariable("__attached__"); } rubyClass.setClassVar(iVisited.getName(), result); return result; } case NodeTypes.CLASSVARDECLNODE: { ClassVarDeclNode iVisited = (ClassVarDeclNode) node; // FIXME: shouldn't we use cref here? if (context.getRubyClass() == null) { throw runtime.newTypeError("no class/module to define class variable"); } IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); ((RubyModule) context.peekCRef().getValue()).setClassVar(iVisited.getName(), result); return runtime.getNil(); } case NodeTypes.CLASSVARNODE: { ClassVarNode iVisited = (ClassVarNode) node; RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule)rubyClass.getInstanceVariable("__attached__"); } return rubyClass.getClassVar(iVisited.getName()); } case NodeTypes.COLON2NODE: { Colon2Node iVisited = (Colon2Node) node; Node leftNode = iVisited.getLeftNode(); // TODO: Made this more colon3 friendly because of cpath production // rule in grammar (it is convenient to think of them as the same thing // at a grammar level even though evaluation is). if (leftNode == null) { return runtime.getObject().getConstantFrom(iVisited.getName()); } else { IRubyObject result = evalInternal(context, iVisited.getLeftNode(), self); if (result instanceof RubyModule) { return ((RubyModule) result).getConstantFrom(iVisited.getName()); } else { return result.callMethod(context, iVisited.getName()); } } } case NodeTypes.COLON3NODE: { Colon3Node iVisited = (Colon3Node) node; return runtime.getObject().getConstantFrom(iVisited.getName()); } case NodeTypes.CONSTDECLNODE: { ConstDeclNode iVisited = (ConstDeclNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); IRubyObject module; if (iVisited.getPathNode() != null) { module = evalInternal(context, iVisited.getPathNode(), self); } else { // FIXME: why do we check RubyClass and then use CRef? if (context.getRubyClass() == null) { // TODO: wire into new exception handling mechanism throw runtime.newTypeError("no class/module to define constant"); } module = (RubyModule) context.peekCRef().getValue(); } // FIXME: shouldn't we use the result of this set in setResult? ((RubyModule) module).setConstant(iVisited.getName(), result); return result; } case NodeTypes.CONSTNODE: { ConstNode iVisited = (ConstNode) node; return context.getConstant(iVisited.getName()); } case NodeTypes.DASGNNODE: { DAsgnNode iVisited = (DAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("DSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.DEFINEDNODE: { DefinedNode iVisited = (DefinedNode) node; String definition = getDefinition(context, iVisited.getExpressionNode(), self); if (definition != null) { return runtime.newString(definition); } else { return runtime.getNil(); } } case NodeTypes.DEFNNODE: { DefnNode iVisited = (DefnNode) node; RubyModule containingClass = context.getRubyClass(); if (containingClass == null) { throw runtime.newTypeError("No class to add method."); } String name = iVisited.getName(); if (containingClass == runtime.getObject() && name.equals("initialize")) { runtime.getWarnings().warn("redefining Object#initialize may cause infinite loop"); } Visibility visibility = context.getCurrentVisibility(); if (name.equals("initialize") || visibility.isModuleFunction()) { visibility = Visibility.PRIVATE; } DefaultMethod newMethod = new DefaultMethod(containingClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), visibility, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } containingClass.addMethod(name, newMethod); if (context.getCurrentVisibility().isModuleFunction()) { containingClass.getSingletonClass().addMethod( name, new WrapperCallable(containingClass.getSingletonClass(), newMethod, Visibility.PUBLIC)); containingClass.callMethod(context, "singleton_method_added", runtime.newSymbol(name)); } // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { ((MetaClass) containingClass).getAttachedObject().callMethod( context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); } else { containingClass.callMethod(context, "method_added", runtime.newSymbol(name)); } return runtime.getNil(); } case NodeTypes.DEFSNODE: { DefsNode iVisited = (DefsNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure; can't define singleton method."); } if (receiver.isFrozen()) { throw runtime.newFrozenError("object"); } if (!receiver.singletonMethodsAllowed()) { throw runtime.newTypeError("can't define singleton method \"" + iVisited.getName() + "\" for " + receiver.getType()); } RubyClass rubyClass = receiver.getSingletonClass(); if (runtime.getSafeLevel() >= 4) { ICallable method = (ICallable) rubyClass.getMethods().get(iVisited.getName()); if (method != null) { throw runtime.newSecurityError("Redefining method prohibited."); } } DefaultMethod newMethod = new DefaultMethod(rubyClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), Visibility.PUBLIC, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } rubyClass.addMethod(iVisited.getName(), newMethod); receiver.callMethod(context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); return runtime.getNil(); } case NodeTypes.DOTNODE: { DotNode iVisited = (DotNode) node; return RubyRange.newRange(runtime, evalInternal(context, iVisited.getBeginNode(), self), evalInternal(context, iVisited .getEndNode(), self), iVisited.isExclusive()); } case NodeTypes.DREGEXPNODE: { DRegexpNode iVisited = (DRegexpNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return RubyRegexp.newRegexp(runtime, sb.toString(), iVisited.getOptions(), null); } case NodeTypes.DSTRNODE: { DStrNode iVisited = (DStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newString(sb.toString()); } case NodeTypes.DSYMBOLNODE: { DSymbolNode iVisited = (DSymbolNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.getNode().iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newSymbol(sb.toString()); } case NodeTypes.DVARNODE: { DVarNode iVisited = (DVarNode) node; // System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject obj = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); // FIXME: null check is removable once we figure out how to assign to unset named block args return obj == null ? runtime.getNil() : obj; } case NodeTypes.DXSTRNODE: { DXStrNode iVisited = (DXStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return self.callMethod(context, "`", runtime.newString(sb.toString())); } case NodeTypes.ENSURENODE: { EnsureNode iVisited = (EnsureNode) node; // save entering the try if there's nothing to ensure if (iVisited.getEnsureNode() != null) { IRubyObject result = runtime.getNil(); try { result = evalInternal(context, iVisited.getBodyNode(), self); } finally { evalInternal(context, iVisited.getEnsureNode(), self); } return result; } node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.EVSTRNODE: { EvStrNode iVisited = (EvStrNode) node; node = iVisited.getBody(); continue bigloop; } case NodeTypes.FALSENODE: { context.pollThreadEvents(); return runtime.getFalse(); } case NodeTypes.FCALLNODE: { FCallNode iVisited = (FCallNode) node; context.beginCallArgs(); IRubyObject[] args; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return self.callMethod(context, iVisited.getName(), args, CallType.FUNCTIONAL); } case NodeTypes.FIXNUMNODE: { FixnumNode iVisited = (FixnumNode) node; return runtime.newFixnum(iVisited.getValue()); } case NodeTypes.FLIPNODE: { FlipNode iVisited = (FlipNode) node; IRubyObject result = runtime.getNil(); if (iVisited.isExclusive()) { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { result = evalInternal(context, iVisited.getBeginNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } else { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { if (evalInternal(context, iVisited.getBeginNode(), self).isTrue()) { context.getCurrentScope().setValue( iVisited.getIndex(), evalInternal(context, iVisited.getEndNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(), iVisited.getDepth()); return runtime.getTrue(); } else { return runtime.getFalse(); } } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } } case NodeTypes.FLOATNODE: { FloatNode iVisited = (FloatNode) node; return RubyFloat.newFloat(runtime, iVisited.getValue()); } case NodeTypes.FORNODE: { ForNode iVisited = (ForNode) node; // For nodes do not have to create an addition scope so we just pass null context.preForLoopEval(Block.createBlock(iVisited.getVarNode(), null, iVisited.getCallable(), self)); try { while (true) { try { ISourcePosition position = context.getPosition(); context.beginCallArgs(); IRubyObject recv = null; try { recv = evalInternal(context, iVisited.getIterNode(), self); } finally { context.setPosition(position); context.endCallArgs(); } return recv.callMethod(context, "each", IRubyObject.NULL_ARRAY, CallType.NORMAL); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // do nothing, allow loop to retry break; default: throw je; } } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postForLoopEval(); } } case NodeTypes.GLOBALASGNNODE: { GlobalAsgnNode iVisited = (GlobalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); runtime.getGlobalVariables().set(iVisited.getName(), result); return result; } case NodeTypes.GLOBALVARNODE: { GlobalVarNode iVisited = (GlobalVarNode) node; return runtime.getGlobalVariables().get(iVisited.getName()); } case NodeTypes.HASHNODE: { HashNode iVisited = (HashNode) node; Map hash = null; if (iVisited.getListNode() != null) { hash = new HashMap(iVisited.getListNode().size() / 2); for (Iterator iterator = iVisited.getListNode().iterator(); iterator.hasNext();) { // insert all nodes in sequence, hash them in the final instruction // KEY IRubyObject key = evalInternal(context, (Node) iterator.next(), self); IRubyObject value = evalInternal(context, (Node) iterator.next(), self); hash.put(key, value); } } if (hash == null) { return RubyHash.newHash(runtime); } return RubyHash.newHash(runtime, hash, runtime.getNil()); } case NodeTypes.IFNODE: { IfNode iVisited = (IfNode) node; IRubyObject result = evalInternal(context, iVisited.getCondition(), self); if (result.isTrue()) { node = iVisited.getThenBody(); continue bigloop; } else { node = iVisited.getElseBody(); continue bigloop; } } case NodeTypes.INSTASGNNODE: { InstAsgnNode iVisited = (InstAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); self.setInstanceVariable(iVisited.getName(), result); return result; } case NodeTypes.INSTVARNODE: { InstVarNode iVisited = (InstVarNode) node; IRubyObject variable = self.getInstanceVariable(iVisited.getName()); return variable == null ? runtime.getNil() : variable; } // case NodeTypes.ISCOPINGNODE: // EvaluateVisitor.iScopingNodeVisitor.execute(this, node); // break; case NodeTypes.ITERNODE: { IterNode iVisited = (IterNode) node; context.preIterEval(Block.createBlock(iVisited.getVarNode(), new DynamicScope(iVisited.getScope(), context.getCurrentScope()), iVisited.getCallable(), self)); try { while (true) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // allow loop to retry break; default: throw je; } } finally { context.clearBlockAvailable(); } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postIterEval(); } } case NodeTypes.LOCALASGNNODE: { LocalAsgnNode iVisited = (LocalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("LSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.LOCALVARNODE: { LocalVarNode iVisited = (LocalVarNode) node; //System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject result = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); return result == null ? runtime.getNil() : result; } case NodeTypes.MATCH2NODE: { Match2Node iVisited = (Match2Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); return ((RubyRegexp) recv).match(value); } case NodeTypes.MATCH3NODE: { Match3Node iVisited = (Match3Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); if (value instanceof RubyString) { return ((RubyRegexp) recv).match(value); } else { return value.callMethod(context, "=~", recv); } } case NodeTypes.MATCHNODE: { MatchNode iVisited = (MatchNode) node; return ((RubyRegexp) evalInternal(context, iVisited.getRegexpNode(), self)).match2(); } case NodeTypes.MODULENODE: { ModuleNode iVisited = (ModuleNode) node; Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingModule = getEnclosingModule(context, classNameNode, self); if (enclosingModule == null) { throw runtime.newTypeError("no outer class/module"); } RubyModule module; if (enclosingModule == runtime.getObject()) { module = runtime.getOrCreateModule(name); } else { module = enclosingModule.defineModuleUnder(name); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), module, self); } case NodeTypes.MULTIPLEASGNNODE: { MultipleAsgnNode iVisited = (MultipleAsgnNode) node; return AssignmentVisitor.assign(context, self, iVisited, evalInternal(context, iVisited.getValueNode(), self), false); } case NodeTypes.NEWLINENODE: { NewlineNode iVisited = (NewlineNode) node; // something in here is used to build up ruby stack trace... context.setPosition(iVisited.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // TODO: do above but not below for additional newline nodes node = iVisited.getNextNode(); continue bigloop; } case NodeTypes.NEXTNODE: { NextNode iVisited = (NextNode) node; context.pollThreadEvents(); IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.NextJump); je.setPrimaryData(result); je.setSecondaryData(iVisited); //state.setCurrentException(je); throw je; } case NodeTypes.NILNODE: return runtime.getNil(); case NodeTypes.NOTNODE: { NotNode iVisited = (NotNode) node; IRubyObject result = evalInternal(context, iVisited.getConditionNode(), self); return result.isTrue() ? runtime.getFalse() : runtime.getTrue(); } case NodeTypes.NTHREFNODE: { NthRefNode iVisited = (NthRefNode) node; return RubyRegexp.nth_match(iVisited.getMatchNumber(), context.getBackref()); } case NodeTypes.OPASGNANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; // add in reverse order IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.OPASGNNODE: { OpAsgnNode iVisited = (OpAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = receiver.callMethod(context, iVisited.getVariableName()); if (iVisited.getOperatorName().equals("||")) { if (value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else { value = value.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited.getValueNode(), self)); } receiver.callMethod(context, iVisited.getVariableName() + "=", value); context.pollThreadEvents(); return value; } case NodeTypes.OPASGNORNODE: { OpAsgnOrNode iVisited = (OpAsgnOrNode) node; String def = getDefinition(context, iVisited.getFirstNode(), self); IRubyObject result = runtime.getNil(); if (def != null) { result = evalInternal(context, iVisited.getFirstNode(), self); } if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } case NodeTypes.OPELEMENTASGNNODE: { OpElementAsgnNode iVisited = (OpElementAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject[] args = setupArgs(context, iVisited.getArgsNode(), self); IRubyObject firstValue = receiver.callMethod(context, "[]", args); if (iVisited.getOperatorName().equals("||")) { if (firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else { firstValue = firstValue.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited .getValueNode(), self)); } IRubyObject[] expandedArgs = new IRubyObject[args.length + 1]; System.arraycopy(args, 0, expandedArgs, 0, args.length); expandedArgs[expandedArgs.length - 1] = firstValue; return receiver.callMethod(context, "[]=", expandedArgs); } case NodeTypes.OPTNNODE: { OptNNode iVisited = (OptNNode) node; IRubyObject result = runtime.getNil(); while (RubyKernel.gets(runtime.getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: // do nothing, this iteration restarts break; case JumpType.NEXT: // recheck condition break loop; case JumpType.BREAK: // end loop return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.ORNODE: { OrNode iVisited = (OrNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } // case NodeTypes.POSTEXENODE: // EvaluateVisitor.postExeNodeVisitor.execute(this, node); // break; case NodeTypes.REDONODE: { context.pollThreadEvents(); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.RedoJump); je.setSecondaryData(node); throw je; } case NodeTypes.REGEXPNODE: { RegexpNode iVisited = (RegexpNode) node; // FIXME: don't pass null return RubyRegexp.newRegexp(runtime, iVisited.getPattern(), null); } case NodeTypes.RESCUEBODYNODE: { RescueBodyNode iVisited = (RescueBodyNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.RESCUENODE: { RescueNode iVisited = (RescueNode)node; RescuedBlock : while (true) { try { // Execute rescue block IRubyObject result = evalInternal(context, iVisited.getBodyNode(), self); // If no exception is thrown execute else block if (iVisited.getElseNode() != null) { if (iVisited.getRescueNode() == null) { runtime.getWarnings().warn(iVisited.getElseNode().getPosition(), "else without rescue is useless"); } result = evalInternal(context, iVisited.getElseNode(), self); } return result; } catch (RaiseException raiseJump) { RubyException raisedException = raiseJump.getException(); // TODO: Rubicon TestKernel dies without this line. A cursory glance implies we // falsely set $! to nil and this sets it back to something valid. This should // get fixed at the same time we address bug #1296484. runtime.getGlobalVariables().set("$!", raisedException); RescueBodyNode rescueNode = iVisited.getRescueNode(); while (rescueNode != null) { Node exceptionNodes = rescueNode.getExceptionNodes(); ListNode exceptionNodesList; if (exceptionNodes instanceof SplatNode) { exceptionNodesList = (ListNode) evalInternal(context, exceptionNodes, self); } else { exceptionNodesList = (ListNode) exceptionNodes; } if (isRescueHandled(context, raisedException, exceptionNodesList, self)) { try { return evalInternal(context, rescueNode, self); } catch (JumpException je) { if (je.getJumpType() == JumpException.JumpType.RetryJump) { // should be handled in the finally block below //state.runtime.getGlobalVariables().set("$!", state.runtime.getNil()); //state.threadContext.setRaisedException(null); continue RescuedBlock; } else { throw je; } } } rescueNode = rescueNode.getOptRescueNode(); } // no takers; bubble up throw raiseJump; } finally { // clear exception when handled or retried runtime.getGlobalVariables().set("$!", runtime.getNil()); } } } case NodeTypes.RETRYNODE: { context.pollThreadEvents(); JumpException je = new JumpException(JumpException.JumpType.RetryJump); throw je; } case NodeTypes.RETURNNODE: { ReturnNode iVisited = (ReturnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.ReturnJump); je.setPrimaryData(iVisited.getTarget()); je.setSecondaryData(result); je.setTertiaryData(iVisited); throw je; } case NodeTypes.ROOTNODE: { RootNode iVisited = (RootNode) node; DynamicScope scope = iVisited.getScope(); // Serialization killed our dynamic scope. We can just create an empty one // since serialization cannot serialize an eval (which is the only thing // which is capable of having a non-empty dynamic scope). if (scope == null) { scope = new DynamicScope(iVisited.getStaticScope(), null); } // Each root node has a top-level scope that we need to push context.preRootNode(scope); // FIXME: Wire up BEGIN and END nodes try { return eval(context, iVisited.getBodyNode(), self); } finally { context.postRootNode(); } } case NodeTypes.SCLASSNODE: { SClassNode iVisited = (SClassNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); RubyClass singletonClass; if (receiver.isNil()) { singletonClass = runtime.getNilClass(); } else if (receiver == runtime.getTrue()) { singletonClass = runtime.getClass("TrueClass"); } else if (receiver == runtime.getFalse()) { singletonClass = runtime.getClass("FalseClass"); } else { if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure: can't extend object."); } singletonClass = receiver.getSingletonClass(); } if (context.getWrapper() != null) { singletonClass.extendObject(context.getWrapper()); singletonClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), singletonClass, self); } case NodeTypes.SELFNODE: return self; case NodeTypes.SPLATNODE: { SplatNode iVisited = (SplatNode) node; return splatValue(evalInternal(context, iVisited.getValue(), self)); } //// case NodeTypes.STARNODE: //// EvaluateVisitor.starNodeVisitor.execute(this, node); //// break; case NodeTypes.STRNODE: { StrNode iVisited = (StrNode) node; return runtime.newString(iVisited.getValue()); } case NodeTypes.SUPERNODE: { SuperNode iVisited = (SuperNode) node; if (context.getFrameLastClass() == null) { throw runtime.newNameError("Superclass method '" + context.getFrameLastFunc() + "' disabled."); } context.beginCallArgs(); IRubyObject[] args = null; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return context.callSuper(args); } case NodeTypes.SVALUENODE: { SValueNode iVisited = (SValueNode) node; return aValueSplat(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.SYMBOLNODE: { SymbolNode iVisited = (SymbolNode) node; return runtime.newSymbol(iVisited.getName()); } case NodeTypes.TOARYNODE: { ToAryNode iVisited = (ToAryNode) node; return aryToAry(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.TRUENODE: { context.pollThreadEvents(); return runtime.getTrue(); } case NodeTypes.UNDEFNODE: { UndefNode iVisited = (UndefNode) node; if (context.getRubyClass() == null) { throw runtime .newTypeError("No class to undef method '" + iVisited.getName() + "'."); } context.getRubyClass().undef(iVisited.getName()); return runtime.getNil(); } case NodeTypes.UNTILNODE: { UntilNode iVisited = (UntilNode) node; IRubyObject result = runtime.getNil(); while (!(result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.VALIASNODE: { VAliasNode iVisited = (VAliasNode) node; runtime.getGlobalVariables().alias(iVisited.getNewName(), iVisited.getOldName()); return runtime.getNil(); } case NodeTypes.VCALLNODE: { VCallNode iVisited = (VCallNode) node; return self.callMethod(context, iVisited.getName(), IRubyObject.NULL_ARRAY, CallType.VARIABLE); } case NodeTypes.WHENNODE: assert false; return null; case NodeTypes.WHILENODE: { WhileNode iVisited = (WhileNode) node; IRubyObject result = runtime.getNil(); boolean firstTest = iVisited.evaluateAtStart(); while (!firstTest || (result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { firstTest = true; loop: while (true) { // Used for the 'redo' command try { evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return result; default: throw je; } } } } return result; } case NodeTypes.XSTRNODE: { XStrNode iVisited = (XStrNode) node; return self.callMethod(context, "`", runtime.newString(iVisited.getValue())); } case NodeTypes.YIELDNODE: { YieldNode iVisited = (YieldNode) node; IRubyObject result = evalInternal(context, iVisited.getArgsNode(), self); if (iVisited.getArgsNode() == null) { result = null; } return context.yieldCurrentBlock(result, null, null, iVisited.getCheckState()); } case NodeTypes.ZARRAYNODE: { return runtime.newArray(); } case NodeTypes.ZSUPERNODE: { if (context.getFrameLastClass() == null) { throw runtime.newNameError("superclass method '" + context.getFrameLastFunc() + "' disabled"); } return context.callSuper(context.getFrameArgs()); } } } while (true); }
private static IRubyObject evalInternal(ThreadContext context, Node node, IRubyObject self) { IRuby runtime = context.getRuntime(); bigloop: do { if (node == null) return runtime.getNil(); switch (node.nodeId) { case NodeTypes.ALIASNODE: { AliasNode iVisited = (AliasNode) node; if (context.getRubyClass() == null) { throw runtime.newTypeError("no class to make alias"); } context.getRubyClass().defineAlias(iVisited.getNewName(), iVisited.getOldName()); context.getRubyClass().callMethod(context, "method_added", runtime.newSymbol(iVisited.getNewName())); return runtime.getNil(); } case NodeTypes.ANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.ARGSCATNODE: { ArgsCatNode iVisited = (ArgsCatNode) node; IRubyObject args = evalInternal(context, iVisited.getFirstNode(), self); IRubyObject secondArgs = splatValue(evalInternal(context, iVisited.getSecondNode(), self)); RubyArray list = args instanceof RubyArray ? (RubyArray) args : runtime.newArray(args); return list.concat(secondArgs); } // case NodeTypes.ARGSNODE: // EvaluateVisitor.argsNodeVisitor.execute(this, node); // break; // case NodeTypes.ARGUMENTNODE: // EvaluateVisitor.argumentNodeVisitor.execute(this, node); // break; case NodeTypes.ARRAYNODE: { ArrayNode iVisited = (ArrayNode) node; IRubyObject[] array = new IRubyObject[iVisited.size()]; int i = 0; for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node next = (Node) iterator.next(); array[i++] = evalInternal(context, next, self); } return runtime.newArray(array); } // case NodeTypes.ASSIGNABLENODE: // EvaluateVisitor.assignableNodeVisitor.execute(this, node); // break; case NodeTypes.BACKREFNODE: { BackRefNode iVisited = (BackRefNode) node; IRubyObject backref = context.getBackref(); switch (iVisited.getType()) { case '~': return backref; case '&': return RubyRegexp.last_match(backref); case '`': return RubyRegexp.match_pre(backref); case '\'': return RubyRegexp.match_post(backref); case '+': return RubyRegexp.match_last(backref); } break; } case NodeTypes.BEGINNODE: { BeginNode iVisited = (BeginNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.BIGNUMNODE: { BignumNode iVisited = (BignumNode) node; return RubyBignum.newBignum(runtime, iVisited.getValue()); } // case NodeTypes.BINARYOPERATORNODE: // EvaluateVisitor.binaryOperatorNodeVisitor.execute(this, node); // break; // case NodeTypes.BLOCKARGNODE: // EvaluateVisitor.blockArgNodeVisitor.execute(this, node); // break; case NodeTypes.BLOCKNODE: { BlockNode iVisited = (BlockNode) node; IRubyObject result = runtime.getNil(); for (Iterator iter = iVisited.iterator(); iter.hasNext();) { result = evalInternal(context, (Node) iter.next(), self); } return result; } case NodeTypes.BLOCKPASSNODE: { BlockPassNode iVisited = (BlockPassNode) node; IRubyObject proc = evalInternal(context, iVisited.getBodyNode(), self); if (proc.isNil()) { context.setNoBlock(); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearNoBlock(); } } // If not already a proc then we should try and make it one. if (!(proc instanceof RubyProc)) { proc = proc.convertToType("Proc", "to_proc", false); if (!(proc instanceof RubyProc)) { throw runtime.newTypeError("wrong argument type " + proc.getMetaClass().getName() + " (expected Proc)"); } } // TODO: Add safety check for taintedness Block block = (Block) context.getCurrentBlock(); if (block != null) { IRubyObject blockObject = block.getBlockObject(); // The current block is already associated with the proc. No need to create new // block for it. Just eval! if (blockObject != null && blockObject == proc) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } finally { context.clearBlockAvailable(); } } } context.preBlockPassEval(((RubyProc) proc).getBlock()); try { return evalInternal(context, iVisited.getIterNode(), self); } finally { context.postBlockPassEval(); } } case NodeTypes.BREAKNODE: { BreakNode iVisited = (BreakNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.BreakJump); je.setPrimaryData(result); je.setSecondaryData(node); throw je; } case NodeTypes.CALLNODE: { CallNode iVisited = (CallNode) node; context.beginCallArgs(); IRubyObject receiver = null; IRubyObject[] args = null; try { receiver = evalInternal(context, iVisited.getReceiverNode(), self); args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } assert receiver.getMetaClass() != null : receiver.getClass().getName(); // If reciever is self then we do the call the same way as vcall CallType callType = (receiver == self ? CallType.VARIABLE : CallType.NORMAL); return receiver.callMethod(context, iVisited.getName(), args, callType); } case NodeTypes.CASENODE: { CaseNode iVisited = (CaseNode) node; IRubyObject expression = null; if (iVisited.getCaseNode() != null) { expression = evalInternal(context, iVisited.getCaseNode(), self); } context.pollThreadEvents(); IRubyObject result = runtime.getNil(); Node firstWhenNode = iVisited.getFirstWhenNode(); while (firstWhenNode != null) { if (!(firstWhenNode instanceof WhenNode)) { node = firstWhenNode; continue bigloop; } WhenNode whenNode = (WhenNode) firstWhenNode; if (whenNode.getExpressionNodes() instanceof ArrayNode) { for (Iterator iter = ((ArrayNode) whenNode.getExpressionNodes()).iterator(); iter .hasNext();) { Node tag = (Node) iter.next(); context.setPosition(tag.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // Ruby grammar has nested whens in a case body because of // productions case_body and when_args. if (tag instanceof WhenNode) { RubyArray expressions = (RubyArray) evalInternal(context, ((WhenNode) tag) .getExpressionNodes(), self); for (int j = 0; j < expressions.getLength(); j++) { IRubyObject condition = expressions.entry(j); if ((expression != null && condition.callMethod(context, "===", expression) .isTrue()) || (expression == null && condition.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } continue; } result = evalInternal(context, tag, self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = whenNode.getBodyNode(); continue bigloop; } } } else { result = evalInternal(context, whenNode.getExpressionNodes(), self); if ((expression != null && result.callMethod(context, "===", expression).isTrue()) || (expression == null && result.isTrue())) { node = ((WhenNode) firstWhenNode).getBodyNode(); continue bigloop; } } context.pollThreadEvents(); firstWhenNode = whenNode.getNextCase(); } return runtime.getNil(); } case NodeTypes.CLASSNODE: { ClassNode iVisited = (ClassNode) node; Node superNode = iVisited.getSuperNode(); RubyClass superClass = superNode == null ? null : (RubyClass) evalInternal(context, superNode, self); Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingClass = getEnclosingModule(context, classNameNode, self); RubyClass rubyClass = enclosingClass.defineOrGetClassUnder(name, superClass); if (context.getWrapper() != null) { rubyClass.extendObject(context.getWrapper()); rubyClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), rubyClass, self); } case NodeTypes.CLASSVARASGNNODE: { ClassVarAsgnNode iVisited = (ClassVarAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule) rubyClass.getInstanceVariable("__attached__"); } rubyClass.setClassVar(iVisited.getName(), result); return result; } case NodeTypes.CLASSVARDECLNODE: { ClassVarDeclNode iVisited = (ClassVarDeclNode) node; // FIXME: shouldn't we use cref here? if (context.getRubyClass() == null) { throw runtime.newTypeError("no class/module to define class variable"); } IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); ((RubyModule) context.peekCRef().getValue()).setClassVar(iVisited.getName(), result); return runtime.getNil(); } case NodeTypes.CLASSVARNODE: { ClassVarNode iVisited = (ClassVarNode) node; RubyModule rubyClass = (RubyModule) context.peekCRef().getValue(); if (rubyClass == null) { rubyClass = self.getMetaClass(); } else if (rubyClass.isSingleton()) { rubyClass = (RubyModule)rubyClass.getInstanceVariable("__attached__"); } return rubyClass.getClassVar(iVisited.getName()); } case NodeTypes.COLON2NODE: { Colon2Node iVisited = (Colon2Node) node; Node leftNode = iVisited.getLeftNode(); // TODO: Made this more colon3 friendly because of cpath production // rule in grammar (it is convenient to think of them as the same thing // at a grammar level even though evaluation is). if (leftNode == null) { return runtime.getObject().getConstantFrom(iVisited.getName()); } else { IRubyObject result = evalInternal(context, iVisited.getLeftNode(), self); if (result instanceof RubyModule) { return ((RubyModule) result).getConstantFrom(iVisited.getName()); } else { return result.callMethod(context, iVisited.getName()); } } } case NodeTypes.COLON3NODE: { Colon3Node iVisited = (Colon3Node) node; return runtime.getObject().getConstantFrom(iVisited.getName()); } case NodeTypes.CONSTDECLNODE: { ConstDeclNode iVisited = (ConstDeclNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); IRubyObject module; if (iVisited.getPathNode() != null) { module = evalInternal(context, iVisited.getPathNode(), self); } else { // FIXME: why do we check RubyClass and then use CRef? if (context.getRubyClass() == null) { // TODO: wire into new exception handling mechanism throw runtime.newTypeError("no class/module to define constant"); } module = (RubyModule) context.peekCRef().getValue(); } // FIXME: shouldn't we use the result of this set in setResult? ((RubyModule) module).setConstant(iVisited.getName(), result); return result; } case NodeTypes.CONSTNODE: { ConstNode iVisited = (ConstNode) node; return context.getConstant(iVisited.getName()); } case NodeTypes.DASGNNODE: { DAsgnNode iVisited = (DAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("DSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.DEFINEDNODE: { DefinedNode iVisited = (DefinedNode) node; String definition = getDefinition(context, iVisited.getExpressionNode(), self); if (definition != null) { return runtime.newString(definition); } else { return runtime.getNil(); } } case NodeTypes.DEFNNODE: { DefnNode iVisited = (DefnNode) node; RubyModule containingClass = context.getRubyClass(); if (containingClass == null) { throw runtime.newTypeError("No class to add method."); } String name = iVisited.getName(); if (containingClass == runtime.getObject() && name.equals("initialize")) { runtime.getWarnings().warn("redefining Object#initialize may cause infinite loop"); } Visibility visibility = context.getCurrentVisibility(); if (name.equals("initialize") || visibility.isModuleFunction()) { visibility = Visibility.PRIVATE; } DefaultMethod newMethod = new DefaultMethod(containingClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), visibility, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } containingClass.addMethod(name, newMethod); if (context.getCurrentVisibility().isModuleFunction()) { containingClass.getSingletonClass().addMethod( name, new WrapperCallable(containingClass.getSingletonClass(), newMethod, Visibility.PUBLIC)); containingClass.callMethod(context, "singleton_method_added", runtime.newSymbol(name)); } // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { ((MetaClass) containingClass).getAttachedObject().callMethod( context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); } else { containingClass.callMethod(context, "method_added", runtime.newSymbol(name)); } return runtime.getNil(); } case NodeTypes.DEFSNODE: { DefsNode iVisited = (DefsNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure; can't define singleton method."); } if (receiver.isFrozen()) { throw runtime.newFrozenError("object"); } if (!receiver.singletonMethodsAllowed()) { throw runtime.newTypeError("can't define singleton method \"" + iVisited.getName() + "\" for " + receiver.getType()); } RubyClass rubyClass = receiver.getSingletonClass(); if (runtime.getSafeLevel() >= 4) { ICallable method = (ICallable) rubyClass.getMethods().get(iVisited.getName()); if (method != null) { throw runtime.newSecurityError("Redefining method prohibited."); } } DefaultMethod newMethod = new DefaultMethod(rubyClass, iVisited.getScope(), iVisited.getBodyNode(), (ArgsNode) iVisited.getArgsNode(), Visibility.PUBLIC, context.peekCRef()); if (iVisited.getBodyNode() != null) { iVisited.getBodyNode().accept(new CreateJumpTargetVisitor(newMethod)); } rubyClass.addMethod(iVisited.getName(), newMethod); receiver.callMethod(context, "singleton_method_added", runtime.newSymbol(iVisited.getName())); return runtime.getNil(); } case NodeTypes.DOTNODE: { DotNode iVisited = (DotNode) node; return RubyRange.newRange(runtime, evalInternal(context, iVisited.getBeginNode(), self), evalInternal(context, iVisited .getEndNode(), self), iVisited.isExclusive()); } case NodeTypes.DREGEXPNODE: { DRegexpNode iVisited = (DRegexpNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return RubyRegexp.newRegexp(runtime, sb.toString(), iVisited.getOptions(), null); } case NodeTypes.DSTRNODE: { DStrNode iVisited = (DStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newString(sb.toString()); } case NodeTypes.DSYMBOLNODE: { DSymbolNode iVisited = (DSymbolNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.getNode().iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return runtime.newSymbol(sb.toString()); } case NodeTypes.DVARNODE: { DVarNode iVisited = (DVarNode) node; // System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject obj = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); // FIXME: null check is removable once we figure out how to assign to unset named block args return obj == null ? runtime.getNil() : obj; } case NodeTypes.DXSTRNODE: { DXStrNode iVisited = (DXStrNode) node; StringBuffer sb = new StringBuffer(); for (Iterator iterator = iVisited.iterator(); iterator.hasNext();) { Node iterNode = (Node) iterator.next(); sb.append(evalInternal(context, iterNode, self).toString()); } return self.callMethod(context, "`", runtime.newString(sb.toString())); } case NodeTypes.ENSURENODE: { EnsureNode iVisited = (EnsureNode) node; // save entering the try if there's nothing to ensure if (iVisited.getEnsureNode() != null) { IRubyObject result = runtime.getNil(); try { result = evalInternal(context, iVisited.getBodyNode(), self); } finally { evalInternal(context, iVisited.getEnsureNode(), self); } return result; } node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.EVSTRNODE: { EvStrNode iVisited = (EvStrNode) node; node = iVisited.getBody(); continue bigloop; } case NodeTypes.FALSENODE: { context.pollThreadEvents(); return runtime.getFalse(); } case NodeTypes.FCALLNODE: { FCallNode iVisited = (FCallNode) node; context.beginCallArgs(); IRubyObject[] args; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return self.callMethod(context, iVisited.getName(), args, CallType.FUNCTIONAL); } case NodeTypes.FIXNUMNODE: { FixnumNode iVisited = (FixnumNode) node; return runtime.newFixnum(iVisited.getValue()); } case NodeTypes.FLIPNODE: { FlipNode iVisited = (FlipNode) node; IRubyObject result = runtime.getNil(); if (iVisited.isExclusive()) { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { result = evalInternal(context, iVisited.getBeginNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } else { if (!context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()).isTrue()) { if (evalInternal(context, iVisited.getBeginNode(), self).isTrue()) { context.getCurrentScope().setValue( iVisited.getIndex(), evalInternal(context, iVisited.getEndNode(), self).isTrue() ? runtime.getFalse() : runtime.getTrue(), iVisited.getDepth()); return runtime.getTrue(); } else { return runtime.getFalse(); } } else { if (evalInternal(context, iVisited.getEndNode(), self).isTrue()) { context.getCurrentScope().setValue(iVisited.getIndex(), runtime.getFalse(), iVisited.getDepth()); } return runtime.getTrue(); } } } case NodeTypes.FLOATNODE: { FloatNode iVisited = (FloatNode) node; return RubyFloat.newFloat(runtime, iVisited.getValue()); } case NodeTypes.FORNODE: { ForNode iVisited = (ForNode) node; // For nodes do not have to create an addition scope so we just pass null context.preForLoopEval(Block.createBlock(iVisited.getVarNode(), null, iVisited.getCallable(), self)); try { while (true) { try { ISourcePosition position = context.getPosition(); context.beginCallArgs(); IRubyObject recv = null; try { recv = evalInternal(context, iVisited.getIterNode(), self); } finally { context.setPosition(position); context.endCallArgs(); } return recv.callMethod(context, "each", IRubyObject.NULL_ARRAY, CallType.NORMAL); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // do nothing, allow loop to retry break; default: throw je; } } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postForLoopEval(); } } case NodeTypes.GLOBALASGNNODE: { GlobalAsgnNode iVisited = (GlobalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); runtime.getGlobalVariables().set(iVisited.getName(), result); return result; } case NodeTypes.GLOBALVARNODE: { GlobalVarNode iVisited = (GlobalVarNode) node; return runtime.getGlobalVariables().get(iVisited.getName()); } case NodeTypes.HASHNODE: { HashNode iVisited = (HashNode) node; Map hash = null; if (iVisited.getListNode() != null) { hash = new HashMap(iVisited.getListNode().size() / 2); for (Iterator iterator = iVisited.getListNode().iterator(); iterator.hasNext();) { // insert all nodes in sequence, hash them in the final instruction // KEY IRubyObject key = evalInternal(context, (Node) iterator.next(), self); IRubyObject value = evalInternal(context, (Node) iterator.next(), self); hash.put(key, value); } } if (hash == null) { return RubyHash.newHash(runtime); } return RubyHash.newHash(runtime, hash, runtime.getNil()); } case NodeTypes.IFNODE: { IfNode iVisited = (IfNode) node; IRubyObject result = evalInternal(context, iVisited.getCondition(), self); if (result.isTrue()) { node = iVisited.getThenBody(); continue bigloop; } else { node = iVisited.getElseBody(); continue bigloop; } } case NodeTypes.INSTASGNNODE: { InstAsgnNode iVisited = (InstAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); self.setInstanceVariable(iVisited.getName(), result); return result; } case NodeTypes.INSTVARNODE: { InstVarNode iVisited = (InstVarNode) node; IRubyObject variable = self.getInstanceVariable(iVisited.getName()); return variable == null ? runtime.getNil() : variable; } // case NodeTypes.ISCOPINGNODE: // EvaluateVisitor.iScopingNodeVisitor.execute(this, node); // break; case NodeTypes.ITERNODE: { IterNode iVisited = (IterNode) node; context.preIterEval(Block.createBlock(iVisited.getVarNode(), new DynamicScope(iVisited.getScope(), context.getCurrentScope()), iVisited.getCallable(), self)); try { while (true) { try { context.setBlockAvailable(); return evalInternal(context, iVisited.getIterNode(), self); } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.RETRY: // allow loop to retry break; default: throw je; } } finally { context.clearBlockAvailable(); } } } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.BREAK: IRubyObject breakValue = (IRubyObject) je.getPrimaryData(); return breakValue == null ? runtime.getNil() : breakValue; default: throw je; } } finally { context.postIterEval(); } } case NodeTypes.LOCALASGNNODE: { LocalAsgnNode iVisited = (LocalAsgnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // System.out.println("LSetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth() + " and set " + result); context.getCurrentScope().setValue(iVisited.getIndex(), result, iVisited.getDepth()); return result; } case NodeTypes.LOCALVARNODE: { LocalVarNode iVisited = (LocalVarNode) node; //System.out.println("DGetting: " + iVisited.getName() + " at index " + iVisited.getIndex() + " and at depth " + iVisited.getDepth()); IRubyObject result = context.getCurrentScope().getValue(iVisited.getIndex(), iVisited.getDepth()); return result == null ? runtime.getNil() : result; } case NodeTypes.MATCH2NODE: { Match2Node iVisited = (Match2Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); return ((RubyRegexp) recv).match(value); } case NodeTypes.MATCH3NODE: { Match3Node iVisited = (Match3Node) node; IRubyObject recv = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = evalInternal(context, iVisited.getValueNode(), self); if (value instanceof RubyString) { return ((RubyRegexp) recv).match(value); } else { return value.callMethod(context, "=~", recv); } } case NodeTypes.MATCHNODE: { MatchNode iVisited = (MatchNode) node; return ((RubyRegexp) evalInternal(context, iVisited.getRegexpNode(), self)).match2(); } case NodeTypes.MODULENODE: { ModuleNode iVisited = (ModuleNode) node; Node classNameNode = iVisited.getCPath(); String name = ((INameNode) classNameNode).getName(); RubyModule enclosingModule = getEnclosingModule(context, classNameNode, self); if (enclosingModule == null) { throw runtime.newTypeError("no outer class/module"); } RubyModule module; if (enclosingModule == runtime.getObject()) { module = runtime.getOrCreateModule(name); } else { module = enclosingModule.defineModuleUnder(name); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), module, self); } case NodeTypes.MULTIPLEASGNNODE: { MultipleAsgnNode iVisited = (MultipleAsgnNode) node; return AssignmentVisitor.assign(context, self, iVisited, evalInternal(context, iVisited.getValueNode(), self), false); } case NodeTypes.NEWLINENODE: { NewlineNode iVisited = (NewlineNode) node; // something in here is used to build up ruby stack trace... context.setPosition(iVisited.getPosition()); if (isTrace(runtime)) { callTraceFunction(context, "line", self); } // TODO: do above but not below for additional newline nodes node = iVisited.getNextNode(); continue bigloop; } case NodeTypes.NEXTNODE: { NextNode iVisited = (NextNode) node; context.pollThreadEvents(); IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.NextJump); je.setPrimaryData(result); je.setSecondaryData(iVisited); //state.setCurrentException(je); throw je; } case NodeTypes.NILNODE: return runtime.getNil(); case NodeTypes.NOTNODE: { NotNode iVisited = (NotNode) node; IRubyObject result = evalInternal(context, iVisited.getConditionNode(), self); return result.isTrue() ? runtime.getFalse() : runtime.getTrue(); } case NodeTypes.NTHREFNODE: { NthRefNode iVisited = (NthRefNode) node; return RubyRegexp.nth_match(iVisited.getMatchNumber(), context.getBackref()); } case NodeTypes.OPASGNANDNODE: { BinaryOperatorNode iVisited = (BinaryOperatorNode) node; // add in reverse order IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) return result; node = iVisited.getSecondNode(); continue bigloop; } case NodeTypes.OPASGNNODE: { OpAsgnNode iVisited = (OpAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject value = receiver.callMethod(context, iVisited.getVariableName()); if (iVisited.getOperatorName().equals("||")) { if (value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!value.isTrue()) { return value; } value = evalInternal(context, iVisited.getValueNode(), self); } else { value = value.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited.getValueNode(), self)); } receiver.callMethod(context, iVisited.getVariableName() + "=", value); context.pollThreadEvents(); return value; } case NodeTypes.OPASGNORNODE: { OpAsgnOrNode iVisited = (OpAsgnOrNode) node; String def = getDefinition(context, iVisited.getFirstNode(), self); IRubyObject result = runtime.getNil(); if (def != null) { result = evalInternal(context, iVisited.getFirstNode(), self); } if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } case NodeTypes.OPELEMENTASGNNODE: { OpElementAsgnNode iVisited = (OpElementAsgnNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); IRubyObject[] args = setupArgs(context, iVisited.getArgsNode(), self); IRubyObject firstValue = receiver.callMethod(context, "[]", args); if (iVisited.getOperatorName().equals("||")) { if (firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else if (iVisited.getOperatorName().equals("&&")) { if (!firstValue.isTrue()) { return firstValue; } firstValue = evalInternal(context, iVisited.getValueNode(), self); } else { firstValue = firstValue.callMethod(context, iVisited.getOperatorName(), evalInternal(context, iVisited .getValueNode(), self)); } IRubyObject[] expandedArgs = new IRubyObject[args.length + 1]; System.arraycopy(args, 0, expandedArgs, 0, args.length); expandedArgs[expandedArgs.length - 1] = firstValue; return receiver.callMethod(context, "[]=", expandedArgs); } case NodeTypes.OPTNNODE: { OptNNode iVisited = (OptNNode) node; IRubyObject result = runtime.getNil(); while (RubyKernel.gets(runtime.getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: // do nothing, this iteration restarts break; case JumpType.NEXT: // recheck condition break loop; case JumpType.BREAK: // end loop return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.ORNODE: { OrNode iVisited = (OrNode) node; IRubyObject result = evalInternal(context, iVisited.getFirstNode(), self); if (!result.isTrue()) { result = evalInternal(context, iVisited.getSecondNode(), self); } return result; } // case NodeTypes.POSTEXENODE: // EvaluateVisitor.postExeNodeVisitor.execute(this, node); // break; case NodeTypes.REDONODE: { context.pollThreadEvents(); // now used as an interpreter event JumpException je = new JumpException(JumpException.JumpType.RedoJump); je.setSecondaryData(node); throw je; } case NodeTypes.REGEXPNODE: { RegexpNode iVisited = (RegexpNode) node; // FIXME: don't pass null String lang = null; int opts = iVisited.getOptions(); if((opts & 16) != 0) { lang = "n"; } else if((opts & 48) != 0) { lang = "s"; } else if((opts & 64) != 0) { lang = "u"; } return RubyRegexp.newRegexp(runtime, iVisited.getPattern(), lang); } case NodeTypes.RESCUEBODYNODE: { RescueBodyNode iVisited = (RescueBodyNode) node; node = iVisited.getBodyNode(); continue bigloop; } case NodeTypes.RESCUENODE: { RescueNode iVisited = (RescueNode)node; RescuedBlock : while (true) { try { // Execute rescue block IRubyObject result = evalInternal(context, iVisited.getBodyNode(), self); // If no exception is thrown execute else block if (iVisited.getElseNode() != null) { if (iVisited.getRescueNode() == null) { runtime.getWarnings().warn(iVisited.getElseNode().getPosition(), "else without rescue is useless"); } result = evalInternal(context, iVisited.getElseNode(), self); } return result; } catch (RaiseException raiseJump) { RubyException raisedException = raiseJump.getException(); // TODO: Rubicon TestKernel dies without this line. A cursory glance implies we // falsely set $! to nil and this sets it back to something valid. This should // get fixed at the same time we address bug #1296484. runtime.getGlobalVariables().set("$!", raisedException); RescueBodyNode rescueNode = iVisited.getRescueNode(); while (rescueNode != null) { Node exceptionNodes = rescueNode.getExceptionNodes(); ListNode exceptionNodesList; if (exceptionNodes instanceof SplatNode) { exceptionNodesList = (ListNode) evalInternal(context, exceptionNodes, self); } else { exceptionNodesList = (ListNode) exceptionNodes; } if (isRescueHandled(context, raisedException, exceptionNodesList, self)) { try { return evalInternal(context, rescueNode, self); } catch (JumpException je) { if (je.getJumpType() == JumpException.JumpType.RetryJump) { // should be handled in the finally block below //state.runtime.getGlobalVariables().set("$!", state.runtime.getNil()); //state.threadContext.setRaisedException(null); continue RescuedBlock; } else { throw je; } } } rescueNode = rescueNode.getOptRescueNode(); } // no takers; bubble up throw raiseJump; } finally { // clear exception when handled or retried runtime.getGlobalVariables().set("$!", runtime.getNil()); } } } case NodeTypes.RETRYNODE: { context.pollThreadEvents(); JumpException je = new JumpException(JumpException.JumpType.RetryJump); throw je; } case NodeTypes.RETURNNODE: { ReturnNode iVisited = (ReturnNode) node; IRubyObject result = evalInternal(context, iVisited.getValueNode(), self); JumpException je = new JumpException(JumpException.JumpType.ReturnJump); je.setPrimaryData(iVisited.getTarget()); je.setSecondaryData(result); je.setTertiaryData(iVisited); throw je; } case NodeTypes.ROOTNODE: { RootNode iVisited = (RootNode) node; DynamicScope scope = iVisited.getScope(); // Serialization killed our dynamic scope. We can just create an empty one // since serialization cannot serialize an eval (which is the only thing // which is capable of having a non-empty dynamic scope). if (scope == null) { scope = new DynamicScope(iVisited.getStaticScope(), null); } // Each root node has a top-level scope that we need to push context.preRootNode(scope); // FIXME: Wire up BEGIN and END nodes try { return eval(context, iVisited.getBodyNode(), self); } finally { context.postRootNode(); } } case NodeTypes.SCLASSNODE: { SClassNode iVisited = (SClassNode) node; IRubyObject receiver = evalInternal(context, iVisited.getReceiverNode(), self); RubyClass singletonClass; if (receiver.isNil()) { singletonClass = runtime.getNilClass(); } else if (receiver == runtime.getTrue()) { singletonClass = runtime.getClass("TrueClass"); } else if (receiver == runtime.getFalse()) { singletonClass = runtime.getClass("FalseClass"); } else { if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw runtime.newSecurityError("Insecure: can't extend object."); } singletonClass = receiver.getSingletonClass(); } if (context.getWrapper() != null) { singletonClass.extendObject(context.getWrapper()); singletonClass.includeModule(context.getWrapper()); } return evalClassDefinitionBody(context, iVisited.getScope(), iVisited.getBodyNode(), singletonClass, self); } case NodeTypes.SELFNODE: return self; case NodeTypes.SPLATNODE: { SplatNode iVisited = (SplatNode) node; return splatValue(evalInternal(context, iVisited.getValue(), self)); } //// case NodeTypes.STARNODE: //// EvaluateVisitor.starNodeVisitor.execute(this, node); //// break; case NodeTypes.STRNODE: { StrNode iVisited = (StrNode) node; return runtime.newString(iVisited.getValue()); } case NodeTypes.SUPERNODE: { SuperNode iVisited = (SuperNode) node; if (context.getFrameLastClass() == null) { throw runtime.newNameError("Superclass method '" + context.getFrameLastFunc() + "' disabled."); } context.beginCallArgs(); IRubyObject[] args = null; try { args = setupArgs(context, iVisited.getArgsNode(), self); } finally { context.endCallArgs(); } return context.callSuper(args); } case NodeTypes.SVALUENODE: { SValueNode iVisited = (SValueNode) node; return aValueSplat(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.SYMBOLNODE: { SymbolNode iVisited = (SymbolNode) node; return runtime.newSymbol(iVisited.getName()); } case NodeTypes.TOARYNODE: { ToAryNode iVisited = (ToAryNode) node; return aryToAry(evalInternal(context, iVisited.getValue(), self)); } case NodeTypes.TRUENODE: { context.pollThreadEvents(); return runtime.getTrue(); } case NodeTypes.UNDEFNODE: { UndefNode iVisited = (UndefNode) node; if (context.getRubyClass() == null) { throw runtime .newTypeError("No class to undef method '" + iVisited.getName() + "'."); } context.getRubyClass().undef(iVisited.getName()); return runtime.getNil(); } case NodeTypes.UNTILNODE: { UntilNode iVisited = (UntilNode) node; IRubyObject result = runtime.getNil(); while (!(result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { loop: while (true) { // Used for the 'redo' command try { result = evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return (IRubyObject) je.getPrimaryData(); default: throw je; } } } } return result; } case NodeTypes.VALIASNODE: { VAliasNode iVisited = (VAliasNode) node; runtime.getGlobalVariables().alias(iVisited.getNewName(), iVisited.getOldName()); return runtime.getNil(); } case NodeTypes.VCALLNODE: { VCallNode iVisited = (VCallNode) node; return self.callMethod(context, iVisited.getName(), IRubyObject.NULL_ARRAY, CallType.VARIABLE); } case NodeTypes.WHENNODE: assert false; return null; case NodeTypes.WHILENODE: { WhileNode iVisited = (WhileNode) node; IRubyObject result = runtime.getNil(); boolean firstTest = iVisited.evaluateAtStart(); while (!firstTest || (result = evalInternal(context, iVisited.getConditionNode(), self)).isTrue()) { firstTest = true; loop: while (true) { // Used for the 'redo' command try { evalInternal(context, iVisited.getBodyNode(), self); break loop; } catch (JumpException je) { switch (je.getJumpType().getTypeId()) { case JumpType.REDO: continue; case JumpType.NEXT: break loop; case JumpType.BREAK: return result; default: throw je; } } } } return result; } case NodeTypes.XSTRNODE: { XStrNode iVisited = (XStrNode) node; return self.callMethod(context, "`", runtime.newString(iVisited.getValue())); } case NodeTypes.YIELDNODE: { YieldNode iVisited = (YieldNode) node; IRubyObject result = evalInternal(context, iVisited.getArgsNode(), self); if (iVisited.getArgsNode() == null) { result = null; } return context.yieldCurrentBlock(result, null, null, iVisited.getCheckState()); } case NodeTypes.ZARRAYNODE: { return runtime.newArray(); } case NodeTypes.ZSUPERNODE: { if (context.getFrameLastClass() == null) { throw runtime.newNameError("superclass method '" + context.getFrameLastFunc() + "' disabled"); } return context.callSuper(context.getFrameArgs()); } } } while (true); }
3,229,970
public DisplayOption(Integer attributeId, Boolean redOn, Integer ZStart, Boolean blueOn, String colorMap, Integer ZStop, Float zoom, Integer TStop, Integer TStart, Boolean greenOn, Boolean displayRgb, org.openmicroscopy.omero.model.Image image, org.openmicroscopy.omero.model.ImagePixel imagePixel, org.openmicroscopy.omero.model.ModuleExecution moduleExecution, Set displayRois) { this.attributeId = attributeId; this.redOn = redOn; this.ZStart = ZStart; this.blueOn = blueOn; this.colorMap = colorMap; this.ZStop = ZStop; this.zoom = zoom; this.TStop = TStop; this.TStart = TStart; this.greenOn = greenOn; this.displayRgb = displayRgb; this.image = image; this.imagePixel = imagePixel; this.moduleExecution = moduleExecution; this.displayRois = displayRois; }
public DisplayOption(Integer attributeId, Boolean redOn, Integer ZStart, Boolean blueOn, String colorMap, Integer ZStop, Float zoom, Integer TStop, Integer TStart, Boolean greenOn, Boolean displayRgb, org.openmicroscopy.omero.model.Image image, org.openmicroscopy.omero.model.ImagePixel imagePixel, org.openmicroscopy.omero.model.ModuleExecution moduleExecution, Set displayRois) { this.attributeId = attributeId; this.redOn = redOn; this.ZStart = ZStart; this.blueOn = blueOn; this.colorMap = colorMap; this.ZStop = ZStop; this.zoom = zoom; this.TStop = TStop; this.TStart = TStart; this.greenOn = greenOn; this.displayRgb = displayRgb; this.image = image; this.imagePixel = imagePixel; this.moduleExecution = moduleExecution; this.displayRois = displayRois; }
3,229,971
public org.openmicroscopy.omero.model.Image getImage() { return this.image; }
public Image getImage() { return this.image; }
3,229,972
public org.openmicroscopy.omero.model.ImagePixel getImagePixel() { return this.imagePixel; }
public ImagePixel getImagePixel() { return this.imagePixel; }
3,229,973
public org.openmicroscopy.omero.model.ModuleExecution getModuleExecution() { return this.moduleExecution; }
public ModuleExecution getModuleExecution() { return this.moduleExecution; }
3,229,974
public void setImage(org.openmicroscopy.omero.model.Image image) { this.image = image; }
public void setImage(Image image) { this.image = image; }
3,229,975
public void setImagePixel(org.openmicroscopy.omero.model.ImagePixel imagePixel) { this.imagePixel = imagePixel; }
public void setImagePixel(ImagePixel imagePixel) { this.imagePixel = imagePixel; }
3,229,976
public void setModuleExecution(org.openmicroscopy.omero.model.ModuleExecution moduleExecution) { this.moduleExecution = moduleExecution; }
public void setModuleExecution(ModuleExecution moduleExecution) { this.moduleExecution = moduleExecution; }
3,229,977
private void handleExit(String element){ if (Property.FIELDS.contains(element)){ if (null==property){ throw new IllegalStateException("Exiting non-extant property!\n"+"Element:"+element+"\nType:"+type+"\nProperty:"+property); } if (null==type){ throw new IllegalStateException("Inside of non-extant type!!\n"+"Element:"+element+"\nType:"+type); } property.validate(); type.getProperties().add(property); property=null; } else if (SemanticType.TYPES.contains(element)){ if (null==type){ throw new IllegalStateException("Exiting non-extent type!\n"+"Element:"+element+"\nType:"+type); } type.validate(); types.add(type); type=null; } }
private void handleExit(String element){ if (Property.FIELDS.contains(element)){ if (null==property){ throw new IllegalStateException("Exiting non-extant property!\n"+"Element:"+element+"\nType:"+type+"\nProperty:"+property); } if (null==type){ throw new IllegalStateException("Inside of non-extant type!!\n"+"Element:"+element+"\nType:"+type); } property.validate(); type.getProperties().add(property); property=null; } else if (SemanticType.TYPES.contains(element)){ if (null==type){ throw new IllegalStateException("Exiting non-extent type!\n"+"Element:"+element+"\nType:"+type); } type.validate(); types.add(type); type=null; } }
3,229,978
public Set process(){ return types; }
public Set process(){ return types; }
3,229,979
public SaxReader(String filename){ xmlFile = this.getClass().getClassLoader().getResource(filename); init(); }
public SaxReader(String filename){ xmlFile = this.getClass().getClassLoader().getResource(filename); init(); }
3,229,980
public Set parse(){ try { parser.parse(xmlFile.getPath(), handler); } catch (Exception e) { throw new RuntimeException( "Error parsing "+xmlFile+" :\n"+e.getMessage(),e); } return handler.process(); }
public Set parse(){ try { parser.parse(xmlFile.getPath(), handler); } catch (Exception e) { throw new RuntimeException( "Error parsing "+xmlFile+" :\n"+e.getMessage(),e); } return handler.process(); }
3,229,981
public Set parse(){ try { parser.parse(xmlFile.getPath(), handler); } catch (Exception e) { throw new RuntimeException( "Error parsing "+xmlFile+" :\n"+e.getMessage(),e); } return handler.process(); }
public Set parse(){ try { parser.parse(xmlFile.getPath(), handler); } catch (Exception e) { throw new RuntimeException( "Error parsing "+xmlFile+" :\n"+e.getMessage(),e); } return handler.process(); }
3,229,982
public Set getProperties() { return properties; }
public Set getProperties() { return properties; }
3,229,983
public abstract HttpMethodBase marshal() throws ImageServiceException;
public abstract HttpMethod marshal() throws ImageServiceException;
3,229,984
void saveROIResult(String format, String name, String msg) { UserNotifier un = control.getRegistry().getUserNotifier(); if (mng.getROIStats() == null) un.notifyError("Save ROI results", msg); else { name +="."+format; //Add extension File f = new File(name); try { if (format.equals(TEXTFilter.TEXT)) WriterText.writeTableAsText(f, mng.getModel()); else if (format.equals(TEXTFilter.TEXT)) writeXMLFile(); un.notifyInfo("ROI results saved", msg); } catch (Exception e) { f.delete(); un.notifyError("Save ROI result failure", "Unable to save the " + "result of the ROI analysis.", e); } } }
void saveROIResult(String format, String name, String msg) { UserNotifier un = control.getRegistry().getUserNotifier(); if (mng.getROIStats() == null) un.notifyError("Save ROI results", msg); else { name +="."+format; //Add extension File f = new File(name); try { if (format.equals(TEXTFilter.TEXT)) WriterText.writeTableAsText(f, mng.getModel()); else if (format.equals(TEXTFilter.TEXT)) writeXMLFile(); un.notifyInfo("ROI results saved", msg); } catch (Exception e) { f.delete(); un.notifyError("Save ROI result failure", "Unable to save the " + "result of the ROI analysis.", e); } } }
3,229,985
String[][] getROIStats() { return control.getROIStats(); }
String[][] getROIStats() { return control.getROIStats(); }
3,229,986
public void declare(JFormatter f) { if (jdoc != null) f.nl().g(jdoc); if (annotations != null){ for( int i=0; i<annotations.size(); i++ ) f.g(annotations.get(i)).nl(); } f.g(mods).p(classType.declarationToken).id(name).d(generifiable); if (superClass != null && superClass != owner().ref(Object.class)) f.nl().i().p("extends").g(superClass).nl().o(); if (!interfaces.isEmpty()) { if (superClass == null) f.nl(); f.i().p(classType==ClassType.INTERFACE ? "extends" : "implements"); f.g(interfaces); f.nl().o(); } declareBody(f); }
public void declare(JFormatter f) { if (jdoc != null) f.nl().g(jdoc); if (annotations != null){ for( int i=0; i<annotations.size(); i++ ) f.g(annotations.get(i)).nl(); } f.g(mods).p(classType.declarationToken).id(name).d(generifiable); if (superClass != null && superClass != owner().ref(Object.class)) f.nl().i().p("extends").g(superClass).nl().o(); if (!interfaces.isEmpty()) { if (superClass == null) f.nl(); f.i().p(classType==ClassType.INTERFACE ? "extends" : "implements"); f.g(interfaces); f.nl().o(); } declareBody(f); }
3,229,990
public JEnumConstant enumConstant(String name){ JEnumConstant ec = new JEnumConstant(this, name); enumConstantsByName.put(name, ec); return ec; }
public JEnumConstant enumConstant(String name){ JEnumConstant ec = new JEnumConstant(this, name); enumConstantsByName.put(name, ec); return ec; }
3,229,991