def changeAnnotationState_(self, doAnnotate):
     '''
     Change the function annotation state.
     '''
     LANG = ProgramExecution.Languages
     currentProject = getCurrentProject()
     mySourceCodeParser = SourceCodeParser(currentProject.getLanguage(), currentProject.getMainFile(), currentProject.getMainFunction())
     auxFileName = self.fileToAnnotate_ + ".aux"
     shutil.copy(self.fileToAnnotate_, auxFileName)
     try:
         if currentProject.getLanguage() == LANG.C_PLUS_PLUS:
             if doAnnotate:
                 mySourceCodeParser.annotateCppFunctions(auxFileName, self.fileToAnnotate_, self.headerToInclude_, [self.functionName_])
             else:
                 mySourceCodeParser.unannotateCppFunctions(auxFileName, self.fileToAnnotate_, [self.functionName_])
         else:
             assert currentProject.getLanguage() == LANG.PYTHON
             if doAnnotate:
                 mySourceCodeParser.annotatePythonObject(self.headerToInclude_, True, self.functionName_)
             else:
                 mySourceCodeParser.unAnnotatePythonObject(self.headerToInclude_, True, self.functionName_)
     except Exception:
         QMessageBox.about(None, 'ERROR','Error al (des)anotar la funcion. Traceback: \n\n"' + traceback.print_exc())
         shutil.copy(auxFileName, self.fileToAnnotate_)
         os.remove(auxFileName)
Esempio n. 2
0
 def changeAnnotationState_(self, doAnnotate):
     '''
     Change the function annotation state.
     '''
     LANG = ProgramExecution.Languages
     currentProject = getCurrentProject()
     mySourceCodeParser = SourceCodeParser(currentProject.getLanguage(),
                                           currentProject.getMainFile(),
                                           currentProject.getMainFunction())
     auxFileName = self.fileToAnnotate_ + ".aux"
     shutil.copy(self.fileToAnnotate_, auxFileName)
     try:
         if currentProject.getLanguage() == LANG.C_PLUS_PLUS:
             if doAnnotate:
                 mySourceCodeParser.annotateCppFunctions(
                     auxFileName, self.fileToAnnotate_,
                     self.headerToInclude_, [self.functionName_])
             else:
                 mySourceCodeParser.unannotateCppFunctions(
                     auxFileName, self.fileToAnnotate_,
                     [self.functionName_])
         else:
             assert currentProject.getLanguage() == LANG.PYTHON
             if doAnnotate:
                 mySourceCodeParser.annotatePythonObject(
                     self.headerToInclude_, True, self.functionName_)
             else:
                 mySourceCodeParser.unAnnotatePythonObject(
                     self.headerToInclude_, True, self.functionName_)
     except Exception:
         QMessageBox.about(
             None, 'ERROR',
             'Error al (des)anotar la funcion. Traceback: \n\n"' +
             traceback.print_exc())
         shutil.copy(auxFileName, self.fileToAnnotate_)
         os.remove(auxFileName)
    def processCppTestingFunction_(self,
                                   doAdd,
                                   functionName,
                                   classNames=None,
                                   functionNames=None):
        mainFileName = os.path.join(TEST_FILES_FOLDER,
                                    "testAnnotateMainCpp.cpp")
        originalFileName = os.path.join(TEST_FILES_FOLDER, functionName + ".h")
        resultFileName = os.path.join(TEST_FILES_FOLDER,
                                      functionName + "_result.h")
        expectedFileName = os.path.join(TEST_FILES_FOLDER,
                                        functionName + "_expected.h")

        if not doAdd:
            aux = originalFileName
            originalFileName = expectedFileName
            expectedFileName = aux

        mySourceCodeParser = SourceCodeParser(
            ProgramExecution.Languages.C_PLUS_PLUS, mainFileName)
        headerToInclude = functionName + ".h"

        #Verify second (un)annotation yields the same file
        try:
            originalFileBkp = originalFileName + '.bkp'
            shutil.copy(originalFileName, originalFileBkp)
            for i in range(2):
                try:
                    ok = False
                    if doAdd:
                        if classNames is None and functionNames is None:
                            mySourceCodeParser.annotateCppFile(
                                originalFileName, resultFileName,
                                headerToInclude)
                        else:
                            if classNames is not None:
                                if functionNames is not None:
                                    assert len(classNames) == 1
                                    mySourceCodeParser.annotateCppClassFunctions(
                                        originalFileName, resultFileName,
                                        headerToInclude, classNames[0],
                                        functionNames)
                                else:
                                    mySourceCodeParser.annotateCppClasses(
                                        originalFileName, resultFileName,
                                        headerToInclude, classNames)
                            if functionNames is not None and classNames is None:
                                mySourceCodeParser.annotateCppFunctions(
                                    originalFileName, resultFileName,
                                    headerToInclude, functionNames)
                    else:
                        if classNames is None and functionNames is None:
                            mySourceCodeParser.unannotateCppFile(
                                originalFileName, resultFileName)
                        else:
                            if classNames is not None:
                                mySourceCodeParser.unannotateCppClasses(
                                    originalFileName, resultFileName,
                                    classNames)
                            if functionNames is not None and classNames is None:
                                mySourceCodeParser.unannotateCppFunctions(
                                    originalFileName, resultFileName,
                                    functionNames)
                    self.compareFileContents_(resultFileName, expectedFileName)
                    ok = True
                finally:
                    if i == 0 and ok:
                        shutil.copy(resultFileName, originalFileName)
                    if os.path.exists(resultFileName):
                        os.remove(resultFileName)
        finally:
            if os.path.exists(originalFileBkp):
                shutil.copy(originalFileBkp, originalFileName)
                os.remove(originalFileBkp)