Exemplo n.º 1
0
    def build(self, is_main=False, is_method=False, is_class=False):
        '''
        Copies the base java file, moves the changes into it and compiles it.
        If an Exception occurs, the change is rolled back.
        '''
        shutil.copyfile(START_FILE, MAIN_FILE)
        self.parse_file(MAIN_FILE)
        
        # Attempt to compile the new change
        try:
            Util.compile_java([MAIN_FILE] + self.full_class_names)
        except Exception as e:
            if verbose_output == True:
                print 'Exception: %s' % e
            else:
                print 'An Exception occurred compiling the program'

            # Determine who caused the exception and remove the code
            if is_main is True:
                self.main_input.pop()
            elif is_method is True:
                self.methods.pop()
                self.method_names.pop()
            elif is_class is True:
                self.classes.pop()
                self.class_names.pop()
                filename = self.full_class_names.pop()
                Util.remove_file(filename)

            return

        if is_main is True:
            self.run()
Exemplo n.º 2
0
 def create_class(self):
     '''
     Create a new file using the class name, and then copy the class
     contents into the new file.
     '''
     filename = "%s.%s" % (self.class_names[-1], 'java')
     Util.remove_file(filename)
     
     self.full_class_names.append(filename)
     file = open(filename, 'w+')
     file.write(self.classes[-1])
     file.close()