bugged
stringlengths
6
599k
fixed
stringlengths
6
40.8M
__index_level_0__
int64
0
3.24M
public MetaClass(Ruby runtime, RubyClass type, RubyClass superClass) { super(runtime, type, superClass); }
public MetaClass(Ruby runtime, RubyClass type, RubyClass superClass) { super(runtime, type, superClass); }
3,228,773
public static RubyObject backquote(Ruby ruby, RubyObject recv, RubyString aString) { // XXX use other methods try { String lShellProp = System.getProperty("jruby.shell"); Process aProcess; String lCommand = aString.toString(); String lSwitch = "-c"; if (lShellProp != null) { if (!lShellProp.endsWith("sh")) //case windowslike lSwitch = "/c"; System.out.println("command: " + lShellProp + " " + lSwitch + " " + lCommand); aProcess = Runtime.getRuntime().exec(new String[] { lShellProp, lSwitch, lCommand}); } else { System.out.println("command: " + lCommand); aProcess = Runtime.getRuntime().exec(lCommand); } final StringBuffer sb = new StringBuffer(); final BufferedReader reader = new BufferedReader(new InputStreamReader(aProcess.getInputStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line).append('\n'); } aProcess.waitFor(); return RubyString.newString(ruby, sb.toString()); } catch (Exception excptn) { excptn.printStackTrace(); return RubyString.newString(ruby, ""); } }
public static RubyObject backquote(Ruby ruby, RubyObject recv, RubyString aString) { // XXX use other methods try { String lShellProp = System.getProperty("jruby.shell"); Process aProcess; String lCommand = aString.toString(); String lSwitch = "-c"; if (lShellProp != null) { if (!lShellProp.endsWith("sh")) //case windowslike lSwitch = "/c"; System.out.println("command: " + lShellProp + " " + lSwitch + " " + lCommand); aProcess = Runtime.getRuntime().exec(new String[] { lShellProp, lSwitch, lCommand}); } else { System.out.println("command: " + lCommand); aProcess = Runtime.getRuntime().exec(lCommand); } final StringBuffer sb = new StringBuffer(); final BufferedReader reader = new BufferedReader(new InputStreamReader(aProcess.getInputStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line).append('\n'); } aProcess.waitFor(); return RubyString.newString(ruby, sb.toString()); } catch (Exception excptn) { excptn.printStackTrace(); return RubyString.newString(ruby, ""); } }
3,228,774
public static RubyObject backquote(Ruby ruby, RubyObject recv, RubyString aString) { // XXX use other methods try { String lShellProp = System.getProperty("jruby.shell"); Process aProcess; String lCommand = aString.toString(); String lSwitch = "-c"; if (lShellProp != null) { if (!lShellProp.endsWith("sh")) //case windowslike lSwitch = "/c"; System.out.println("command: " + lShellProp + " " + lSwitch + " " + lCommand); aProcess = Runtime.getRuntime().exec(new String[] { lShellProp, lSwitch, lCommand}); } else { System.out.println("command: " + lCommand); aProcess = Runtime.getRuntime().exec(lCommand); } final StringBuffer sb = new StringBuffer(); final BufferedReader reader = new BufferedReader(new InputStreamReader(aProcess.getInputStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line).append('\n'); } aProcess.waitFor(); return RubyString.newString(ruby, sb.toString()); } catch (Exception excptn) { excptn.printStackTrace(); return RubyString.newString(ruby, ""); } }
public static RubyObject backquote(Ruby ruby, RubyObject recv, RubyString aString) { // XXX use other methods try { String lShellProp = System.getProperty("jruby.shell"); Process aProcess; String lCommand = aString.toString(); String lSwitch = "-c"; if (lShellProp != null) { if (!lShellProp.endsWith("sh")) //case windowslike lSwitch = "/c"; System.out.println("command: " + lShellProp + " " + lSwitch + " " + lCommand); aProcess = Runtime.getRuntime().exec(new String[] { lShellProp, lSwitch, lCommand}); } else { aProcess = Runtime.getRuntime().exec(lCommand); } final StringBuffer sb = new StringBuffer(); final BufferedReader reader = new BufferedReader(new InputStreamReader(aProcess.getInputStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line).append('\n'); } aProcess.waitFor(); return RubyString.newString(ruby, sb.toString()); } catch (Exception excptn) { excptn.printStackTrace(); return RubyString.newString(ruby, ""); } }
3,228,775
public static RubyArray createBacktrace(Ruby ruby, int level) { RubyFrame frame = ruby.getRubyFrame(); RubyArray backtrace = RubyArray.newArray(ruby); if (level < 0) { StringBuffer sb = new StringBuffer(100); if (frame.getLastFunc() != null) { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); sb.append(":in '").append(frame.getLastFunc()).append('\''); } else if (ruby.getSourceLine() == 0) { sb.append(ruby.getSourceFile()); } else { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); } backtrace.push(RubyString.newString(ruby, sb.toString())); } else { while (level-- > 0) { frame = frame.getPrev(); if (frame == null) { return RubyArray.nilArray(ruby); } } } while (frame != null && frame.getFile() != null) { StringBuffer sb = new StringBuffer(100); if (frame.getPrev() != null && frame.getPrev().getLastFunc() != null) { sb.append(frame.getFile()).append(':').append(frame.getLine()); sb.append(":in '").append(frame.getPrev().getLastFunc()).append('\''); } else { sb.append(frame.getFile()).append(':').append(frame.getLine()); } backtrace.push(RubyString.newString(ruby, sb.toString())); frame = frame.getPrev(); } return backtrace; }
public static RubyArray createBacktrace(Ruby ruby, int level) { RubyFrame frame = ruby.getRubyFrame(); RubyArray backtrace = RubyArray.newArray(ruby); if (level < 0) { StringBuffer sb = new StringBuffer(100); if (frame.getLastFunc() != null) { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); sb.append(":in '").append(frame.getLastFunc()).append('\''); } else if (ruby.getSourceLine() == 0) { sb.append(ruby.getSourceFile()); } else { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); } backtrace.push(RubyString.newString(ruby, sb.toString())); } else { while (level-- > 0) { frame = frame.getPrev(); if (frame == null) { return RubyArray.nilArray(ruby); } } } while (frame != null && frame.getFile() != null) { StringBuffer sb = new StringBuffer(100); if (frame.getPrev() != null && frame.getPrev().getLastFunc() != null) { sb.append(frame.getFile()).append(':').append(frame.getLine()); sb.append(":in '").append(frame.getPrev().getLastFunc()).append('\''); } else { sb.append(frame.getFile()).append(':').append(frame.getLine()); } backtrace.push(RubyString.newString(ruby, sb.toString())); frame = frame.getPrev(); } return backtrace; }
3,228,776
public static RubyArray createBacktrace(Ruby ruby, int level) { RubyFrame frame = ruby.getRubyFrame(); RubyArray backtrace = RubyArray.newArray(ruby); if (level < 0) { StringBuffer sb = new StringBuffer(100); if (frame.getLastFunc() != null) { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); sb.append(":in '").append(frame.getLastFunc()).append('\''); } else if (ruby.getSourceLine() == 0) { sb.append(ruby.getSourceFile()); } else { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); } backtrace.push(RubyString.newString(ruby, sb.toString())); } else { while (level-- > 0) { frame = frame.getPrev(); if (frame == null) { return RubyArray.nilArray(ruby); } } } while (frame != null && frame.getFile() != null) { StringBuffer sb = new StringBuffer(100); if (frame.getPrev() != null && frame.getPrev().getLastFunc() != null) { sb.append(frame.getFile()).append(':').append(frame.getLine()); sb.append(":in '").append(frame.getPrev().getLastFunc()).append('\''); } else { sb.append(frame.getFile()).append(':').append(frame.getLine()); } backtrace.push(RubyString.newString(ruby, sb.toString())); frame = frame.getPrev(); } return backtrace; }
public static RubyArray createBacktrace(Ruby ruby, int level) { RubyFrame frame = ruby.getRubyFrame(); RubyArray backtrace = RubyArray.newArray(ruby); if (level < 0) { StringBuffer sb = new StringBuffer(100); if (frame.getLastFunc() != null) { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); sb.append(":in '").append(frame.getLastFunc()).append('\''); else if (ruby.getSourceLine() == 0) { sb.append(ruby.getSourceFile()); else { sb.append(ruby.getSourceFile()).append(':').append(ruby.getSourceLine()); backtrace.push(RubyString.newString(ruby, sb.toString())); else { while (level-- > 0) { frame = frame.getPrev(); if (frame == null) { return RubyArray.nilArray(ruby); while (frame != null && frame.getFile() != null) { StringBuffer sb = new StringBuffer(100); if (frame.getPrev() != null && frame.getPrev().getLastFunc() != null) { sb.append(frame.getFile()).append(':').append(frame.getLine()); sb.append(":in '").append(frame.getPrev().getLastFunc()).append('\''); else { sb.append(frame.getFile()).append(':').append(frame.getLine()); backtrace.push(RubyString.newString(ruby, sb.toString())); frame = frame.getPrev(); return backtrace; }
3,228,777
public void push(StackElement newElement) { if (top != null) { ((Scope) top).setMethodScope(ruby.getActMethodScope()); } super.push(newElement); ruby.setActMethodScope(Constants.NOEX_PUBLIC); }
public void push(StackElement newElement) { if (top != null) { ((Scope) top).setMethodScope(ruby.getActMethodScope()); } super.push(newElement); ruby.setActMethodScope(Constants.NOEX_PUBLIC); }
3,228,778
public void push(StackElement newElement) { if (top != null) { ((Scope) top).setMethodScope(ruby.getActMethodScope()); } super.push(newElement); ruby.setActMethodScope(Constants.NOEX_PUBLIC); }
public void push(StackElement newElement) { if (top != null) { ((Scope) top).setMethodScope(ruby.getActMethodScope()); } super.push(newElement); ruby.setActMethodScope(Constants.NOEX_PUBLIC); }
3,228,779
PinButton(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node"); parentNode = node; setBorder(BorderFactory.createEmptyBorder()); //No border around icon. setMargin(new Insets(0, 0, 0, 0));//Just to make sure button sz=icon sz. setOpaque(false); //B/c button=icon. setFocusPainted(false); //Don't paint focus box on top of icon. setRolloverEnabled(true); IconManager im = IconManager.getInstance(); setIcon(im.getIcon(IconManager.PIN_SMALL)); setRolloverIcon(im.getIcon(IconManager.PIN_SMALL_OVER)); setToolTipText(DESCRIPTION); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { parentNode.pinThumbnail(); } }); }
PinButton(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node"); parentNode = node; setBorder(BorderFactory.createEmptyBorder()); //No border around icon. setMargin(new Insets(0, 0, 0, 0));//Just to make sure button sz=icon sz. setOpaque(false); //B/c button=icon. setFocusPainted(false); //Don't paint focus box on top of icon. IconManager im = IconManager.getInstance(); setIcon(im.getIcon(IconManager.PIN_SMALL)); setRolloverIcon(im.getIcon(IconManager.PIN_SMALL_OVER)); setToolTipText(DESCRIPTION); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { parentNode.pinThumbnail(); } }); }
3,228,780
PinButton(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node"); parentNode = node; setBorder(BorderFactory.createEmptyBorder()); //No border around icon. setMargin(new Insets(0, 0, 0, 0));//Just to make sure button sz=icon sz. setOpaque(false); //B/c button=icon. setFocusPainted(false); //Don't paint focus box on top of icon. setRolloverEnabled(true); IconManager im = IconManager.getInstance(); setIcon(im.getIcon(IconManager.PIN_SMALL)); setRolloverIcon(im.getIcon(IconManager.PIN_SMALL_OVER)); setToolTipText(DESCRIPTION); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { parentNode.pinThumbnail(); } }); }
PinButton(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node"); parentNode = node; setBorder(BorderFactory.createEmptyBorder()); //No border around icon. setMargin(new Insets(0, 0, 0, 0));//Just to make sure button sz=icon sz. setOpaque(false); //B/c button=icon. setFocusPainted(false); //Don't paint focus box on top of icon. setRolloverEnabled(true); IconManager im = IconManager.getInstance(); setIcon(im.getIcon(IconManager.PIN_SMALL)); setToolTipText(DESCRIPTION); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { parentNode.pinThumbnail(); } }); }
3,228,781
private void addContactListToWorkspace() { Workspace workspace = SparkManager.getWorkspace(); workspace.getWorkspacePane().addTab("Contacts", SparkRes.getImageIcon(SparkRes.SMALL_ALL_CHATS_IMAGE), this); //NOTRANS // Add To Contacts Menu final JMenu contactsMenu = SparkManager.getMainWindow().getMenuByName("Contacts"); JMenuItem addContactsMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.USER1_ADD_16x16)); ResourceUtils.resButton(addContactsMenu, "&Add Contact"); ResourceUtils.resButton(addContactGroupMenu, "Add Contact &Group"); contactsMenu.add(addContactsMenu); contactsMenu.add(addContactGroupMenu); addContactsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new RosterDialog().showRosterDialog(); } }); addContactGroupMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String groupName = JOptionPane.showInputDialog(getGUI(), "Name of Group:", "Add New Group", JOptionPane.QUESTION_MESSAGE); if (ModelUtil.hasLength(groupName)) { ContactGroup contactGroup = getContactGroup(groupName); if (contactGroup == null) { contactGroup = addContactGroup(groupName); } } } }); // Add Toggle Contacts Menu ResourceUtils.resButton(showHideMenu, "&Show Empty Groups"); contactsMenu.add(showHideMenu); showHideMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showEmptyGroups(showHideMenu.isSelected()); } }); // Initialize vcard support SparkManager.getVCardManager(); }
privatevoidaddContactListToWorkspace(){Workspaceworkspace=SparkManager.getWorkspace();workspace.getWorkspacePane().addTab("Contacts",SparkRes.getImageIcon(SparkRes.SMALL_ALL_CHATS_IMAGE),this);//NOTRANS//AddToContactsMenufinalJMenucontactsMenu=SparkManager.getMainWindow().getMenuByName("Contacts");JMenuItemaddContactsMenu=newJMenuItem("",SparkRes.getImageIcon(SparkRes.USER1_ADD_16x16));ResourceUtils.resButton(addContactsMenu,"&AddContact");ResourceUtils.resButton(addContactGroupMenu,"AddContact&Group");contactsMenu.add(addContactsMenu);contactsMenu.add(addContactGroupMenu);addContactsMenu.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){newRosterDialog().showRosterDialog();}});addContactGroupMenu.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){StringgroupName=JOptionPane.showInputDialog(getGUI(),"NameofGroup:","AddNewGroup",JOptionPane.QUESTION_MESSAGE);if(ModelUtil.hasLength(groupName)){ContactGroupcontactGroup=getContactGroup(groupName);if(contactGroup==null){contactGroup=addContactGroup(groupName);}}}});//AddToggleContactsMenuResourceUtils.resButton(showHideMenu,"&ShowEmptyGroups");contactsMenu.add(showHideMenu);showHideMenu.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){showEmptyGroups(showHideMenu.isSelected());}});//InitializevcardsupportSparkManager.getVCardManager();}
3,228,782
public void actionPerformed(ActionEvent e) { String groupName = JOptionPane.showInputDialog(getGUI(), "Name of Group:", "Add New Group", JOptionPane.QUESTION_MESSAGE); if (ModelUtil.hasLength(groupName)) { ContactGroup contactGroup = getContactGroup(groupName); if (contactGroup == null) { contactGroup = addContactGroup(groupName); } } }
publicvoidactionPerformed(ActionEvente){StringgroupName=JOptionPane.showInputDialog(getGUI(),"NameofGroup:","AddNewGroup",JOptionPane.QUESTION_MESSAGE);if(ModelUtil.hasLength(groupName)){ContactGroupcontactGroup=getContactGroup(groupName);if(contactGroup==null){contactGroup=addContactGroup(groupName);}}}
3,228,784
private void addUser(RosterEntry entry) { String name = entry.getName(); if (!ModelUtil.hasLength(name)) { name = entry.getUser(); } String nickname = entry.getName(); if (!ModelUtil.hasLength(nickname)) { nickname = entry.getUser(); } ContactItem newContactItem = new ContactItem(nickname, entry.getUser()); // Update users icon Presence presence = SparkManager.getConnection().getRoster().getPresence(entry.getUser()); newContactItem.setPresence(presence); if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)) { // Ignore, since the new user is pending to be added. for(RosterGroup group : entry.getGroups()){ ContactGroup contactGroup = getContactGroup(group.getName()); if (contactGroup == null) { contactGroup = addContactGroup(group.getName()); } contactGroup.addContactItem(newContactItem); } return; } else { offlineGroup.addContactItem(newContactItem); } if (presence != null) { updateUserPresence(presence); } }
private void addUser(RosterEntry entry) { String name = entry.getName(); if (!ModelUtil.hasLength(name)) { name = entry.getUser(); } String nickname = entry.getName(); if (!ModelUtil.hasLength(nickname)) { nickname = entry.getUser(); } ContactItem newContactItem = new ContactItem(nickname, entry.getUser()); // Update users icon Presence presence = SparkManager.getConnection().getRoster().getPresence(entry.getUser()); newContactItem.setPresence(presence); if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)) { // Ignore, since the new user is pending to be added. for (RosterGroup group : entry.getGroups()) { ContactGroup contactGroup = getContactGroup(group.getName()); if (contactGroup == null) { contactGroup = addContactGroup(group.getName()); } contactGroup.addContactItem(newContactItem); } return; } else { offlineGroup.addContactItem(newContactItem); } if (presence != null) { updateUserPresence(presence); } }
3,228,786
private void buildContactList() { XMPPConnection con = SparkManager.getConnection(); final Roster roster = con.getRoster(); roster.addRosterListener(this); for(RosterGroup group : roster.getGroups()){ ContactGroup contactGroup = addContactGroup(group.getName()); for(RosterEntry entry : group.getEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); contactItem.setPresence(null); if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Add to contact group. contactGroup.addContactItem(contactItem); contactGroup.setVisible(true); } else { if (offlineGroup.getContactItemByJID(entry.getUser()) == null) { offlineGroup.addContactItem(contactItem); } } } } // Add Unfiled Group // addContactGroup(unfiledGroup); for(RosterEntry entry : roster.getUnfiledEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); offlineGroup.addContactItem(contactItem); } unfiledGroup.setVisible(false); }
private void buildContactList() { XMPPConnection con = SparkManager.getConnection(); final Roster roster = con.getRoster(); roster.addRosterListener(this); for (RosterGroup group : roster.getGroups()) { ContactGroup contactGroup = addContactGroup(group.getName()); for(RosterEntry entry : group.getEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); contactItem.setPresence(null); if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Add to contact group. contactGroup.addContactItem(contactItem); contactGroup.setVisible(true); } else { if (offlineGroup.getContactItemByJID(entry.getUser()) == null) { offlineGroup.addContactItem(contactItem); } } } } // Add Unfiled Group // addContactGroup(unfiledGroup); for(RosterEntry entry : roster.getUnfiledEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); offlineGroup.addContactItem(contactItem); } unfiledGroup.setVisible(false); }
3,228,787
private void buildContactList() { XMPPConnection con = SparkManager.getConnection(); final Roster roster = con.getRoster(); roster.addRosterListener(this); for(RosterGroup group : roster.getGroups()){ ContactGroup contactGroup = addContactGroup(group.getName()); for(RosterEntry entry : group.getEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); contactItem.setPresence(null); if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Add to contact group. contactGroup.addContactItem(contactItem); contactGroup.setVisible(true); } else { if (offlineGroup.getContactItemByJID(entry.getUser()) == null) { offlineGroup.addContactItem(contactItem); } } } } // Add Unfiled Group // addContactGroup(unfiledGroup); for(RosterEntry entry : roster.getUnfiledEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); offlineGroup.addContactItem(contactItem); } unfiledGroup.setVisible(false); }
private void buildContactList() { XMPPConnection con = SparkManager.getConnection(); final Roster roster = con.getRoster(); roster.addRosterListener(this); for(RosterGroup group : roster.getGroups()){ ContactGroup contactGroup = addContactGroup(group.getName()); for (RosterEntry entry : group.getEntries()) { String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); contactItem.setPresence(null); if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Add to contact group. contactGroup.addContactItem(contactItem); contactGroup.setVisible(true); } else { if (offlineGroup.getContactItemByJID(entry.getUser()) == null) { offlineGroup.addContactItem(contactItem); } } } } // Add Unfiled Group // addContactGroup(unfiledGroup); for(RosterEntry entry : roster.getUnfiledEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); offlineGroup.addContactItem(contactItem); } unfiledGroup.setVisible(false); }
3,228,788
private void buildContactList() { XMPPConnection con = SparkManager.getConnection(); final Roster roster = con.getRoster(); roster.addRosterListener(this); for(RosterGroup group : roster.getGroups()){ ContactGroup contactGroup = addContactGroup(group.getName()); for(RosterEntry entry : group.getEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); contactItem.setPresence(null); if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Add to contact group. contactGroup.addContactItem(contactItem); contactGroup.setVisible(true); } else { if (offlineGroup.getContactItemByJID(entry.getUser()) == null) { offlineGroup.addContactItem(contactItem); } } } } // Add Unfiled Group // addContactGroup(unfiledGroup); for(RosterEntry entry : roster.getUnfiledEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); offlineGroup.addContactItem(contactItem); } unfiledGroup.setVisible(false); }
private void buildContactList() { XMPPConnection con = SparkManager.getConnection(); final Roster roster = con.getRoster(); roster.addRosterListener(this); for(RosterGroup group : roster.getGroups()){ ContactGroup contactGroup = addContactGroup(group.getName()); for(RosterEntry entry : group.getEntries()){ String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); contactItem.setPresence(null); if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Add to contact group. contactGroup.addContactItem(contactItem); contactGroup.setVisible(true); } else { if (offlineGroup.getContactItemByJID(entry.getUser()) == null) { offlineGroup.addContactItem(contactItem); } } } } // Add Unfiled Group // addContactGroup(unfiledGroup); for (RosterEntry entry : roster.getUnfiledEntries()) { String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); offlineGroup.addContactItem(contactItem); } unfiledGroup.setVisible(false); }
3,228,789
private void changeOfflineToOnline(String bareJID, final RosterEntry entry, Presence presence) { // Move out of offline group. Add to all groups. ContactItem offlineItem = offlineGroup.getContactItemByJID(bareJID); if (offlineItem == null) { return; } offlineGroup.removeContactItem(offlineItem); // Add To all groups it belongs to. boolean isFiled = false; for(RosterGroup rosterGroup : entry.getGroups()){ isFiled = true; ContactGroup contactGroup = getContactGroup(rosterGroup.getName()); if (contactGroup != null) { String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = null; if (contactGroup.getContactItemByJID(entry.getUser()) == null) { contactItem = new ContactItem(name, entry.getUser()); contactGroup.addContactItem(contactItem); } else if (contactGroup.getContactItemByJID(entry.getUser()) != null) { // If the user is in their, but without a nice presence. contactItem = contactGroup.getContactItemByJID(entry.getUser()); } contactItem.setPresence(presence); contactItem.setAvailable(true); toggleGroupVisibility(contactGroup.getGroupName(), true); contactItem.showUserComingOnline(); contactGroup.fireContactGroupUpdated(); int numberOfMillisecondsInTheFuture = 5000; Date timeToRun = new Date(System.currentTimeMillis() + numberOfMillisecondsInTheFuture); Timer timer = new Timer(); final ContactItem staticItem = contactItem; final ContactGroup staticGroup = contactGroup; timer.schedule(new TimerTask() { public void run() { staticItem.updatePresenceIcon(staticItem.getPresence()); staticGroup.fireContactGroupUpdated(); } }, timeToRun); } } if (!isFiled) { String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); unfiledGroup.addContactItem(contactItem); contactItem.setPresence(presence); contactItem.setAvailable(true); unfiledGroup.setVisible(true); unfiledGroup.fireContactGroupUpdated(); } }
private void changeOfflineToOnline(String bareJID, final RosterEntry entry, Presence presence) { // Move out of offline group. Add to all groups. ContactItem offlineItem = offlineGroup.getContactItemByJID(bareJID); if (offlineItem == null) { return; } offlineGroup.removeContactItem(offlineItem); // Add To all groups it belongs to. boolean isFiled = false; for (RosterGroup rosterGroup : entry.getGroups()) { isFiled = true; ContactGroup contactGroup = getContactGroup(rosterGroup.getName()); if (contactGroup != null) { String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = null; if (contactGroup.getContactItemByJID(entry.getUser()) == null) { contactItem = new ContactItem(name, entry.getUser()); contactGroup.addContactItem(contactItem); } else if (contactGroup.getContactItemByJID(entry.getUser()) != null) { // If the user is in their, but without a nice presence. contactItem = contactGroup.getContactItemByJID(entry.getUser()); } contactItem.setPresence(presence); contactItem.setAvailable(true); toggleGroupVisibility(contactGroup.getGroupName(), true); contactItem.showUserComingOnline(); contactGroup.fireContactGroupUpdated(); int numberOfMillisecondsInTheFuture = 5000; Date timeToRun = new Date(System.currentTimeMillis() + numberOfMillisecondsInTheFuture); Timer timer = new Timer(); final ContactItem staticItem = contactItem; final ContactGroup staticGroup = contactGroup; timer.schedule(new TimerTask() { public void run() { staticItem.updatePresenceIcon(staticItem.getPresence()); staticGroup.fireContactGroupUpdated(); } }, timeToRun); } } if (!isFiled) { String name = entry.getName(); if (name == null) { name = entry.getUser(); } ContactItem contactItem = new ContactItem(name, entry.getUser()); unfiledGroup.addContactItem(contactItem); contactItem.setPresence(presence); contactItem.setAvailable(true); unfiledGroup.setVisible(true); unfiledGroup.fireContactGroupUpdated(); } }
3,228,790
public void clientReconnected() { XMPPConnection con = SparkManager.getConnection(); if (con.isConnected()) { // Send Available status final Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence(); SparkManager.getSessionManager().changePresence(presence); final Roster roster = con.getRoster(); for(RosterEntry entry : roster.getEntries()){ updateUserPresence(roster.getPresence(entry.getUser())); } } workspace.changeCardLayout(Workspace.WORKSPACE_PANE); }
public void clientReconnected() { XMPPConnection con = SparkManager.getConnection(); if (con.isConnected()) { // Send Available status final Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence(); SparkManager.getSessionManager().changePresence(presence); final Roster roster = con.getRoster(); for (RosterEntry entry : roster.getEntries()) { updateUserPresence(roster.getPresence(entry.getUser())); } } workspace.changeCardLayout(Workspace.WORKSPACE_PANE); }
3,228,791
public void contactGroupPopup(MouseEvent e, final ContactGroup group) { // Do nothing with offline group if (group == offlineGroup || group == unfiledGroup) { return; } final JPopupMenu popup = new JPopupMenu(); popup.add(addContactMenu); popup.add(addContactGroupMenu); popup.addSeparator(); fireContextMenuListenerPopup(popup, group); JMenuItem delete = new JMenuItem("Delete"); JMenuItem rename = new JMenuItem("Rename"); if (!group.isSharedGroup()) { popup.addSeparator(); popup.add(delete); popup.add(rename); } delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int ok = JOptionPane.showConfirmDialog(group, "Are you sure you want to delete \"" + group.getGroupName() + "\"", "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { String groupName = group.getGroupName(); Roster roster = SparkManager.getConnection().getRoster(); RosterGroup rosterGroup = roster.getGroup(groupName); if (rosterGroup != null) { for(RosterEntry entry : rosterGroup.getEntries()){ try { rosterGroup.removeEntry(entry); } catch (XMPPException e1) { Log.error("Error removing entry", e1); } } } // Remove from UI removeContactGroup(group); invalidate(); repaint(); } } }); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newName = JOptionPane.showInputDialog(group, "Rename Roster Group", "Rename to:", JOptionPane.QUESTION_MESSAGE); if (!ModelUtil.hasLength(newName)) { return; } String groupName = group.getGroupName(); Roster roster = SparkManager.getConnection().getRoster(); RosterGroup rosterGroup = roster.getGroup(groupName); if (rosterGroup != null) { removeContactGroup(group); rosterGroup.setName(newName); } } }); // popup.add(inviteFirstAcceptor); popup.show(group, e.getX(), e.getY()); activeGroup = group; }
public void contactGroupPopup(MouseEvent e, final ContactGroup group) { // Do nothing with offline group if (group == offlineGroup || group == unfiledGroup) { return; } final JPopupMenu popup = new JPopupMenu(); popup.add(addContactMenu); popup.add(addContactGroupMenu); popup.addSeparator(); fireContextMenuListenerPopup(popup, group); JMenuItem delete = new JMenuItem("Delete"); JMenuItem rename = new JMenuItem("Rename"); if (!group.isSharedGroup()) { popup.addSeparator(); popup.add(delete); popup.add(rename); } delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int ok = JOptionPane.showConfirmDialog(group, "Are you sure you want to delete \"" + group.getGroupName() + "\"", "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { String groupName = group.getGroupName(); Roster roster = SparkManager.getConnection().getRoster(); RosterGroup rosterGroup = roster.getGroup(groupName); if (rosterGroup != null) { for (RosterEntry entry : rosterGroup.getEntries()) { try { rosterGroup.removeEntry(entry); } catch (XMPPException e1) { Log.error("Error removing entry", e1); } } } // Remove from UI removeContactGroup(group); invalidate(); repaint(); } } }); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newName = JOptionPane.showInputDialog(group, "Rename Roster Group", "Rename to:", JOptionPane.QUESTION_MESSAGE); if (!ModelUtil.hasLength(newName)) { return; } String groupName = group.getGroupName(); Roster roster = SparkManager.getConnection().getRoster(); RosterGroup rosterGroup = roster.getGroup(groupName); if (rosterGroup != null) { removeContactGroup(group); rosterGroup.setName(newName); } } }); // popup.add(inviteFirstAcceptor); popup.show(group, e.getX(), e.getY()); activeGroup = group; }
3,228,792
public void actionPerformed(ActionEvent e) { int ok = JOptionPane.showConfirmDialog(group, "Are you sure you want to delete \"" + group.getGroupName() + "\"", "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { String groupName = group.getGroupName(); Roster roster = SparkManager.getConnection().getRoster(); RosterGroup rosterGroup = roster.getGroup(groupName); if (rosterGroup != null) { for(RosterEntry entry : rosterGroup.getEntries()){ try { rosterGroup.removeEntry(entry); } catch (XMPPException e1) { Log.error("Error removing entry", e1); } } } // Remove from UI removeContactGroup(group); invalidate(); repaint(); } }
public void actionPerformed(ActionEvent e) { int ok = JOptionPane.showConfirmDialog(group, "Are you sure you want to delete \"" + group.getGroupName() + "\"", "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { String groupName = group.getGroupName(); Roster roster = SparkManager.getConnection().getRoster(); RosterGroup rosterGroup = roster.getGroup(groupName); if (rosterGroup != null) { for (RosterEntry entry : rosterGroup.getEntries()) { try { rosterGroup.removeEntry(entry); } catch (XMPPException e1) { Log.error("Error removing entry", e1); } } } // Remove from UI removeContactGroup(group); invalidate(); repaint(); } }
3,228,793
public void entriesUpdated(final Collection addresses) { SwingUtilities.invokeLater(new Runnable() { public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for(RosterGroup g : rosterEntry.getGroups()){ groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } } }); }
public void entriesUpdated(final Collection addresses) { SwingUtilities.invokeLater(new Runnable() { public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for(RosterGroup g : rosterEntry.getGroups()){ groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } } }); }
3,228,794
public void entriesUpdated(final Collection addresses) { SwingUtilities.invokeLater(new Runnable() { public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for(RosterGroup g : rosterEntry.getGroups()){ groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } } }); }
public void entriesUpdated(final Collection addresses) { SwingUtilities.invokeLater(new Runnable() { public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for (RosterGroup g : rosterEntry.getGroups()) { groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } } }); }
3,228,795
public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for(RosterGroup g : rosterEntry.getGroups()){ groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } }
public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for(RosterGroup g : rosterEntry.getGroups()){ groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } }
3,228,796
public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for(RosterGroup g : rosterEntry.getGroups()){ groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } }
public void run() { Roster roster = SparkManager.getConnection().getRoster(); Iterator jids = addresses.iterator(); while (jids.hasNext()) { String jid = (String)jids.next(); RosterEntry rosterEntry = roster.getEntry(jid); if (rosterEntry != null) { // Check for new Roster Groups and add them if they do not exist. boolean isUnfiled = true; for(RosterGroup group : rosterEntry.getGroups()){ isUnfiled = false; // Handle if this is a new Entry in a new Group. if (getContactGroup(group.getName()) == null) { // Create group. ContactGroup contactGroup = addContactGroup(group.getName()); contactGroup.setVisible(false); contactGroup = getContactGroup(group.getName()); String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } ContactItem contactItem = new ContactItem(name, rosterEntry.getUser()); contactGroup.addContactItem(contactItem); Presence presence = roster.getPresence(jid); contactItem.setPresence(presence); if (presence != null) { contactGroup.setVisible(true); } } else { ContactGroup contactGroup = getContactGroup(group.getName()); ContactItem item = contactGroup.getContactItemByJID(jid); // Check to see if this entry is new to a pre-existing group. if (item == null) { String name = rosterEntry.getName(); if (name == null) { name = rosterEntry.getUser(); } item = new ContactItem(name, rosterEntry.getUser()); Presence presence = roster.getPresence(jid); item.setPresence(presence); if (presence != null) { contactGroup.addContactItem(item); contactGroup.fireContactGroupUpdated(); } } // If not, just update their presence. else { Presence presence = roster.getPresence(jid); item.setPresence(presence); updateUserPresence(presence); contactGroup.fireContactGroupUpdated(); } } } // Now check to see if groups have been modified or removed. This is used // to check if Contact Groups have been renamed or removed. Set groupSet = new HashSet(); jids = addresses.iterator(); while (jids.hasNext()) { jid = (String)jids.next(); rosterEntry = roster.getEntry(jid); for (RosterGroup g : rosterEntry.getGroups()) { groupSet.add(g.getName()); } for (ContactGroup group : new ArrayList<ContactGroup>(getContactGroups())) { if (group.getContactItemByJID(jid) != null && group != unfiledGroup && group != offlineGroup) { if (!groupSet.contains(group.getGroupName())) { removeContactGroup(group); } } } } if (!isUnfiled) { return; } ContactItem unfiledItem = unfiledGroup.getContactItemByJID(jid); if (unfiledItem != null) { } else { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { // Remove from offlineItem and add to unfiledItem. offlineGroup.removeContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem); unfiledGroup.fireContactGroupUpdated(); unfiledGroup.setVisible(true); } } } } } }
3,228,797
public RosterDialog() { contactList = SparkManager.getWorkspace().getContactList(); panel = new JPanel(); JLabel contactIDLabel = new JLabel(); jidField = new JTextField(); JLabel nicknameLabel = new JLabel(); nicknameField = new JTextField(); JLabel groupLabel = new JLabel(); groupBox = new JComboBox(groupModel); JButton newGroupButton = new JButton(); JLabel accountsLabel = new JLabel(); accounts = new JComboBox(); publicBox = new JCheckBox(Res.getString("label.user.on.public.network")); ResourceUtils.resLabel(accountsLabel, publicBox, Res.getString("label.network")); pane = null; dialog = null; panel.setLayout(new GridBagLayout()); panel.add(contactIDLabel, new GridBagConstraints(0, 0, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(jidField, new GridBagConstraints(1, 0, 1, 1, 1.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(nicknameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(nicknameField, new GridBagConstraints(1, 1, 1, 1, 1.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); ComponentTitledBorder componentBorder = new ComponentTitledBorder(publicBox, networkPanel , BorderFactory.createEtchedBorder()); networkPanel.add(accountsLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); networkPanel.add(accounts, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); networkPanel.setBorder(componentBorder); networkPanel.setVisible(false); accounts.setEnabled(false); panel.add(groupLabel, new GridBagConstraints(0, 4, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(groupBox, new GridBagConstraints(1, 4, 1, 1, 1.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(newGroupButton, new GridBagConstraints(2, 4, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); newGroupButton.addActionListener(this); panel.add(networkPanel, new GridBagConstraints(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); ResourceUtils.resLabel(contactIDLabel, jidField, Res.getString("label.username") + ":"); ResourceUtils.resLabel(nicknameLabel, nicknameField, Res.getString("label.nickname") + ":"); ResourceUtils.resLabel(groupLabel, groupBox, Res.getString("label.group") + ":"); ResourceUtils.resButton(newGroupButton, Res.getString("button.new")); accounts.setRenderer(new JPanelRenderer()); for (ContactGroup group : contactList.getContactGroups()) { if (!group.isOfflineGroup() && !"Unfiled".equalsIgnoreCase(group.getGroupName()) && !group.isSharedGroup()) { groupModel.add(group.getGroupName()); } } groupBox.setEditable(true); if (groupModel.size() == 0) { groupBox.addItem("Friends"); } if (groupModel.size() > 0) { groupBox.setSelectedIndex(0); } jidField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { String jid = jidField.getText(); String nickname = nicknameField.getText(); if (!ModelUtil.hasLength(nickname) && ModelUtil.hasLength(jid)) { nickname = StringUtils.parseName(jid); if (!ModelUtil.hasLength(nickname)) { nickname = jid; } nicknameField.setText(nickname); } } }); final List<AccountItem> accountCol = getAccounts(); for (AccountItem item : accountCol) { accounts.addItem(item); } if (accountCol.size() > 0) { accountsLabel.setVisible(true); accounts.setVisible(true); publicBox.setVisible(true); networkPanel.setVisible(true); } publicBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { accounts.setEnabled(publicBox.isSelected()); } }); }
public RosterDialog() { contactList = SparkManager.getWorkspace().getContactList(); panel = new JPanel(); JLabel contactIDLabel = new JLabel(); jidField = new JTextField(); JLabel nicknameLabel = new JLabel(); nicknameField = new JTextField(); JLabel groupLabel = new JLabel(); groupBox = new JComboBox(groupModel); JButton newGroupButton = new JButton(); JLabel accountsLabel = new JLabel(); accounts = new JComboBox(); publicBox = new JCheckBox(Res.getString("label.user.on.public.network")); ResourceUtils.resLabel(accountsLabel, publicBox, Res.getString("label.network")); pane = null; dialog = null; panel.setLayout(new GridBagLayout()); panel.add(contactIDLabel, new GridBagConstraints(0, 0, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(jidField, new GridBagConstraints(1, 0, 1, 1, 1.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(nicknameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(nicknameField, new GridBagConstraints(1, 1, 1, 1, 1.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); ComponentTitledBorder componentBorder = new ComponentTitledBorder(publicBox, networkPanel , BorderFactory.createEtchedBorder()); networkPanel.add(accountsLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); networkPanel.add(accounts, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); networkPanel.setBorder(componentBorder); networkPanel.setVisible(false); accounts.setEnabled(false); panel.add(groupLabel, new GridBagConstraints(0, 4, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(groupBox, new GridBagConstraints(1, 4, 1, 1, 1.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); panel.add(newGroupButton, new GridBagConstraints(2, 4, 1, 1, 0.0D, 0.0D, 17, 2, new Insets(5, 5, 5, 5), 0, 0)); newGroupButton.addActionListener(this); panel.add(networkPanel, new GridBagConstraints(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); ResourceUtils.resLabel(contactIDLabel, jidField, Res.getString("label.username") + ":"); ResourceUtils.resLabel(nicknameLabel, nicknameField, Res.getString("label.nickname") + ":"); ResourceUtils.resLabel(groupLabel, groupBox, Res.getString("label.group") + ":"); ResourceUtils.resButton(newGroupButton, Res.getString("button.new")); accounts.setRenderer(new JPanelRenderer()); for (ContactGroup group : contactList.getContactGroups()) { if (!group.isOfflineGroup() && !"Unfiled".equalsIgnoreCase(group.getGroupName()) && !group.isSharedGroup()) { groupModel.add(group.getGroupName()); } } groupBox.setEditable(true); if (groupModel.size() == 0) { groupBox.addItem("Friends"); } if (groupModel.size() > 0) { groupBox.setSelectedIndex(0); } jidField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { String jid = jidField.getText(); String nickname = nicknameField.getText(); if (!ModelUtil.hasLength(nickname) && ModelUtil.hasLength(jid)) { nickname = StringUtils.parseName(jid); if (!ModelUtil.hasLength(nickname)) { nickname = jid; } nicknameField.setText(nickname); } } }); final List<AccountItem> accountCol = getAccounts(); for (AccountItem item : accountCol) { accounts.addItem(item); } if (accountCol.size() > 0) { accountsLabel.setVisible(true); accounts.setVisible(true); publicBox.setVisible(true); networkPanel.setVisible(true); } publicBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { accounts.setEnabled(publicBox.isSelected()); } }); }
3,228,798
public void showRosterDialog() { showRosterDialog(SparkManager.getMainWindow()); }
public void showRosterDialog() { showRosterDialog(SparkManager.getMainWindow()); }
3,228,799
public void updatePresenceIcon(Presence presence) { ChatManager chatManager = SparkManager.getChatManager(); boolean handled = chatManager.fireContactItemPresenceChanged(this, presence); if (handled) { return; } String status = presence != null ? presence.getStatus() : null; Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL); boolean isAvailable = false; if (status == null && presence != null) { Presence.Mode mode = presence.getMode(); if (mode == Presence.Mode.available) { status = "Available"; isAvailable = true; } else if (mode == Presence.Mode.away) { status = "I'm away"; statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } else if (mode == Presence.Mode.chat) { status = "I'm free to chat"; } else if (mode == Presence.Mode.dnd) { status = "Do not disturb"; statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } else if (mode == Presence.Mode.xa) { status = "Extended away"; statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } } else if (presence != null && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) { statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } else if (presence != null && presence.getType() == Presence.Type.available) { isAvailable = true; } else if (presence == null) { getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); getNicknameLabel().setForeground((Color)UIManager.get("ContactItemOffline.color")); RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getFullJID()); if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Do not move out of group. setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION)); getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); setStatusText("Pending"); } else { setIcon(null); setFont(new Font("Dialog", Font.PLAIN, 11)); getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); setAvailable(false); setStatusText(""); } sideIcon.setIcon(null); setAvailable(false); return; } StatusItem statusItem = SparkManager.getWorkspace().getStatusBar().getItemFromPresence(presence); if (statusItem != null) { setIcon(statusItem.getIcon()); } else { setIcon(statusIcon); } if (status != null) { setStatus(status); } if (status != null && status.indexOf("phone") != -1) { statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE); setIcon(statusIcon); } // Always change nickname label to black. getNicknameLabel().setForeground((Color)UIManager.get("ContactItemNickname.foreground")); if (isAvailable) { getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); if ("Online".equals(status) || "Available".equalsIgnoreCase(status)) { setStatusText(""); } else { setStatusText(status); } } else if (presence != null) { getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, 11)); getNicknameLabel().setForeground(Color.gray); if (status != null) { setStatusText(status); } } setAvailable(true); }
public void updatePresenceIcon(Presence presence) { ChatManager chatManager = SparkManager.getChatManager(); boolean handled = chatManager.fireContactItemPresenceChanged(this, presence); if (handled) { return; } String status = presence != null ? presence.getStatus() : null; Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL); boolean isAvailable = false; if (status == null && presence != null) { Presence.Mode mode = presence.getMode(); if (mode == Presence.Mode.available) { status = "Available"; isAvailable = true; } else if (mode == Presence.Mode.away) { status = "I'm away"; statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } else if (mode == Presence.Mode.chat) { status = "I'm free to chat"; } else if (mode == Presence.Mode.dnd) { status = "Do not disturb"; statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } else if (mode == Presence.Mode.xa) { status = "Extended away"; statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } } else if (presence != null && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) { statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); } else if (presence != null && presence.getType() == Presence.Type.available) { isAvailable = true; } else if (presence == null) { getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); getNicknameLabel().setForeground((Color)UIManager.get("ContactItemOffline.color")); RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getFullJID()); if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { // Do not move out of group. setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION)); getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); setStatusText("Pending"); } else { setIcon(null); setFont(new Font("Dialog", Font.PLAIN, 11)); getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); setAvailable(false); setStatusText(""); } sideIcon.setIcon(null); setAvailable(false); return; } StatusItem statusItem = SparkManager.getWorkspace().getStatusBar().getItemFromPresence(presence); if (statusItem != null) { setIcon(statusItem.getIcon()); } else { setIcon(statusIcon); } if (status != null) { setStatus(status); } if (status != null && status.toLowerCase().indexOf("phone") != -1) { statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE); setIcon(statusIcon); } // Always change nickname label to black. getNicknameLabel().setForeground((Color)UIManager.get("ContactItemNickname.foreground")); if (isAvailable) { getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); if ("Online".equals(status) || "Available".equalsIgnoreCase(status)) { setStatusText(""); } else { setStatusText(status); } } else if (presence != null) { getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, 11)); getNicknameLabel().setForeground(Color.gray); if (status != null) { setStatusText(status); } } setAvailable(true); }
3,228,800
public List findAll(final Class klass, final Filter filter) { if ( filter == null ) return getHibernateTemplate().loadAll( klass ); return (List) getHibernateTemplate().execute( new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); return c.list(); } }); }
public <T extends IObject> List<T> findAll(final Class<T> klass, final Filter filter) { if ( filter == null ) return getHibernateTemplate().loadAll( klass ); return (List) getHibernateTemplate().execute( new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); return c.list(); } }); }
3,228,802
public List findAll(final Class klass, final Filter filter) { if ( filter == null ) return getHibernateTemplate().loadAll( klass ); return (List) getHibernateTemplate().execute( new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); return c.list(); } }); }
public List findAll(final Class klass, final Filter filter) { if ( filter == null ) return getHibernateTemplate().loadAll( klass ); return (List<T>) getHibernateTemplate().execute( new HibernateCallback(){ public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); return c.list(); } }); }
3,228,803
public List findAllByExample(final IObject example, final Filter filter) { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); parseFilter(c,filter); return c.list(); } }); }
public <T extends IObject> List<T> findAllByExample(final T example, final Filter filter) { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); parseFilter(c,filter); return c.list(); } }); }
3,228,804
public List findAllByExample(final IObject example, final Filter filter) { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); parseFilter(c,filter); return c.list(); } }); }
public List findAllByExample(final IObject example, final Filter filter) { return (List<T>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); parseFilter(c,filter); return c.list(); } }); }
3,228,805
public List findAllByQuery(String queryName, Parameters params) { Query<List> q = queryFactory.lookup( queryName, params ); return execute(q); }
public <T extends IObject> List<T> findAllByQuery(String queryName, Parameters params) { Query<List> q = queryFactory.lookup( queryName, params ); return execute(q); }
3,228,806
public List findAllByQuery(String queryName, Parameters params) { Query<List> q = queryFactory.lookup( queryName, params ); return execute(q); }
public List findAllByQuery(String queryName, Parameters params) { Query<List<T>> q = queryFactory.lookup( queryName, params ); return execute(q); }
3,228,807
public List findAllByString( final Class klass, final String fieldName, final String value, final boolean caseSensitive, final Filter filter) throws ApiUsageException { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); if (caseSensitive) c.add(Expression.like(fieldName,value,MatchMode.ANYWHERE)); else c.add(Expression.ilike(fieldName,value,MatchMode.ANYWHERE)); return c.list(); } }); }
public List findAllByString( final Class klass, final String fieldName, final String value, final boolean caseSensitive, final Filter filter) throws ApiUsageException { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); if (caseSensitive) c.add(Expression.like(fieldName,value,MatchMode.ANYWHERE)); else c.add(Expression.ilike(fieldName,value,MatchMode.ANYWHERE)); return c.list(); } }); }
3,228,808
public List findAllByString( final Class klass, final String fieldName, final String value, final boolean caseSensitive, final Filter filter) throws ApiUsageException { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); if (caseSensitive) c.add(Expression.like(fieldName,value,MatchMode.ANYWHERE)); else c.add(Expression.ilike(fieldName,value,MatchMode.ANYWHERE)); return c.list(); } }); }
public List findAllByString( final Class klass, final String fieldName, final String value, final boolean caseSensitive, final Filter filter) throws ApiUsageException { return (List<T>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); parseFilter( c,filter ); if (caseSensitive) c.add(Expression.like(fieldName,value,MatchMode.ANYWHERE)); else c.add(Expression.ilike(fieldName,value,MatchMode.ANYWHERE)); return c.list(); } }); }
3,228,809
public IObject findByExample(final IObject example) throws ApiUsageException { return (IObject) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); return c.uniqueResult(); } }); }
public <T extends IObject> T findByExample(final T example) throws ApiUsageException { return (IObject) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); return c.uniqueResult(); } }); }
3,228,810
public IObject findByExample(final IObject example) throws ApiUsageException { return (IObject) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); return c.uniqueResult(); } }); }
public IObject findByExample(final IObject example) throws ApiUsageException { return (T) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(example.getClass()); c.add(Example.create(example)); return c.uniqueResult(); } }); }
3,228,811
public IObject findByQuery(String queryName, Parameters params) throws ValidationException { if ( params == null ) { params = new Parameters(); } // specify that we should only return a single value if possible params.getFilter().unique(); Query<IObject> q = queryFactory.lookup( queryName, params ); IObject result = null; try { result = execute(q); } catch (ClassCastException cce) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned an Object of type "+cce.getMessage()+"\n" + "Queries must return IObjects when using findByQuery. \n" + "Please try findAllByQuery for queries which return Lists." ); } catch (NonUniqueResultException nure) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned more than one Object\n" + "findByQuery must return a single value.\n" + "Please try findAllByQuery for queries which return Lists." ); } return result; }
public <T extends IObject> T findByQuery(String queryName, Parameters params) throws ValidationException { if ( params == null ) { params = new Parameters(); } // specify that we should only return a single value if possible params.getFilter().unique(); Query<IObject> q = queryFactory.lookup( queryName, params ); IObject result = null; try { result = execute(q); } catch (ClassCastException cce) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned an Object of type "+cce.getMessage()+"\n" + "Queries must return IObjects when using findByQuery. \n" + "Please try findAllByQuery for queries which return Lists." ); } catch (NonUniqueResultException nure) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned more than one Object\n" + "findByQuery must return a single value.\n" + "Please try findAllByQuery for queries which return Lists." ); } return result; }
3,228,812
public IObject findByQuery(String queryName, Parameters params) throws ValidationException { if ( params == null ) { params = new Parameters(); } // specify that we should only return a single value if possible params.getFilter().unique(); Query<IObject> q = queryFactory.lookup( queryName, params ); IObject result = null; try { result = execute(q); } catch (ClassCastException cce) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned an Object of type "+cce.getMessage()+"\n" + "Queries must return IObjects when using findByQuery. \n" + "Please try findAllByQuery for queries which return Lists." ); } catch (NonUniqueResultException nure) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned more than one Object\n" + "findByQuery must return a single value.\n" + "Please try findAllByQuery for queries which return Lists." ); } return result; }
public IObject findByQuery(String queryName, Parameters params) throws ValidationException { if ( params == null ) { params = new Parameters(); } // specify that we should only return a single value if possible params.getFilter().unique(); Query<IObject> q = queryFactory.lookup( queryName, params ); IObject result = null; try { result = execute(q); } catch (ClassCastException cce) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned an Object of type "+cce.getMessage()+"\n" + "Queries must return IObjects when using findByQuery. \n" + "Please try findAllByQuery for queries which return Lists." ); } catch (NonUniqueResultException nure) { throw new ApiUsageException( "Query named:\n\t"+queryName+"\n" + "has returned more than one Object\n" + "findByQuery must return a single value.\n" + "Please try findAllByQuery for queries which return Lists." ); } return result; }
3,228,813
public IObject findByString( final Class klass, final String fieldName, final String value) throws ApiUsageException { return (IObject) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); c.add(Expression.like(fieldName,value)); return c.uniqueResult(); } }); }
public IObject findByString( final Class klass, final String fieldName, final String value) throws ApiUsageException { return (IObject) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); c.add(Expression.like(fieldName,value)); return c.uniqueResult(); } }); }
3,228,814
public IObject findByString( final Class klass, final String fieldName, final String value) throws ApiUsageException { return (IObject) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); c.add(Expression.like(fieldName,value)); return c.uniqueResult(); } }); }
public IObject findByString( final Class klass, final String fieldName, final String value) throws ApiUsageException { return (T) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria c = session.createCriteria(klass); c.add(Expression.like(fieldName,value)); return c.uniqueResult(); } }); }
3,228,815
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) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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; String lang = null; int opts = iVisited.getOptions(); if((opts & 16) != 0) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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); }
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) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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; String lang = null; int opts = iVisited.getOptions(); if((opts & 16) != 0) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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,228,816
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) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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; String lang = null; int opts = iVisited.getOptions(); if((opts & 16) != 0) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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); }
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) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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; String lang = null; int opts = iVisited.getOptions(); if((opts & 16) != 0) { // param n lang = "n"; } else if((opts & 48) != 0) { // param s lang = "s"; } else if((opts & 64) != 0) { // param s 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,228,817
public void propertyChange(PropertyChangeEvent pce) { String propName = pce.getPropertyName(); if (Browser.POPUP_POINT_PROPERTY.equals(propName)) { Browser browser = model.getBrowser(); ImageDisplay d = browser.getLastSelectedDisplay(); Point p = browser.getPopupPoint(); if (d != null && p != null) view.showPopup(d, p); } else if (Browser.THUMB_SELECTED_PROPERTY.equals(propName)) { ImageNode d = (ImageNode) pce.getNewValue(); if (d != null) ThumbWinManager.display(d, model); } else if (Browser.SELECTED_DISPLAY_PROPERTY.equals(propName)) { TreeView treeView = model.getTreeView(); if (treeView == null) return; ImageDisplay d = model.getBrowser().getLastSelectedDisplay(); treeView.accept(new SelectedNodeVisitor(treeView, d)); } else if (TreeView.TREE_POPUP_POINT_PROPERTY.equals(propName)) { TreeView treeView = model.getTreeView(); if (treeView == null) return; //tree shouldn't be null Point p = treeView.getPopupPoint(); if (p != null) view.showPopup(((JComponent) pce.getNewValue()), p); } else if (TreeView.CLOSE_PROPERTY.equals(propName)) { model.showTreeView(false); } else if (TreeView.TREE_SELECTED_DISPLAY_PROPERTY.equals(propName)) { TreeView treeView = model.getTreeView(); if (treeView == null) return; //tree shouldn't be null Browser browser = model.getBrowser(); ImageDisplay img = (ImageDisplay) pce.getNewValue(); if (img != null) { if (!(img.equals(browser.getLastSelectedDisplay()))) browser.setSelectedDisplay(img); } else browser.setSelectedDisplay(img); } else if (HiViewer.SCROLL_TO_NODE_PROPERTY.equals(propName)) { scrollToNode((ImageDisplay) pce.getNewValue()); } else if (Browser.ANNOTATED_NODE_PROPERTY.equals(propName)) { ImageDisplay n = (ImageDisplay) pce.getNewValue(); model.getClipBoard().setSelectedPane(ClipBoard.ANNOTATION_PANE, n); model.getBrowser().setSelectedDisplay(n); } else if (Browser.CLASSIFIED_NODE_PROPERTY.equals(propName)) { ImageNode n = (ImageNode) pce.getNewValue(); ClassifyCmd cmd = new ClassifyCmd( (ImageData) n.getHierarchyObject(), Classifier.DECLASSIFICATION_MODE, view, model.getUserDetails().getId(), model.getRootID(), model.getRootLevel()); cmd.execute(); } else if (Browser.ROLL_OVER_PROPERTY.equals(propName)) { if (model.isRollOver()) { ImageDisplay n = (ImageDisplay) pce.getNewValue(); if (n instanceof ImageNode) ThumbWinManager.rollOverDisplay((ImageNode) n, model.getBrowser()); else ThumbWinManager.rollOverDisplay(null, model.getBrowser()); } } }
public void propertyChange(PropertyChangeEvent pce) { String propName = pce.getPropertyName(); if (Browser.POPUP_POINT_PROPERTY.equals(propName)) { Browser browser = model.getBrowser(); ImageDisplay d = browser.getLastSelectedDisplay(); Point p = browser.getPopupPoint(); if (d != null && p != null) view.showPopup(d, p); } else if (Browser.THUMB_SELECTED_PROPERTY.equals(propName)) { ImageNode d = (ImageNode) pce.getNewValue(); if (d != null) ThumbWinManager.display(d, model); } else if (Browser.SELECTED_DISPLAY_PROPERTY.equals(propName)) { TreeView treeView = model.getTreeView(); if (treeView == null) return; ImageDisplay d = model.getBrowser().getLastSelectedDisplay(); treeView.accept(new SelectedNodeVisitor(treeView, d)); } else if (TreeView.TREE_POPUP_POINT_PROPERTY.equals(propName)) { TreeView treeView = model.getTreeView(); if (treeView == null) return; //tree shouldn't be null Point p = treeView.getPopupPoint(); if (p != null) view.showPopup(((JComponent) pce.getNewValue()), p); } else if (TreeView.CLOSE_PROPERTY.equals(propName)) { model.showTreeView(false); } else if (TreeView.TREE_SELECTED_DISPLAY_PROPERTY.equals(propName)) { TreeView treeView = model.getTreeView(); if (treeView == null) return; //tree shouldn't be null Browser browser = model.getBrowser(); ImageDisplay img = (ImageDisplay) pce.getNewValue(); if (img != null) { if (!(img.equals(browser.getLastSelectedDisplay()))) browser.setSelectedDisplay(img); } else browser.setSelectedDisplay(img); } else if (HiViewer.SCROLL_TO_NODE_PROPERTY.equals(propName)) { scrollToNode((ImageDisplay) pce.getNewValue()); } else if (Browser.ANNOTATED_NODE_PROPERTY.equals(propName)) { ImageDisplay n = (ImageDisplay) pce.getNewValue(); model.getClipBoard().setSelectedPane(ClipBoard.ANNOTATION_PANE, n); model.getBrowser().setSelectedDisplay(n); } else if (Browser.CLASSIFIED_NODE_PROPERTY.equals(propName)) { ImageNode n = (ImageNode) pce.getNewValue(); ClassifyCmd cmd = new ClassifyCmd( (ImageData) n.getHierarchyObject(), Classifier.DECLASSIFICATION_MODE, view, model.getUserDetails().getId(), model.getRootID(), model.getRootLevel()); cmd.execute(); } else if (Browser.ROLL_OVER_PROPERTY.equals(propName)) { if (model.isRollOver()) { ImageDisplay n = (ImageDisplay) pce.getNewValue(); if (n instanceof ImageNode) ThumbWinManager.rollOverDisplay((ImageNode) n, model.getBrowser()); else ThumbWinManager.rollOverDisplay(null, model.getBrowser()); } } }
3,228,818
static void display(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node."); TinyDialog w = getWindowFor(node); if (w != null) { //Could be null, see notes in getWindowFor(). w.pack(); //Now we have the right width and height. Point p = getWindowLocation(node, w.getWidth(), w.getHeight()); w.setCollapsed(false); w.moveToFront(p); } }
static void display(ImageNode node, HiViewer model) { if (node == null) throw new IllegalArgumentException("No node."); TinyDialog w = getWindowFor(node); if (w != null) { //Could be null, see notes in getWindowFor(). w.pack(); //Now we have the right width and height. Point p = getWindowLocation(node, w.getWidth(), w.getHeight()); w.setCollapsed(false); w.moveToFront(p); } }
3,228,819
static void display(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node."); TinyDialog w = getWindowFor(node); if (w != null) { //Could be null, see notes in getWindowFor(). w.pack(); //Now we have the right width and height. Point p = getWindowLocation(node, w.getWidth(), w.getHeight()); w.setCollapsed(false); w.moveToFront(p); } }
static void display(ImageNode node) { if (node == null) throw new IllegalArgumentException("No node."); if (model == null) throw new IllegalArgumentException("No model."); TinyDialog w = getWindowFor(node, model); if (w != null) { //Could be null, see notes in getWindowFor(). w.pack(); //Now we have the right width and height. Point p = getWindowLocation(node, w.getWidth(), w.getHeight()); w.setCollapsed(false); w.moveToFront(p); } }
3,228,820
public RenderingEngine getRenderingService(){ return (RenderingEngine) this.ctx.getBean("renderingService"); }
public RenderingEngine getRenderingService(){ return (RenderingEngine) this.ctx.getBean("renderService"); }
3,228,821
public Object invoke(ObjectName objectName, String methodName) throws org.apache.geronimo.kernel.GBeanNotFoundException, org.apache.geronimo.kernel.NoSuchOperationException, Exception { boolean running = isRunning(objectName); if (running) { throw new IllegalStateException("Service is not running: name=" + objectName); } ServiceInvoker serviceInvoker = getServiceInvoker(objectName); try { Object value = serviceInvoker.invoke(methodName, NO_ARGS, NO_TYPES); return value; } catch (NoSuchOperationException e) { throw new org.apache.geronimo.kernel.NoSuchOperationException(e); } }
public Object invoke(ObjectName objectName, String methodName) throws org.apache.geronimo.kernel.GBeanNotFoundException, org.apache.geronimo.kernel.NoSuchOperationException, Exception { boolean running = isRunning(objectName); if (!running) { throw new IllegalStateException("Service is not running: name=" + objectName); } ServiceInvoker serviceInvoker = getServiceInvoker(objectName); try { Object value = serviceInvoker.invoke(methodName, NO_ARGS, NO_TYPES); return value; } catch (NoSuchOperationException e) { throw new org.apache.geronimo.kernel.NoSuchOperationException(e); } }
3,228,822
public Node newArgs(Object f, Node o, RubyId r) { // +++ // return new ArgsNode(o, r, f); // --- return null; }
public Node newArgs(Object f, Node o, RubyId r) { // +++ // return new ArgsNode(o, r, f); // --- return null; }
3,228,823
public static String rtrim(String s) { if (s == null) return null; for (int i = s.length() - 1; i > -1; i--) { if (!Character.isWhitespace(s.charAt(i))) return s.substring(0, i); } // if all WS return empty string return ""; }
public static String rtrim(String s) { if (s == null) return null; for (int i = s.length() - 1; i > -1; i--) { if (!Character.isWhitespace(s.charAt(i))) return s.substring(0, i+1); } // if all WS return empty string return ""; }
3,228,824
public static Criteria buildCategoryGroupCriteria(int groupID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("CategoryList"); c.addWantedField("module_execution"); c.addWantedField("CategoryList", "Name"); c.addWantedField("CategoryList", "ClassificationList"); c.addWantedField("CategoryList.ClassificationList", "Valid"); c.addWantedField("CategoryList.ClassificationList", "image"); c.addWantedField("CategoryList", "module_execution"); c.addWantedField("CategoryList.module_execution", "experimenter"); c.addWantedField("CategoryList.ClassificationList", "module_execution"); c.addWantedField("CategoryList.ClassificationList.module_execution", "experimenter"); //Specify which fields we want for the owner. //group mex c.addWantedField("module_execution", "experimenter"); if (groupID != -1) c.addFilter("id", new Integer(groupID)); return c; }
public static Criteria buildCategoryGroupCriteria(int groupID, int userID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("CategoryList"); c.addWantedField("module_execution"); c.addWantedField("CategoryList", "Name"); c.addWantedField("CategoryList", "ClassificationList"); c.addWantedField("CategoryList.ClassificationList", "Valid"); c.addWantedField("CategoryList.ClassificationList", "image"); c.addWantedField("CategoryList", "module_execution"); c.addWantedField("CategoryList.module_execution", "experimenter"); c.addWantedField("CategoryList.ClassificationList", "module_execution"); c.addWantedField("CategoryList.ClassificationList.module_execution", "experimenter"); //Specify which fields we want for the owner. //group mex c.addWantedField("module_execution", "experimenter"); if (groupID != -1) c.addFilter("id", new Integer(groupID)); return c; }
3,228,825
public static Criteria buildCategoryGroupCriteria(int groupID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("CategoryList"); c.addWantedField("module_execution"); c.addWantedField("CategoryList", "Name"); c.addWantedField("CategoryList", "ClassificationList"); c.addWantedField("CategoryList.ClassificationList", "Valid"); c.addWantedField("CategoryList.ClassificationList", "image"); c.addWantedField("CategoryList", "module_execution"); c.addWantedField("CategoryList.module_execution", "experimenter"); c.addWantedField("CategoryList.ClassificationList", "module_execution"); c.addWantedField("CategoryList.ClassificationList.module_execution", "experimenter"); //Specify which fields we want for the owner. //group mex c.addWantedField("module_execution", "experimenter"); if (groupID != -1) c.addFilter("id", new Integer(groupID)); return c; }
public static Criteria buildCategoryGroupCriteria(int groupID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("CategoryList"); c.addWantedField("CategoryList", "Name"); c.addWantedField("CategoryList", "ClassificationList"); c.addWantedField("CategoryList.ClassificationList", "Valid"); c.addWantedField("CategoryList.ClassificationList", "image"); c.addWantedField("CategoryList", "module_execution"); c.addWantedField("CategoryList.module_execution", "experimenter"); c.addWantedField("CategoryList.ClassificationList", "module_execution"); c.addWantedField("CategoryList.ClassificationList.module_execution", "experimenter"); //Specify which fields we want for the owner. //group mex c.addWantedField("module_execution", "experimenter"); if (groupID != -1) c.addFilter("id", new Integer(groupID)); return c; }
3,228,826
public static Criteria buildCategoryGroupCriteria(int groupID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("CategoryList"); c.addWantedField("module_execution"); c.addWantedField("CategoryList", "Name"); c.addWantedField("CategoryList", "ClassificationList"); c.addWantedField("CategoryList.ClassificationList", "Valid"); c.addWantedField("CategoryList.ClassificationList", "image"); c.addWantedField("CategoryList", "module_execution"); c.addWantedField("CategoryList.module_execution", "experimenter"); c.addWantedField("CategoryList.ClassificationList", "module_execution"); c.addWantedField("CategoryList.ClassificationList.module_execution", "experimenter"); //Specify which fields we want for the owner. //group mex c.addWantedField("module_execution", "experimenter"); if (groupID != -1) c.addFilter("id", new Integer(groupID)); return c; }
public static Criteria buildCategoryGroupCriteria(int groupID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("CategoryList"); c.addWantedField("module_execution"); c.addWantedField("CategoryList", "Name"); c.addWantedField("CategoryList", "ClassificationList"); c.addWantedField("CategoryList.ClassificationList", "Valid"); c.addWantedField("CategoryList.ClassificationList", "image"); c.addWantedField("CategoryList", "module_execution"); c.addWantedField("CategoryList.module_execution", "experimenter"); c.addWantedField("CategoryList.ClassificationList", "module_execution"); c.addWantedField("CategoryList.ClassificationList.module_execution", "experimenter"); //Specify which fields we want for the owner. //group mex if (groupID != -1) c.addFilter("id", new Integer(groupID)); return c; }
3,228,827
public static Criteria buildDatasetAnnotationCriteria(int datasetID) { Criteria c = new Criteria(); fillAnnotationCriteria(c); c.addWantedField("dataset"); c.addFilter("dataset_id", new Integer(datasetID)); return c; }
public static Criteria buildDatasetAnnotationCriteria(List datasetIDs, int userID) { Criteria c = new Criteria(); fillAnnotationCriteria(c); c.addWantedField("dataset"); c.addFilter("dataset_id", new Integer(datasetID)); return c; }
3,228,829
public static Criteria buildDatasetAnnotationCriteria(int datasetID) { Criteria c = new Criteria(); fillAnnotationCriteria(c); c.addWantedField("dataset"); c.addFilter("dataset_id", new Integer(datasetID)); return c; }
public static Criteria buildDatasetAnnotationCriteria(int datasetID) { Criteria c = new Criteria(); fillAnnotationCriteria(c); c.addWantedField("dataset"); c.addFilter("dataset_id", "IN", datasetIDs); if (userID != -1) c.addFilter("module_execution.experimenter_id", new Integer(userID)); return c; }
3,228,830
public static Criteria buildICGHierarchyCriteria(List imageIDs) { Criteria c = new Criteria(); c.addWantedField("Confidence"); c.addWantedField("Category"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); //Fields for the category c.addWantedField("Category", "Name"); c.addWantedField("Category", "Description"); c.addWantedField("Category", "CategoryGroup"); c.addWantedField("Category.CategoryGroup", "Name"); c.addWantedField("Category.CategoryGroup", "Description"); //Fields we want for the images. c.addWantedField("image"); c.addWantedField("image", "id"); c.addFilter("image_id", "IN", imageIDs); //In this case, the filter should work ;-) return c; }
public static Criteria buildICGHierarchyCriteria(List imageIDs, int userID) { Criteria c = new Criteria(); c.addWantedField("Confidence"); c.addWantedField("Category"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); //Fields for the category c.addWantedField("Category", "Name"); c.addWantedField("Category", "Description"); c.addWantedField("Category", "CategoryGroup"); c.addWantedField("Category.CategoryGroup", "Name"); c.addWantedField("Category.CategoryGroup", "Description"); //Fields we want for the images. c.addWantedField("image"); c.addWantedField("image", "id"); c.addFilter("image_id", "IN", imageIDs); //In this case, the filter should work ;-) return c; }
3,228,831
public static Criteria buildICGHierarchyCriteria(List imageIDs) { Criteria c = new Criteria(); c.addWantedField("Confidence"); c.addWantedField("Category"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); //Fields for the category c.addWantedField("Category", "Name"); c.addWantedField("Category", "Description"); c.addWantedField("Category", "CategoryGroup"); c.addWantedField("Category.CategoryGroup", "Name"); c.addWantedField("Category.CategoryGroup", "Description"); //Fields we want for the images. c.addWantedField("image"); c.addWantedField("image", "id"); c.addFilter("image_id", "IN", imageIDs); //In this case, the filter should work ;-) return c; }
public static Criteria buildICGHierarchyCriteria(List imageIDs) { Criteria c = new Criteria(); c.addWantedField("Confidence"); c.addWantedField("Category"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); //Fields for the category c.addWantedField("Category", "Name"); c.addWantedField("Category", "Description"); c.addWantedField("Category", "CategoryGroup"); c.addWantedField("Category.CategoryGroup", "Name"); c.addWantedField("Category.CategoryGroup", "Description"); //Fields we want for the images. c.addWantedField("image"); c.addWantedField("image", "id"); c.addFilter("image_id", "IN", imageIDs); //In this case, the filter should work ;-) return c; }
3,228,832
public static Criteria buildICGHierarchyCriteria(List imageIDs) { Criteria c = new Criteria(); c.addWantedField("Confidence"); c.addWantedField("Category"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); //Fields for the category c.addWantedField("Category", "Name"); c.addWantedField("Category", "Description"); c.addWantedField("Category", "CategoryGroup"); c.addWantedField("Category.CategoryGroup", "Name"); c.addWantedField("Category.CategoryGroup", "Description"); //Fields we want for the images. c.addWantedField("image"); c.addWantedField("image", "id"); c.addFilter("image_id", "IN", imageIDs); //In this case, the filter should work ;-) return c; }
public static Criteria buildICGHierarchyCriteria(List imageIDs) { Criteria c = new Criteria(); c.addWantedField("Confidence"); c.addWantedField("Category"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. //Fields for the category c.addWantedField("Category", "Name"); c.addWantedField("Category", "Description"); c.addWantedField("Category", "CategoryGroup"); c.addWantedField("Category.CategoryGroup", "Name"); c.addWantedField("Category.CategoryGroup", "Description"); //Fields we want for the images. c.addWantedField("image"); c.addWantedField("image", "id"); c.addFilter("image_id", "IN", imageIDs); //In this case, the filter should work ;-) return c; }
3,228,833
public static Criteria buildBasicCriteria(int id) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); if (id != -1) c.addFilter("id", new Integer(id)); return c; }
public static Criteria buildBasicCriteria(int id, int userID) { Criteria c = new Criteria(); c.addWantedField("Name"); c.addWantedField("Description"); c.addWantedField("module_execution"); c.addWantedField("module_execution", "experimenter"); //Specify which fields we want for the owner. c.addWantedField("module_execution.experimenter", "id"); if (id != -1) c.addFilter("id", new Integer(id)); return c; }
3,228,835
public WeakReferenceListNode(Object ref, ReferenceQueue queue, WeakReferenceListNode prev) { super(ref, queue); this.prev = prev; if (prev != null) { prev.next = this; } }
public WeakReferenceListNode(Object ref, ReferenceQueue queue, WeakReferenceListNode next) { super(ref, queue); this.prev = prev; if (prev != null) { prev.next = this; } }
3,228,837
public WeakReferenceListNode(Object ref, ReferenceQueue queue, WeakReferenceListNode prev) { super(ref, queue); this.prev = prev; if (prev != null) { prev.next = this; } }
public WeakReferenceListNode(Object ref, ReferenceQueue queue, WeakReferenceListNode prev) { super(ref, queue); this.prev = prev; if (prev != null) { prev.next = this; } }
3,228,838
public void remove() { if (prev != null) { prev.next = next; } if (next != null) { next.prev = prev; } }
public void remove() { if (prev != null) { prev.next = next; } if (next != null) { next.prev = prev; } }
3,228,839
private void cleanup() { WeakReferenceListNode reference; while ((reference = (WeakReferenceListNode)deadReferences.poll()) != null) { reference.remove(); } }
private synchronized void cleanup() { WeakReferenceListNode reference; while ((reference = (WeakReferenceListNode)deadReferences.poll()) != null) { reference.remove(); } }
3,228,840
public Iterator iterator(RubyModule rubyClass) { return new ObjectSpaceIterator(rubyClass); }
public Iterator iterator(RubyModule rubyClass) { return new ObjectSpaceIterator(rubyClass); }
3,228,841
private void showErrorDialog(String title, String summary, String detail) { Exception e; if (detail == null) e = new Exception(summary); else e = new Exception(detail); MessengerDialog d = new MessengerDialog(SHARED_FRAME, DEFAULT_COMMENT_TITLE, "", e); d.addPropertyChangeListener(manager); d.setModal(true); UIUtilities.centerAndShow(d); }
private void showErrorDialog(String title, String summary, String detail) { Exception e; if (detail == null) e = new Exception(summary); else e = new Exception(detail); MessengerDialog d = new MessengerDialog(SHARED_FRAME, DEFAULT_COMMENT_TITLE, "", e); d.addPropertyChangeListener(manager); d.setModal(true); UIUtilities.centerAndShow(d); }
3,228,842
public org.openmicroscopy.omero.model.Image getImage() { return this.image; }
public Image getImage() { return this.image; }
3,228,845
public void setImage(org.openmicroscopy.omero.model.Image image) { this.image = image; }
public void setImage(Image image) { this.image = image; }
3,228,846
public org.openmicroscopy.omero.model.ModuleExecution getModuleExecution() { return this.moduleExecution; }
public ModuleExecution getModuleExecution() { return this.moduleExecution; }
3,228,847
public void setModuleExecution(org.openmicroscopy.omero.model.ModuleExecution moduleExecution) { this.moduleExecution = moduleExecution; }
public void setModuleExecution(ModuleExecution moduleExecution) { this.moduleExecution = moduleExecution; }
3,228,848
public org.openmicroscopy.omero.model.DisplayOption getDisplayOption() { return this.displayOption; }
public DisplayOption getDisplayOption() { return this.displayOption; }
3,228,849
public void setDisplayOption(org.openmicroscopy.omero.model.DisplayOption displayOption) { this.displayOption = displayOption; }
public void setDisplayOption(DisplayOption displayOption) { this.displayOption = displayOption; }
3,228,850
public static RubyObject each_with_index_i(Ruby ruby, RubyObject blockArg, RubyObject arg1, RubyObject self) { ruby.yield(RubyArray.newArray(ruby, blockArg, arg1)); ((RubyFixnum) arg1).setValue(((RubyFixnum) arg1).getValue() + 1); return ruby.getNil(); }
public static RubyObject each_with_index_i(Ruby ruby, RubyObject blockArg, RubyObject arg1, RubyObject self) { ruby.yield(RubyArray.newArray(ruby, blockArg, arg1)); ((RubyFixnum) arg1).setValue(RubyNumeric.fix2long(arg1) + 1); return ruby.getNil(); }
3,228,851
public static RubyObject find_i(Ruby ruby, RubyObject blockArg, RubyObject arg1, RubyObject self) { if (ruby.yield(blockArg).isTrue()) { ((RubyArray) arg1).push(blockArg); throw new BreakException(); } return ruby.getNil(); }
public static RubyObject find_i(Ruby ruby, RubyObject blockArg, RubyObject arg1, RubyObject self) { if (ruby.yield(blockArg).isTrue()) { ((RubyArray) arg1).push(blockArg); throw new BreakJump(); } return ruby.getNil(); }
3,228,852
public static RubyObject member_i(Ruby ruby, RubyObject blockArg, RubyObject arg1, RubyObject self) { if (blockArg.funcall("==", ((RubyArray) arg1).entry(0)).isTrue()) { ((RubyArray) arg1).push(ruby.getTrue()); throw new BreakException(); } return ruby.getNil(); }
public static RubyObject member_i(Ruby ruby, RubyObject blockArg, RubyObject arg1, RubyObject self) { if (blockArg.funcall("==", ((RubyArray) arg1).entry(0)).isTrue()) { ((RubyArray) arg1).push(ruby.getTrue()); throw new BreakJump(); } return ruby.getNil(); }
3,228,853
public static Callback getBlockMethod(Class type, String method) { return new ReflectionCallbackMethod(type, method, new Class[] { RubyObject.class, RubyObject.class }, false, true); }
public static Callback getBlockMethod(Class type, String method) { return new ReflectionCallbackMethod(type, method, new Class[] { RubyObject.class, RubyObject.class }, false, true, 2); }
3,228,854
GraphicsRepresentation(QuantumPaneManager control, int family, double curveCoefficient, int cdStart, int cdEnd, int min, int max) { this.family = family; this.curveCoefficient = curveCoefficient; this.cdStart = cdStart; this.cdEnd = cdEnd; type = family; reverseIntensity = false; //TODO: retrieve user settings manager = new GraphicsRepresentationManager(this, control, type); setInputWindow(min, max); minimum = min; maximum = max; quad = new QuadCurve2D.Double(); startPt = new Point2D.Double(); controlPt = new Point2D.Double(); endPt = new Point2D.Double(); staticStartPt = new Point2D.Double(); staticEndPt = new Point2D.Double(); xStartMax = leftBorder; }
GraphicsRepresentation(QuantumPaneManager control, int family, double curveCoefficient, int cdStart, int cdEnd, int min, int max) { this.family = family; this.curveCoefficient = curveCoefficient; this.cdStart = cdStart; this.cdEnd = cdEnd; type = family; reverseIntensity = false; //TODO: retrieve user settings manager = new GraphicsRepresentationManager(this, control, type); setInputWindow(min, max); minimum = min; maximum = max; quad = new QuadCurve2D.Double(); startPt = new Point2D.Double(); controlPt = new Point2D.Double(); endPt = new Point2D.Double(); staticStartPt = new Point2D.Double(); staticEndPt = new Point2D.Double(); xStartMax = leftBorder; }
3,228,855
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2D = (Graphics2D) g; g2D.setColor(getBackground()); g2D.fillRect(0, 0, width, height); //FONT settings. Font font = g2D.getFont(); FontMetrics fontMetrics = g2D.getFontMetrics(); int hFont = fontMetrics.getHeight(); Rectangle2D rStart = font.getStringBounds(start, g2D.getFontRenderContext()); int wStart = (int) rStart.getWidth(); int hStart = (int) rStart.getHeight(); Rectangle2D rEnd = font.getStringBounds(end, g2D.getFontRenderContext()); int wEnd = (int) rEnd.getWidth(); Rectangle2D rInput = font.getStringBounds("Pixel intensity", g2D.getFontRenderContext()); int wInput = (int) rInput.getWidth(); int hInput = (int) rInput.getHeight(); setKnobStartY(tS+hStart+5); setKnobEndY(hStart+5); int extra = 0; if (type == QuantumFactory.EXPONENTIAL) extra = hStart/2; //Grid AffineTransform transform = new AffineTransform(); //140/10 = 14 then middle = 14/2 transform.translate(leftBorder+70, topBorder+70); transform.scale(10, 10); g2D.setPaint(Color.lightGray); GeneralPath path = new GeneralPath(); for (int i = -7; i <= 7; i++) { path.moveTo(i, -7); path.lineTo(i, 7); } for (int i = -7; i <= 7; i++) { path.moveTo(-7, i); path.lineTo(7, i); } g2D.draw(transform.createTransformedShape(path)); g2D.setColor(axisColor); //y-axis g2D.drawLine(leftBorder, topBorder-8, leftBorder, tS+5); g2D.drawLine(leftBorder, topBorder-8, leftBorder-3, topBorder-5); g2D.drawLine(leftBorder, topBorder-8, leftBorder+3, topBorder-5); g2D.drawLine(leftBorder-5, topBorder, leftBorder, topBorder); //x-axis g2D.drawLine(leftBorder-5, tS, lS+8, tS); g2D.drawLine(lS+5, tS-3, lS+8, tS); g2D.drawLine(lS+5, tS+3, lS+8, tS); g2D.drawLine(xControl, tS, xControl, tS+5); //input interval g2D.drawString(start, leftBorder-wStart/2, tS+hFont); g2D.drawString(end, xControl-wEnd/2, hFont+tS+extra); g2D.drawString("Pixels intensity", lS2-wInput/2, hFont/2+tS+bottomBorder+hInput); //g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //inputStart knob int xStartPoints[] = {xStart1, xStart2, xStart3}; int yStartPoints[] = {yStart1+extra, yStart2+extra, yStart3+extra}; GeneralPath filledPolygonStart = new GeneralPath(); filledPolygonStart.moveTo(xStartPoints[0], yStartPoints[0]); for (int index = 1; index < xStartPoints.length; index++) filledPolygonStart.lineTo(xStartPoints[index], yStartPoints[index]); filledPolygonStart.closePath(); g2D.setColor(iStartColor); g2D.fill(filledPolygonStart); //curStart value g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //inputEnd knob int xEndPoints[] = {xEnd1, xEnd2, xEnd3}; int yEndPoints[] = {yEnd1+extra, yEnd2+extra, yEnd3+extra}; GeneralPath filledPolygonEnd = new GeneralPath(); filledPolygonEnd.moveTo(xEndPoints[0], yEndPoints[0]); for (int index = 1; index < xEndPoints.length; index++) filledPolygonEnd.lineTo(xEndPoints[index], yEndPoints[index]); filledPolygonEnd.closePath(); g2D.setColor(iEndColor); g2D.fill(filledPolygonEnd); //curEnd value. g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //outputStart knob int xStartOutputPoints[] = {xStartOutput1, xStartOutput2, xStartOutput3}; int yStartOutputPoints[] = {yStartOutput1, yStartOutput2, yStartOutput3}; GeneralPath filledPolygonStartOutput = new GeneralPath(); filledPolygonStartOutput.moveTo(xStartOutputPoints[0], yStartOutputPoints[0]); for (int index = 1; index < xStartOutputPoints.length; index++) filledPolygonStartOutput.lineTo(xStartOutputPoints[index], yStartOutputPoints[index]); filledPolygonStartOutput.closePath(); g2D.setColor(ostartColor); g2D.fill(filledPolygonStartOutput); //outputEnd knob. int xEndOutputPoints[] = {xEndOutput1, xEndOutput2, xEndOutput3}; int yEndOutputPoints[] = {yEndOutput1, yEndOutput2, yEndOutput3}; GeneralPath filledPolygonEndOutput = new GeneralPath(); filledPolygonEndOutput.moveTo(xEndOutputPoints[0], yEndOutputPoints[0]); for (int index = 1; index < xEndOutputPoints.length; index++) filledPolygonEndOutput.lineTo(xEndOutputPoints[index], yEndOutputPoints[index]); filledPolygonEndOutput.closePath(); g2D.setColor(oendColor); g2D.fill(filledPolygonEndOutput); g2D.setColor(lineColor); g2D.setStroke(new BasicStroke(1.5f)); //draw line g2D.drawLine((int) staticStartPt.getX(), (int) staticStartPt.getY(), (int) startPt.getX(), (int) startPt.getY()); g2D.drawLine((int) endPt.getX(), (int) endPt.getY(), (int) staticEndPt.getX(), (int) staticEndPt.getY()); //draw curve g2D.draw(quad); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2D = (Graphics2D) g; g2D.setColor(getBackground()); g2D.fillRect(0, 0, width, height); //FONT settings. Font font = g2D.getFont(); FontMetrics fontMetrics = g2D.getFontMetrics(); int hFont = fontMetrics.getHeight(); Rectangle2D rStart = font.getStringBounds(start, g2D.getFontRenderContext()); int wStart = (int) rStart.getWidth(); int hStart = (int) rStart.getHeight(); Rectangle2D rEnd = font.getStringBounds(end, g2D.getFontRenderContext()); int wEnd = (int) rEnd.getWidth(); Rectangle2D rInput = font.getStringBounds("Pixel intensity", g2D.getFontRenderContext()); int wInput = (int) rInput.getWidth(); int hInput = (int) rInput.getHeight(); setKnobStartY(tS+hStart+5); setKnobEndY(hStart+5); int extra = 0; if (type == QuantumFactory.EXPONENTIAL) extra = hStart/2; //Grid AffineTransform transform = new AffineTransform(); //140/10 = 14 then middle = 14/2 transform.translate(leftBorder+70, topBorder+70); transform.scale(10, 10); g2D.setPaint(Color.lightGray); GeneralPath path = new GeneralPath(); for (int i = -7; i <= 7; i++) { path.moveTo(i, -7); path.lineTo(i, 7); } for (int i = -7; i <= 7; i++) { path.moveTo(-7, i); path.lineTo(7, i); } g2D.draw(transform.createTransformedShape(path)); g2D.setColor(axisColor); //y-axis g2D.drawLine(leftBorder, topBorder-8, leftBorder, tS+5); g2D.drawLine(leftBorder, topBorder-8, leftBorder-3, topBorder-5); g2D.drawLine(leftBorder, topBorder-8, leftBorder+3, topBorder-5); g2D.drawLine(leftBorder-5, topBorder, leftBorder, topBorder); //x-axis g2D.drawLine(leftBorder-5, tS, lS+8, tS); g2D.drawLine(lS+5, tS-3, lS+8, tS); g2D.drawLine(lS+5, tS+3, lS+8, tS); g2D.drawLine(xControl, tS, xControl, tS+5); //input interval g2D.drawString(start, leftBorder-wStart/2, tS+hFont); g2D.drawString(end, xControl-wEnd/2, hFont+tS+extra); g2D.drawString("Pixels intensity", lS2-wInput/2, hFont/2+tS+bottomBorder+hInput); //g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //inputStart knob int xStartPoints[] = {xStart1, xStart2, xStart3}; int yStartPoints[] = {yStart1+extra, yStart2+extra, yStart3+extra}; GeneralPath filledPolygonStart = new GeneralPath(); filledPolygonStart.moveTo(xStartPoints[0], yStartPoints[0]); for (int index = 1; index < xStartPoints.length; index++) filledPolygonStart.lineTo(xStartPoints[index], yStartPoints[index]); filledPolygonStart.closePath(); g2D.setColor(iStartColor); g2D.fill(filledPolygonStart); //curStart value g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //inputEnd knob int xEndPoints[] = {xEnd1, xEnd2, xEnd3}; int yEndPoints[] = {yEnd1+extra, yEnd2+extra, yEnd3+extra}; GeneralPath filledPolygonEnd = new GeneralPath(); filledPolygonEnd.moveTo(xEndPoints[0], yEndPoints[0]); for (int index = 1; index < xEndPoints.length; index++) filledPolygonEnd.lineTo(xEndPoints[index], yEndPoints[index]); filledPolygonEnd.closePath(); g2D.setColor(iEndColor); g2D.fill(filledPolygonEnd); //curEnd value. g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //outputStart knob int xStartOutputPoints[] = {xStartOutput1, xStartOutput2, xStartOutput3}; int yStartOutputPoints[] = {yStartOutput1, yStartOutput2, yStartOutput3}; GeneralPath filledPolygonStartOutput = new GeneralPath(); filledPolygonStartOutput.moveTo(xStartOutputPoints[0], yStartOutputPoints[0]); for (int index = 1; index < xStartOutputPoints.length; index++) filledPolygonStartOutput.lineTo(xStartOutputPoints[index], yStartOutputPoints[index]); filledPolygonStartOutput.closePath(); g2D.setColor(ostartColor); g2D.fill(filledPolygonStartOutput); //outputEnd knob. int xEndOutputPoints[] = {xEndOutput1, xEndOutput2, xEndOutput3}; int yEndOutputPoints[] = {yEndOutput1, yEndOutput2, yEndOutput3}; GeneralPath filledPolygonEndOutput = new GeneralPath(); filledPolygonEndOutput.moveTo(xEndOutputPoints[0], yEndOutputPoints[0]); for (int index = 1; index < xEndOutputPoints.length; index++) filledPolygonEndOutput.lineTo(xEndOutputPoints[index], yEndOutputPoints[index]); filledPolygonEndOutput.closePath(); g2D.setColor(oendColor); g2D.fill(filledPolygonEndOutput); g2D.setColor(lineColor); g2D.setStroke(new BasicStroke(1.5f)); //draw line g2D.drawLine((int) staticStartPt.getX(), (int) staticStartPt.getY(), (int) startPt.getX(), (int) startPt.getY()); g2D.drawLine((int) endPt.getX(), (int) endPt.getY(), (int) staticEndPt.getX(), (int) staticEndPt.getY()); //draw curve g2D.draw(quad); }
3,228,856
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2D = (Graphics2D) g; g2D.setColor(getBackground()); g2D.fillRect(0, 0, width, height); //FONT settings. Font font = g2D.getFont(); FontMetrics fontMetrics = g2D.getFontMetrics(); int hFont = fontMetrics.getHeight(); Rectangle2D rStart = font.getStringBounds(start, g2D.getFontRenderContext()); int wStart = (int) rStart.getWidth(); int hStart = (int) rStart.getHeight(); Rectangle2D rEnd = font.getStringBounds(end, g2D.getFontRenderContext()); int wEnd = (int) rEnd.getWidth(); Rectangle2D rInput = font.getStringBounds("Pixel intensity", g2D.getFontRenderContext()); int wInput = (int) rInput.getWidth(); int hInput = (int) rInput.getHeight(); setKnobStartY(tS+hStart+5); setKnobEndY(hStart+5); int extra = 0; if (type == QuantumFactory.EXPONENTIAL) extra = hStart/2; //Grid AffineTransform transform = new AffineTransform(); //140/10 = 14 then middle = 14/2 transform.translate(leftBorder+70, topBorder+70); transform.scale(10, 10); g2D.setPaint(Color.lightGray); GeneralPath path = new GeneralPath(); for (int i = -7; i <= 7; i++) { path.moveTo(i, -7); path.lineTo(i, 7); } for (int i = -7; i <= 7; i++) { path.moveTo(-7, i); path.lineTo(7, i); } g2D.draw(transform.createTransformedShape(path)); g2D.setColor(axisColor); //y-axis g2D.drawLine(leftBorder, topBorder-8, leftBorder, tS+5); g2D.drawLine(leftBorder, topBorder-8, leftBorder-3, topBorder-5); g2D.drawLine(leftBorder, topBorder-8, leftBorder+3, topBorder-5); g2D.drawLine(leftBorder-5, topBorder, leftBorder, topBorder); //x-axis g2D.drawLine(leftBorder-5, tS, lS+8, tS); g2D.drawLine(lS+5, tS-3, lS+8, tS); g2D.drawLine(lS+5, tS+3, lS+8, tS); g2D.drawLine(xControl, tS, xControl, tS+5); //input interval g2D.drawString(start, leftBorder-wStart/2, tS+hFont); g2D.drawString(end, xControl-wEnd/2, hFont+tS+extra); g2D.drawString("Pixels intensity", lS2-wInput/2, hFont/2+tS+bottomBorder+hInput); //g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //inputStart knob int xStartPoints[] = {xStart1, xStart2, xStart3}; int yStartPoints[] = {yStart1+extra, yStart2+extra, yStart3+extra}; GeneralPath filledPolygonStart = new GeneralPath(); filledPolygonStart.moveTo(xStartPoints[0], yStartPoints[0]); for (int index = 1; index < xStartPoints.length; index++) filledPolygonStart.lineTo(xStartPoints[index], yStartPoints[index]); filledPolygonStart.closePath(); g2D.setColor(iStartColor); g2D.fill(filledPolygonStart); //curStart value g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //inputEnd knob int xEndPoints[] = {xEnd1, xEnd2, xEnd3}; int yEndPoints[] = {yEnd1+extra, yEnd2+extra, yEnd3+extra}; GeneralPath filledPolygonEnd = new GeneralPath(); filledPolygonEnd.moveTo(xEndPoints[0], yEndPoints[0]); for (int index = 1; index < xEndPoints.length; index++) filledPolygonEnd.lineTo(xEndPoints[index], yEndPoints[index]); filledPolygonEnd.closePath(); g2D.setColor(iEndColor); g2D.fill(filledPolygonEnd); //curEnd value. g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //outputStart knob int xStartOutputPoints[] = {xStartOutput1, xStartOutput2, xStartOutput3}; int yStartOutputPoints[] = {yStartOutput1, yStartOutput2, yStartOutput3}; GeneralPath filledPolygonStartOutput = new GeneralPath(); filledPolygonStartOutput.moveTo(xStartOutputPoints[0], yStartOutputPoints[0]); for (int index = 1; index < xStartOutputPoints.length; index++) filledPolygonStartOutput.lineTo(xStartOutputPoints[index], yStartOutputPoints[index]); filledPolygonStartOutput.closePath(); g2D.setColor(ostartColor); g2D.fill(filledPolygonStartOutput); //outputEnd knob. int xEndOutputPoints[] = {xEndOutput1, xEndOutput2, xEndOutput3}; int yEndOutputPoints[] = {yEndOutput1, yEndOutput2, yEndOutput3}; GeneralPath filledPolygonEndOutput = new GeneralPath(); filledPolygonEndOutput.moveTo(xEndOutputPoints[0], yEndOutputPoints[0]); for (int index = 1; index < xEndOutputPoints.length; index++) filledPolygonEndOutput.lineTo(xEndOutputPoints[index], yEndOutputPoints[index]); filledPolygonEndOutput.closePath(); g2D.setColor(oendColor); g2D.fill(filledPolygonEndOutput); g2D.setColor(lineColor); g2D.setStroke(new BasicStroke(1.5f)); //draw line g2D.drawLine((int) staticStartPt.getX(), (int) staticStartPt.getY(), (int) startPt.getX(), (int) startPt.getY()); g2D.drawLine((int) endPt.getX(), (int) endPt.getY(), (int) staticEndPt.getX(), (int) staticEndPt.getY()); //draw curve g2D.draw(quad); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2D = (Graphics2D) g; g2D.setColor(getBackground()); g2D.fillRect(0, 0, width, height); //FONT settings. Font font = g2D.getFont(); FontMetrics fontMetrics = g2D.getFontMetrics(); int hFont = fontMetrics.getHeight(); Rectangle2D rStart = font.getStringBounds(start, g2D.getFontRenderContext()); int wStart = (int) rStart.getWidth(); int hStart = (int) rStart.getHeight(); Rectangle2D rEnd = font.getStringBounds(end, g2D.getFontRenderContext()); int wEnd = (int) rEnd.getWidth(); Rectangle2D rInput = font.getStringBounds("Pixel intensity", g2D.getFontRenderContext()); int wInput = (int) rInput.getWidth(); int hInput = (int) rInput.getHeight(); setKnobStartY(tS+hStart+5); setKnobEndY(hStart+5); int extra = 0; if (type == QuantumFactory.EXPONENTIAL) extra = hStart/2; //Grid AffineTransform transform = new AffineTransform(); //140/10 = 14 then middle = 14/2 transform.translate(leftBorder+70, topBorder+70); transform.scale(10, 10); g2D.setPaint(Color.lightGray); GeneralPath path = new GeneralPath(); for (int i = -7; i <= 7; i++) { path.moveTo(i, -7); path.lineTo(i, 7); } for (int i = -7; i <= 7; i++) { path.moveTo(-7, i); path.lineTo(7, i); } g2D.draw(transform.createTransformedShape(path)); g2D.setColor(axisColor); //y-axis g2D.drawLine(leftBorder, topBorder-8, leftBorder, tS+5); g2D.drawLine(leftBorder, topBorder-8, leftBorder-3, topBorder-5); g2D.drawLine(leftBorder, topBorder-8, leftBorder+3, topBorder-5); g2D.drawLine(leftBorder-5, topBorder, leftBorder, topBorder); //x-axis g2D.drawLine(leftBorder-5, tS, lS+8, tS); g2D.drawLine(lS+5, tS-3, lS+8, tS); g2D.drawLine(lS+5, tS+3, lS+8, tS); g2D.drawLine(xControl, tS, xControl, tS+5); //input interval g2D.drawString(start, leftBorder-wStart/2, tS+hFont); g2D.drawString(end, xControl-wEnd/2, hFont+tS+extra); g2D.drawString("Pixels intensity", lS2-wInput/2, hFont/2+tS+bottomBorder+hInput); //g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //inputStart knob int xStartPoints[] = {xStart1, xStart2, xStart3}; int yStartPoints[] = {yStart1+extra, yStart2+extra, yStart3+extra}; GeneralPath filledPolygonStart = new GeneralPath(); filledPolygonStart.moveTo(xStartPoints[0], yStartPoints[0]); for (int index = 1; index < xStartPoints.length; index++) filledPolygonStart.lineTo(xStartPoints[index], yStartPoints[index]); filledPolygonStart.closePath(); g2D.setColor(iStartColor); g2D.fill(filledPolygonStart); //curStart value g2D.drawString(curStart, 10, hFont+tS+bottomBorder+2*hInput); //inputEnd knob int xEndPoints[] = {xEnd1, xEnd2, xEnd3}; int yEndPoints[] = {yEnd1+extra, yEnd2+extra, yEnd3+extra}; GeneralPath filledPolygonEnd = new GeneralPath(); filledPolygonEnd.moveTo(xEndPoints[0], yEndPoints[0]); for (int index = 1; index < xEndPoints.length; index++) filledPolygonEnd.lineTo(xEndPoints[index], yEndPoints[index]); filledPolygonEnd.closePath(); g2D.setColor(iEndColor); g2D.fill(filledPolygonEnd); //curEnd value. g2D.drawString(curEnd, lS2+10, hFont+tS+bottomBorder+2*hInput); //outputStart knob int xStartOutputPoints[] = {xStartOutput1, xStartOutput2, xStartOutput3}; int yStartOutputPoints[] = {yStartOutput1, yStartOutput2, yStartOutput3}; GeneralPath filledPolygonStartOutput = new GeneralPath(); filledPolygonStartOutput.moveTo(xStartOutputPoints[0], yStartOutputPoints[0]); for (int index = 1; index < xStartOutputPoints.length; index++) filledPolygonStartOutput.lineTo(xStartOutputPoints[index], yStartOutputPoints[index]); filledPolygonStartOutput.closePath(); g2D.setColor(ostartColor); g2D.fill(filledPolygonStartOutput); //outputEnd knob. int xEndOutputPoints[] = {xEndOutput1, xEndOutput2, xEndOutput3}; int yEndOutputPoints[] = {yEndOutput1, yEndOutput2, yEndOutput3}; GeneralPath filledPolygonEndOutput = new GeneralPath(); filledPolygonEndOutput.moveTo(xEndOutputPoints[0], yEndOutputPoints[0]); for (int index = 1; index < xEndOutputPoints.length; index++) filledPolygonEndOutput.lineTo(xEndOutputPoints[index], yEndOutputPoints[index]); filledPolygonEndOutput.closePath(); g2D.setColor(oendColor); g2D.fill(filledPolygonEndOutput); g2D.setColor(lineColor); g2D.setStroke(new BasicStroke(1.5f)); //draw line g2D.drawLine((int) staticStartPt.getX(), (int) staticStartPt.getY(), (int) startPt.getX(), (int) startPt.getY()); g2D.drawLine((int) endPt.getX(), (int) endPt.getY(), (int) staticEndPt.getX(), (int) staticEndPt.getY()); //draw curve g2D.draw(quad); }
3,228,857
private void repaintCurve() { quad.setCurve(startPt, controlPt, endPt); repaint(); }
private void repaintCurve() { quad.setCurve(startPt, controlPt, endPt); repaint(); }
3,228,858
void reverse(boolean b) { double yStart, yEnd; double xStaticStart, xStart; reverseIntensity = b; yEnd = endPt.getY(); yStart = startPt.getY(); setKnobOutputStart((int) yStart); setKnobOutputEnd((int) yEnd); manager.setOutputRectangles((int) yStart, (int) yEnd); xStaticStart = staticStartPt.getX(); xStart = startPt.getX(); startPt.setLocation(endPt.getX(), yStart); endPt.setLocation(xStart, yEnd); if (reverseIntensity) { if (type == QuantumFactory.EXPONENTIAL) { staticStartPt.setLocation(staticEndPt.getX(), yStart); staticEndPt.setLocation(xStaticStart, yEnd); controlPt.setLocation(controlPt.getX(), yEnd); repaintCurve(); } else { staticStartPt.setLocation(lS, yStart); staticEndPt.setLocation(leftBorder, yEnd); setControlLocation(coefficient); } } else { if (type == QuantumFactory.EXPONENTIAL) { staticStartPt.setLocation(staticEndPt.getX(), yStart); staticEndPt.setLocation(xStaticStart, yEnd); controlPt.setLocation(controlPt.getX(), yStart); repaintCurve(); } else { staticStartPt.setLocation(leftBorder, yStart); staticEndPt.setLocation(lS, yEnd); setControlLocation(coefficient); } } }
void reverse(boolean b) { double yStart, yEnd; double xStaticStart, xStart; reverseIntensity = b; yEnd = endPt.getY(); yStart = startPt.getY(); setKnobOutputStart((int) yStart); setKnobOutputEnd((int) yEnd); manager.setOutputRectangles((int) yStart, (int) yEnd); xStaticStart = staticStartPt.getX(); xStart = startPt.getX(); startPt.setLocation(endPt.getX(), yStart); endPt.setLocation(xStart, yEnd); if (reverseIntensity) { if (type == QuantumFactory.EXPONENTIAL) { staticStartPt.setLocation(staticEndPt.getX(), yStart); staticEndPt.setLocation(xStaticStart, yEnd); controlPt.setLocation(controlPt.getX(), yEnd); repaintCurve(); } else { staticStartPt.setLocation(lS, yStart); staticEndPt.setLocation(leftBorder, yEnd); setControlLocation(coefficient); } } else { if (type == QuantumFactory.EXPONENTIAL) { staticStartPt.setLocation(staticEndPt.getX(), yStart); staticEndPt.setLocation(xStaticStart, yEnd); controlPt.setLocation(controlPt.getX(), yStart); repaintCurve(); } else { staticStartPt.setLocation(leftBorder, yStart); staticEndPt.setLocation(lS, yEnd); setControlLocation(coefficient); } } }
3,228,859
void setControlAndEndLocation(int k) { double x = 0; double diffEnd; coefficient = k; if (k == INIT) { if (reverseIntensity) x = (staticEndPt.getX()+square/2); else x = (staticStartPt.getX()+square/2); } else if (MIN <= k && k < INIT) { k = INIT-k; if (reverseIntensity) x = (staticEndPt.getX()+square/2+k*binMax); else x = (staticStartPt.getX()+square/2+k*binMax); } else if (k > INIT && k <= MAX) { k = k-INIT; if (reverseIntensity) x = (staticEndPt.getX()+square/2-k*binMin); else x = (staticStartPt.getX()+square/2-k*binMin); } xControl = (int) x; if (x >= xStartMax+triangleW) { if (reverseIntensity) { diffEnd = staticStartPt.getX()-startPt.getX(); startPt.setLocation(x-diffEnd, startPt.getY()); controlPt.setLocation(x-diffEnd, endPt.getY()); staticStartPt.setLocation(x, staticStartPt.getY()); manager.setInputEndBox((int) (x-diffEnd)); setKnobEnd((int) (x-diffEnd)); } else { diffEnd = staticEndPt.getX()-endPt.getX(); endPt.setLocation(x-diffEnd, endPt.getY()); controlPt.setLocation(x-diffEnd, startPt.getY()); staticEndPt.setLocation(x, staticEndPt.getY()); manager.setInputEndBox((int) (x-diffEnd)); setKnobEnd((int) (x-diffEnd)); } range = (int) x-leftBorder; manager.setMaxEndX(xControl); repaintCurve(); } }
void setControlAndEndLocation(int k) { double x = 0; double diffEnd; coefficient = k; if (k == INIT) { if (reverseIntensity) x = (staticEndPt.getX()+square/2); else x = (staticStartPt.getX()+square/2); } else if (MIN <= k && k < INIT) { k = INIT-k; if (reverseIntensity) x = (staticEndPt.getX()+square/2+k*binMax); else x = (staticStartPt.getX()+square/2+k*binMax); } else if (k > INIT && k <= MAX) { k = k-INIT; if (reverseIntensity) x = (staticEndPt.getX()+square/2-k*binMin); else x = (staticStartPt.getX()+square/2-k*binMin); } xControl = (int) x; if (x >= xStartMax+triangleW) { if (reverseIntensity) { diffEnd = staticStartPt.getX()-startPt.getX(); startPt.setLocation(x-diffEnd, startPt.getY()); controlPt.setLocation(x-diffEnd, endPt.getY()); staticStartPt.setLocation(x, staticStartPt.getY()); manager.setInputEndBox((int) (x-diffEnd)); setKnobEnd((int) (x-diffEnd)); } else { diffEnd = staticEndPt.getX()-endPt.getX(); endPt.setLocation(x-diffEnd, endPt.getY()); controlPt.setLocation(x-diffEnd, startPt.getY()); staticEndPt.setLocation(x, staticEndPt.getY()); manager.setInputEndBox((int) (x-diffEnd)); setKnobEnd((int) (x-diffEnd)); } range = (int) x-leftBorder; manager.setMaxEndX(xControl); repaintCurve(); } }
3,228,860
void setControlLocation(int k) { double x = 0, y = 0; coefficient = k; double diff; if (reverseIntensity) diff = startPt.getX()-endPt.getX(); else diff = endPt.getX()-startPt.getX(); binMin = (int) (diff/rangeMin); binMax = (int) (diff/rangeMax); if (k == INIT) { x = startPt.getX(); y = startPt.getY(); } else if (MIN <= k && k < INIT) { if (reverseIntensity) { x = endPt.getX()+(k-1)*binMin; y = startPt.getY(); } else { x = startPt.getX() + (k-1)*binMin; y = endPt.getY(); } } else if (k > INIT && k <= MAX) { if (reverseIntensity) { x = endPt.getX()+(k-INIT)*binMax; y = endPt.getY(); } else { x = startPt.getX()+(k-INIT)*binMax; y = startPt.getY(); } } controlPt.setLocation(x, y); repaintCurve(); }
void setControlLocation(int k) { double x = 0, y = 0; coefficient = k; double diff; if (reverseIntensity) diff = startPt.getX()-endPt.getX(); else diff = endPt.getX()-startPt.getX(); binMin = (int) (diff/rangeMin); binMax = (int) (diff/rangeMax); if (k == INIT) { x = startPt.getX(); y = startPt.getY(); } else if (MIN <= k && k < INIT) { if (reverseIntensity) { x = endPt.getX()+(k-1)*binMin; y = startPt.getY(); } else { x = startPt.getX() + (k-1)*binMin; y = endPt.getY(); } } else if (k > INIT && k <= MAX) { if (reverseIntensity) { x = endPt.getX()+(k-INIT)*binMax; y = endPt.getY(); } else { x = startPt.getX()+(k-INIT)*binMax; y = startPt.getY(); } } controlPt.setLocation(x, y); repaintCurve(); }
3,228,861
void setControlsPoints(int t) { type = t; double xStaticEnd, xStaticStart, xEnd, xStart; xStaticEnd = 0; xStaticStart = 0; xEnd = 0; xStart = 0; if (type == QuantumFactory.EXPONENTIAL) { xControl = lS2; range = square/2; binMin = ((square-40)/(2*rangeMinExpo)); binMax = ((square-40)/(2*rangeMaxExpo)); if (reverseIntensity) { xStaticStart = lS2; xStaticEnd = leftBorder; xEnd = (endPt.getX()+leftBorder)/2; xStart = (startPt.getX()+leftBorder)/2; } else { xEnd = (endPt.getX()+leftBorder)/2; xStart = (startPt.getX()+leftBorder)/2; xStaticEnd = lS2; xStaticStart = leftBorder; } } else { xControl = lS; range = square; double a; binMin = (square/rangeMin); binMax = (square/rangeMax); if (reverseIntensity) { a = square/(staticStartPt.getX()-leftBorder); xStaticStart = lS; xStaticEnd = leftBorder; xEnd = a*(endPt.getX()-leftBorder)+leftBorder; xStart = a*(startPt.getX()-leftBorder)+leftBorder; } else { a = square/(staticEndPt.getX()-leftBorder); xEnd = a*(endPt.getX()-leftBorder)+leftBorder; xStart = a*(startPt.getX()-leftBorder)+leftBorder; xStaticEnd = lS; xStaticStart = leftBorder; } } manager.setType(type, xControl); staticEndPt.setLocation(xStaticEnd, staticEndPt.getY()); staticStartPt.setLocation(xStaticStart, staticStartPt.getY()); endPt.setLocation(xEnd, endPt.getY()); startPt.setLocation(xStart, startPt.getY()); //Set knob location if (reverseIntensity) { setKnobStart((int) xEnd); setKnobEnd((int) xStart); manager.setInputRectangles((int) xEnd, (int) xStart); } else { setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); } }
void setControlsPoints(int t) { type = t; double xStaticEnd, xStaticStart, xEnd, xStart; xStaticEnd = 0; xStaticStart = 0; xEnd = 0; xStart = 0; if (type == QuantumFactory.EXPONENTIAL) { xControl = lS2; range = square/2; binMin = ((square-40)/(2*rangeMinExpo)); binMax = ((square-40)/(2*rangeMaxExpo)); if (reverseIntensity) { xStaticStart = lS2; xStaticEnd = leftBorder; xEnd = (endPt.getX()+leftBorder)/2; xStart = (startPt.getX()+leftBorder)/2; } else { xEnd = (endPt.getX()+leftBorder)/2; xStart = (startPt.getX()+leftBorder)/2; xStaticEnd = lS2; xStaticStart = leftBorder; } } else { xControl = lS; range = square; double a; binMin = (square/rangeMin); binMax = (square/rangeMax); if (reverseIntensity) { a = square/(staticStartPt.getX()-leftBorder); xStaticStart = lS; xStaticEnd = leftBorder; xEnd = a*(endPt.getX()-leftBorder)+leftBorder; xStart = a*(startPt.getX()-leftBorder)+leftBorder; } else { a = square/(staticEndPt.getX()-leftBorder); xEnd = a*(endPt.getX()-leftBorder)+leftBorder; xStart = a*(startPt.getX()-leftBorder)+leftBorder; xStaticEnd = lS; xStaticStart = leftBorder; } } manager.setType(type, xControl); staticEndPt.setLocation(xStaticEnd, staticEndPt.getY()); staticStartPt.setLocation(xStaticStart, staticStartPt.getY()); endPt.setLocation(xEnd, endPt.getY()); startPt.setLocation(xStart, startPt.getY()); //Set knob location if (reverseIntensity) { setKnobStart((int) xEnd); setKnobEnd((int) xStart); manager.setInputRectangles((int) xEnd, (int) xStart); } else { setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); } }
3,228,862
private void setCurrentInputs(int s, int e) { curStart = "start: "+s; curEnd = "end: "+e; }
private void setCurrentInputs(int s, int e) { curStart = "start: "+s; curEnd = "end: "+e; }
3,228,863
void setDefaultExponential(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); int k = (int) (curveCoefficient*10); binMin = ((square-40)/(2*rangeMinExpo)); binMax = ((square-40)/(2*rangeMaxExpo)); double yStart, yEnd, xStart, xEnd, xStaticStart, xStaticEnd; xStaticStart = 0; xStaticEnd = 0; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); //output knob setKnobOutputStart(leftBorder-10,(int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); if (k == INIT) { if (reverseIntensity) { xStaticStart = lS2; xStaticEnd = leftBorder; range = (int) xStaticStart-leftBorder; } else { xStaticStart = leftBorder; xStaticEnd = lS2; range = (int) xStaticEnd-leftBorder; } } else if (MIN <= k && k < INIT) { k = INIT-k; if (reverseIntensity) { xStaticEnd = leftBorder; xStaticStart = (lS2+k*binMax); range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS2+k*binMax); xStaticStart = leftBorder; range = (int) xStaticEnd-leftBorder; } } else if (k > INIT && k <= MAX) { k = k-INIT; if (reverseIntensity) { xStaticStart = (lS-k*binMin); xStaticEnd = leftBorder; if (xStaticStart < leftBorder+20) xStaticStart = leftBorder+20; range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS-k*binMin); xStaticStart = leftBorder; if (xStaticEnd < leftBorder+20) xStaticEnd = leftBorder+20; range = (int) xStaticEnd-leftBorder; } } staticStartPt.setLocation(xStaticStart, yStart); staticEndPt.setLocation(xStaticEnd, yEnd); xStart = setInputGraphics(inputStart, range); xEnd = setInputGraphics(inputEnd, range); setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); if (reverseIntensity) { xControl = (int) xStaticStart; controlPt.setLocation(xEnd, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { xControl = (int) xStaticEnd; controlPt.setLocation(xEnd, yStart); startPt.setLocation(xStart, yStart); endPt.setLocation(xEnd, yEnd); } manager.setMaxEndX(xControl); repaintCurve(); }
void setDefaultExponential(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); int k = (int) (curveCoefficient*10); binMin = ((square-40)/(2*rangeMinExpo)); binMax = ((square-40)/(2*rangeMaxExpo)); double yStart, yEnd, xStart, xEnd, xStaticStart, xStaticEnd; xStaticStart = 0; xStaticEnd = 0; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); //output knob setKnobOutputStart(leftBorder-10,(int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); if (k == INIT) { if (reverseIntensity) { xStaticStart = lS2; xStaticEnd = leftBorder; range = (int) xStaticStart-leftBorder; } else { xStaticStart = leftBorder; xStaticEnd = lS2; range = (int) xStaticEnd-leftBorder; } } else if (MIN <= k && k < INIT) { k = INIT-k; if (reverseIntensity) { xStaticEnd = leftBorder; xStaticStart = (lS2+k*binMax); range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS2+k*binMax); xStaticStart = leftBorder; range = (int) xStaticEnd-leftBorder; } } else if (k > INIT && k <= MAX) { k = k-INIT; if (reverseIntensity) { xStaticStart = (lS-k*binMin); xStaticEnd = leftBorder; if (xStaticStart < leftBorder+20) xStaticStart = leftBorder+20; range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS-k*binMin); xStaticStart = leftBorder; if (xStaticEnd < leftBorder+20) xStaticEnd = leftBorder+20; range = (int) xStaticEnd-leftBorder; } } staticStartPt.setLocation(xStaticStart, yStart); staticEndPt.setLocation(xStaticEnd, yEnd); xStart = setInputGraphics(inputStart, range); xEnd = setInputGraphics(inputEnd, range); setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); if (reverseIntensity) { xControl = (int) xStaticStart; controlPt.setLocation(xEnd, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { xControl = (int) xStaticEnd; controlPt.setLocation(xEnd, yStart); startPt.setLocation(xStart, yStart); endPt.setLocation(xEnd, yEnd); } manager.setMaxEndX(xControl); repaintCurve(); }
3,228,864
void setDefaultExponential(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); int k = (int) (curveCoefficient*10); binMin = ((square-40)/(2*rangeMinExpo)); binMax = ((square-40)/(2*rangeMaxExpo)); double yStart, yEnd, xStart, xEnd, xStaticStart, xStaticEnd; xStaticStart = 0; xStaticEnd = 0; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); //output knob setKnobOutputStart(leftBorder-10,(int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); if (k == INIT) { if (reverseIntensity) { xStaticStart = lS2; xStaticEnd = leftBorder; range = (int) xStaticStart-leftBorder; } else { xStaticStart = leftBorder; xStaticEnd = lS2; range = (int) xStaticEnd-leftBorder; } } else if (MIN <= k && k < INIT) { k = INIT-k; if (reverseIntensity) { xStaticEnd = leftBorder; xStaticStart = (lS2+k*binMax); range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS2+k*binMax); xStaticStart = leftBorder; range = (int) xStaticEnd-leftBorder; } } else if (k > INIT && k <= MAX) { k = k-INIT; if (reverseIntensity) { xStaticStart = (lS-k*binMin); xStaticEnd = leftBorder; if (xStaticStart < leftBorder+20) xStaticStart = leftBorder+20; range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS-k*binMin); xStaticStart = leftBorder; if (xStaticEnd < leftBorder+20) xStaticEnd = leftBorder+20; range = (int) xStaticEnd-leftBorder; } } staticStartPt.setLocation(xStaticStart, yStart); staticEndPt.setLocation(xStaticEnd, yEnd); xStart = setInputGraphics(inputStart, range); xEnd = setInputGraphics(inputEnd, range); setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); if (reverseIntensity) { xControl = (int) xStaticStart; controlPt.setLocation(xEnd, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { xControl = (int) xStaticEnd; controlPt.setLocation(xEnd, yStart); startPt.setLocation(xStart, yStart); endPt.setLocation(xEnd, yEnd); } manager.setMaxEndX(xControl); repaintCurve(); }
void setDefaultExponential(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); int k = (int) (curveCoefficient*10); binMin = ((square-40)/(2*rangeMinExpo)); binMax = ((square-40)/(2*rangeMaxExpo)); double yStart, yEnd, xStart, xEnd, xStaticStart, xStaticEnd; xStaticStart = 0; xStaticEnd = 0; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); //output knob setKnobOutputStart(leftBorder-10,(int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); if (k == INIT) { if (reverseIntensity) { xStaticStart = lS2; xStaticEnd = leftBorder; range = (int) xStaticStart-leftBorder; } else { xStaticStart = leftBorder; xStaticEnd = lS2; range = (int) xStaticEnd-leftBorder; } } else if (MIN <= k && k < INIT) { k = INIT-k; if (reverseIntensity) { xStaticEnd = leftBorder; xStaticStart = (lS2+k*binMax); range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS2+k*binMax); xStaticStart = leftBorder; range = (int) xStaticEnd-leftBorder; } } else if (k > INIT && k <= MAX) { k = k-INIT; if (reverseIntensity) { xStaticStart = (lS-k*binMin); xStaticEnd = leftBorder; if (xStaticStart < leftBorder+20) xStaticStart = leftBorder+20; range = (int) xStaticStart-leftBorder; } else { xStaticEnd = (lS-k*binMin); xStaticStart = leftBorder; if (xStaticEnd < leftBorder+20) xStaticEnd = leftBorder+20; range = (int) xStaticEnd-leftBorder; } } staticStartPt.setLocation(xStaticStart, yStart); staticEndPt.setLocation(xStaticEnd, yEnd); xStart = setInputGraphics(inputStart, range); xEnd = setInputGraphics(inputEnd, range); setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); if (reverseIntensity) { xControl = (int) xStaticStart; controlPt.setLocation(xEnd, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { xControl = (int) xStaticEnd; controlPt.setLocation(xEnd, yStart); startPt.setLocation(xStart, yStart); endPt.setLocation(xEnd, yEnd); } manager.setMaxEndX(xControl); repaintCurve(); }
3,228,865
void setDefaultLinear(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); xControl = lS; range = square; binMin = (square/rangeMin); binMax = (square/rangeMax); double yStart, yEnd, xStart, xEnd; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); xStart = setInputGraphics(inputStart, square); xEnd = setInputGraphics(inputEnd, square); //Size the rectangles used to control knobs. //Input knob. setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); //Output knob. setKnobOutputStart(leftBorder-10, (int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); //Control points location. if (reverseIntensity) { staticStartPt.setLocation(lS, yStart); staticEndPt.setLocation(leftBorder, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { staticStartPt.setLocation(leftBorder, yStart); startPt.setLocation(xStart, yStart); staticEndPt.setLocation(lS, yEnd); endPt.setLocation(xEnd, yEnd); } //draw curve int k; if (family == QuantumFactory.LINEAR) k = INIT; else if (family == QuantumFactory.LOGARITHMIC) k = MIN; else k = (int) (curveCoefficient*10); setControlLocation(k); }
void setDefaultLinear(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); xControl = lS; range = square; binMin = (square/rangeMin); binMax = (square/rangeMax); double yStart, yEnd, xStart, xEnd; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); xStart = setInputGraphics(inputStart, square); xEnd = setInputGraphics(inputEnd, square); //Size the rectangles used to control knobs. //Input knob. setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); //Output knob. setKnobOutputStart(leftBorder-10, (int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); //Control points location. if (reverseIntensity) { staticStartPt.setLocation(lS, yStart); staticEndPt.setLocation(leftBorder, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { staticStartPt.setLocation(leftBorder, yStart); startPt.setLocation(xStart, yStart); staticEndPt.setLocation(lS, yEnd); endPt.setLocation(xEnd, yEnd); } //draw curve int k; if (family == QuantumFactory.LINEAR) k = INIT; else if (family == QuantumFactory.LOGARITHMIC) k = MIN; else k = (int) (curveCoefficient*10); setControlLocation(k); }
3,228,866
void setDefaultLinear(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); xControl = lS; range = square; binMin = (square/rangeMin); binMax = (square/rangeMax); double yStart, yEnd, xStart, xEnd; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); xStart = setInputGraphics(inputStart, square); xEnd = setInputGraphics(inputEnd, square); //Size the rectangles used to control knobs. //Input knob. setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); //Output knob. setKnobOutputStart(leftBorder-10, (int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); //Control points location. if (reverseIntensity) { staticStartPt.setLocation(lS, yStart); staticEndPt.setLocation(leftBorder, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { staticStartPt.setLocation(leftBorder, yStart); startPt.setLocation(xStart, yStart); staticEndPt.setLocation(lS, yEnd); endPt.setLocation(xEnd, yEnd); } //draw curve int k; if (family == QuantumFactory.LINEAR) k = INIT; else if (family == QuantumFactory.LOGARITHMIC) k = MIN; else k = (int) (curveCoefficient*10); setControlLocation(k); }
void setDefaultLinear(int inputStart, int inputEnd) { setCurrentInputs(inputStart, inputEnd); xControl = lS; range = square; binMin = (square/rangeMin); binMax = (square/rangeMax); double yStart, yEnd, xStart, xEnd; yStart = setOuputGraphics(cdStart); yEnd = setOuputGraphics(cdEnd); xStart = setInputGraphics(inputStart, square); xEnd = setInputGraphics(inputEnd, square); //Size the rectangles used to control knobs. //Input knob. setKnobStart((int) xStart); setKnobEnd((int) xEnd); manager.setInputRectangles((int) xStart, (int) xEnd); //Output knob. setKnobOutputStart(leftBorder-10, (int) yStart); //setKnobOutputEnd(leftBorder-10, topBorder); setKnobOutputEnd(lS+10, topBorder); manager.setOutputRectangles((int) yStart, (int) yEnd); //Control points location. if (reverseIntensity) { staticStartPt.setLocation(lS, yStart); staticEndPt.setLocation(leftBorder, yEnd); startPt.setLocation(xEnd, yStart); endPt.setLocation(xStart, yEnd); } else { staticStartPt.setLocation(leftBorder, yStart); startPt.setLocation(xStart, yStart); staticEndPt.setLocation(lS, yEnd); endPt.setLocation(xEnd, yEnd); } //draw curve int k; if (family == QuantumFactory.LINEAR) k = INIT; else if (family == QuantumFactory.LOGARITHMIC) k = MIN; else k = (int) (curveCoefficient*10); setControlLocation(k); }
3,228,867
private double setInputGraphics(int x, int r) { double b = (double) r/(maximum-minimum); return (b*(x-minimum)+leftBorder); }
private double setInputGraphics(int x, int r) { double b = (double) r/(maximum-minimum); return (b*(x-minimum)+leftBorder); }
3,228,868
private void setInputWindow(int s, int e) { start = ""+s; end = ""+e; }
private void setInputWindow(int s, int e) { start = ""+s; end = ""+e; }
3,228,869
void setInputs(int min, int max, int xStart, int xEnd, int xRealStart, int xRealEnd) { setInputWindow(min, max); setCurrentInputs(xRealStart, xRealEnd); minimum = min; maximum = max; updateInputStartAndEnd(xStart, xEnd); }
void setInputs(int min, int max, int xStart, int xEnd, int xRealStart, int xRealEnd) { setInputWindow(min, max); setCurrentInputs(xRealStart, xRealEnd); minimum = min; maximum = max; updateInputStartAndEnd(xStart, xEnd); }
3,228,870
private void setKnobEnd(int x) { xEnd1 = x; xEnd2 = x-triangleW; xEnd3 = x+triangleW; }
private void setKnobEnd(int x) { xEnd1 = x; xEnd2 = x-triangleW; xEnd3 = x+triangleW; }
3,228,871
private void setKnobOutputEnd(int x, int y) { xEndOutput1 = x; xEndOutput2 = x+triangleH; xEndOutput3 = x+triangleH; yEndOutput1 = y; yEndOutput2 = y-triangleW; yEndOutput3 = y+triangleW; }
private void setKnobOutputEnd(int x, int y) { xEndOutput1 = x; xEndOutput2 = x+triangleH; xEndOutput3 = x+triangleH; yEndOutput1 = y; yEndOutput2 = y-triangleW; yEndOutput3 = y+triangleW; }
3,228,872
private void setKnobOutputStart(int x, int y) { xStartOutput1 = x; xStartOutput2 = x-triangleH; xStartOutput3 = x-triangleH; yStartOutput1 = y; yStartOutput2 = y-triangleW; yStartOutput3 = y+triangleW; }
private void setKnobOutputStart(int x, int y) { xStartOutput1 = x; xStartOutput2 = x-triangleH; xStartOutput3 = x-triangleH; yStartOutput1 = y; yStartOutput2 = y-triangleW; yStartOutput3 = y+triangleW; }
3,228,873
private void setKnobStart(int x) { xStart1 = x; xStart2 = x-triangleW; xStart3 = x+triangleW; }
private void setKnobStart(int x) { xStart1 = x; xStart2 = x-triangleW; xStart3 = x+triangleW; }
3,228,874
private void setKnobStartY(int y) { yStart1 = y; yStart2 = y+triangleH; yStart3 = y+triangleH; }
private void setKnobStartY(int y) { yStart1 = y; yStart2 = y+triangleH; yStart3 = y+triangleH; }
3,228,875
private double setOuputGraphics(int x) { double a = (double) square/outputRange; return (tS-x*a); }
private double setOuputGraphics(int x) { double a = (double) square/outputRange; return (tS-x*a); }
3,228,876
void setReverseIntensity(boolean reverseIntensity) { this.reverseIntensity = reverseIntensity; }
void setReverseIntensity(boolean reverseIntensity) { this.reverseIntensity = reverseIntensity; }
3,228,877
void updateInputEnd(int x, int xReal) { curEnd = "end: "+xReal; /* limit control b/c the method can be called via the histogram Dialog widget */ boolean b = true; /* control to synchronize the display of real value using the Histogram widget the user can still size the inputWindow but for graphics reasons the cursor in the curvePanel cannot be repainted (cf. limit control below.). */ int limit; if (reverseIntensity) limit = (int) endPt.getX()-triangleW; else limit = (int) startPt.getX()+triangleW; if (x >= limit) { setKnobEnd(x); b = false; if (reverseIntensity) startPt.setLocation(x, startPt.getY()); else endPt.setLocation(x, endPt.getY()); if (type == QuantumFactory.EXPONENTIAL) { if (reverseIntensity) controlPt.setLocation(x, endPt.getY()); else controlPt.setLocation(x, startPt.getY()); repaintCurve(); } else setControlLocation(coefficient); } if (b) repaint(0, tS+bottomBorder, width, bottomBorderSupp); }
void updateInputEnd(int x, int xReal) { curEnd = "end: "+xReal; /* limit control b/c the method can be called via the histogram Dialog widget */ boolean b = true; /* control to synchronize the display of real value using the Histogram widget the user can still size the inputWindow but for graphics reasons the cursor in the curvePanel cannot be repainted (cf. limit control below.). */ int limit; if (reverseIntensity) limit = (int) endPt.getX()-triangleW; else limit = (int) startPt.getX()+triangleW; if (x >= limit) { setKnobEnd(x); b = false; if (reverseIntensity) startPt.setLocation(x, startPt.getY()); else endPt.setLocation(x, endPt.getY()); if (type == QuantumFactory.EXPONENTIAL) { if (reverseIntensity) controlPt.setLocation(x, endPt.getY()); else controlPt.setLocation(x, startPt.getY()); repaintCurve(); } else setControlLocation(coefficient); } if (b) repaint(0, tS+bottomBorder, width, bottomBorderSupp); }
3,228,878
void updateInputStart(int x, int xReal) { curStart = "start: "+xReal; /* limit control b/c the method can be called via the histogram Dialog widget */ boolean b = true; /* control to synchronize the display of real value using the Histogram widget the user can still size the inputWindow but for graphics reasons the cursor in the curvePanel cannot be repainted (cf. limit control below.). */ int limit; if (reverseIntensity) limit = (int) startPt.getX()-triangleW; else limit = (int) endPt.getX()-triangleW; if (x <= limit) { xStartMax = x; b = false; setKnobStart(x); if (reverseIntensity) endPt.setLocation(x, endPt.getY()); else startPt.setLocation(x, startPt.getY()); if (type == QuantumFactory.EXPONENTIAL) repaintCurve(); else setControlLocation(coefficient); } if (b) repaint(0, tS+bottomBorder, width, bottomBorderSupp); }
void updateInputStart(int x, int xReal) { curStart = "start: "+xReal; /* limit control b/c the method can be called via the histogram Dialog widget */ boolean b = true; /* control to synchronize the display of real value using the Histogram widget the user can still size the inputWindow but for graphics reasons the cursor in the curvePanel cannot be repainted (cf. limit control below.). */ int limit; if (reverseIntensity) limit = (int) startPt.getX()-triangleW; else limit = (int) endPt.getX()-triangleW; if (x <= limit) { xStartMax = x; b = false; setKnobStart(x); if (reverseIntensity) endPt.setLocation(x, endPt.getY()); else startPt.setLocation(x, startPt.getY()); if (type == QuantumFactory.EXPONENTIAL) repaintCurve(); else setControlLocation(coefficient); } if (b) repaint(0, tS+bottomBorder, width, bottomBorderSupp); }
3,228,879
private void updateInputStartAndEnd(int xStart, int xEnd) { xStartMax = xStart; setKnobEnd(xEnd); setKnobStart(xStart); if (reverseIntensity) { endPt.setLocation(xStart, endPt.getY()); startPt.setLocation(xEnd, startPt.getY()); } else { startPt.setLocation(xStart, startPt.getY()); endPt.setLocation(xEnd, endPt.getY()); } if (type == QuantumFactory.EXPONENTIAL) { if (reverseIntensity) controlPt.setLocation(xEnd, endPt.getY()); else controlPt.setLocation(xEnd, startPt.getY()); repaintCurve(); } else setControlLocation(coefficient); }
private void updateInputStartAndEnd(int xStart, int xEnd) { xStartMax = xStart; setKnobEnd(xEnd); setKnobStart(xStart); if (reverseIntensity) { endPt.setLocation(xStart, endPt.getY()); startPt.setLocation(xEnd, startPt.getY()); } else { startPt.setLocation(xStart, startPt.getY()); endPt.setLocation(xEnd, endPt.getY()); } if (type == QuantumFactory.EXPONENTIAL) { if (reverseIntensity) controlPt.setLocation(xEnd, endPt.getY()); else controlPt.setLocation(xEnd, startPt.getY()); repaintCurve(); } else setControlLocation(coefficient); }
3,228,880