@Test
  public void variablesDefinedInVariablesFilesAreLocated_onlyUntilDetectorWantsToContinue()
      throws Exception {
    final IFile sourceFile =
        projectProvider.createFile(
            "importingFile.robot", createVariablesImportSettingsSection("vars.py"));

    final RobotModel model = new RobotModel();
    final RobotSuiteFile suiteFile = model.createSuiteFile(sourceFile);

    final RobotSettingsSection settings = suiteFile.findSection(RobotSettingsSection.class).get();
    final RobotSetting varSetting = (RobotSetting) settings.findChild("Variables");
    final VariablesImport varsImport = (VariablesImport) varSetting.getLinkedElement();

    final VariablesFileImportReference varsImportRef = new VariablesFileImportReference(varsImport);
    varsImportRef.map(ImmutableMap.of("var_a", 42, "var_b", 1729));

    final RobotFileOutput output = suiteFile.getLinkedElement().getParent();
    output.setVariablesImportReferences(newArrayList(varsImportRef));

    final Set<String> visitedVars = new HashSet<>();
    final VariableDefinitionLocator locator = new VariableDefinitionLocator(sourceFile, model);
    locator.locateVariableDefinition(limitedVarFileVariableDetector(visitedVars));
    assertThat(visitedVars).containsOnly("${var_a}");
  }
Exemple #2
0
 private static RobotParser createParser(final RobotSuiteFile model) {
   final RobotProjectHolder holder =
       isNonFileModel(model)
           ? new RobotProjectHolder()
           : model.getProject().getRobotProjectHolder();
   final PathsProvider pathsProvider =
       isNonFileModel(model) ? null : model.getProject().createPathsProvider();
   return RobotParser.create(holder, RobotParserConfig.allImportsLazy(), pathsProvider);
 }
 private void addCustomStyling(final NatTable table, final TableTheme theme) {
   table.addConfiguration(new GeneralTableStyleConfiguration(theme, new RedTableTextPainter()));
   table.addConfiguration(new HoveredCellStyleConfiguration(theme));
   table.addConfiguration(new ColumnHeaderStyleConfiguration(theme));
   table.addConfiguration(new RowHeaderStyleConfiguration(theme));
   table.addConfiguration(new AlternatingRowsStyleConfiguration(theme));
   table.addConfiguration(new CasesElementsStyleConfiguration(theme, fileModel.isEditable()));
   table.addConfiguration(new SelectionStyleConfiguration(theme, table.getFont()));
   table.addConfiguration(new AddingElementStyleConfiguration(theme, fileModel.isEditable()));
 }
Exemple #4
0
 private void createParserIfNeeded() {
   if (parser == null) {
     final RobotSuiteFile suiteFile = fileModelSupplier.get();
     parser = createParser(suiteFile);
     file =
         suiteFile.getFile() == null
             ? new File(suiteFile.getName())
             : suiteFile.getFile().getLocation().toFile();
     reparse();
   }
 }
 @Inject
 @Optional
 private void whenModelIsDisposed(
     @UIEventTopic(RobotModelEvents.SUITE_MODEL_DISPOSED) final RobotElementChange change) {
   if (change.getElement() instanceof RobotSuiteFile
       && change.getKind() == Kind.CHANGED
       && viewer != null) {
     final RobotSuiteFile suiteFile = (RobotSuiteFile) change.getElement();
     viewer.refresh(suiteFile.getSuiteFile().getFile());
   }
 }
 @Inject
 @Optional
 private void whenFileChangesExternally(
     @UIEventTopic(RobotModelEvents.EXTERNAL_MODEL_CHANGE) final RobotElementChange change) {
   if (change.getElement() instanceof RobotSuiteFile
       && change.getKind() == Kind.CHANGED
       && viewer != null) {
     final RobotSuiteFile suiteFile = (RobotSuiteFile) change.getElement();
     viewer.refresh(suiteFile.getSuiteFile().getFile());
   }
 }
 @Inject
 @Optional
 private void whenReconcilationWasDone(
     @UIEventTopic(RobotModelEvents.REPARSING_DONE) final RobotSuiteFile fileModel) {
   if (viewer != null && !viewer.getTree().isDisposed()) {
     viewer.refresh(fileModel.getFile());
   }
 }
  @SuppressWarnings("unchecked")
  @Test
  public void globalVariablesAreLocated_onlyUntilDetectorWantsToContinue() throws Exception {
    final IFile sourceFile = projectProvider.createFile("source.robot", "");

    final RobotModel model = new RobotModel();
    final RobotSuiteFile suiteFile = model.createSuiteFile(sourceFile);
    final RobotProjectHolder projectHolder = suiteFile.getProject().getRobotProjectHolder();
    projectHolder.getGlobalVariables().clear();
    projectHolder
        .getGlobalVariables()
        .addAll(
            newArrayList(
                new ScalarRobotInternalVariable("global_scalar", null),
                new ListRobotInternalVariable("global_list", null),
                new DictionaryRobotInternalVariable("global_dict", null)));

    final Set<String> visitedVars = new HashSet<>();
    final VariableDefinitionLocator locator = new VariableDefinitionLocator(sourceFile, model);
    locator.locateVariableDefinition(limitedGlobalVarDetector(visitedVars));
    assertThat(visitedVars).containsOnly("global_scalar", "global_list");
  }
 private static TestCase getTestCase(final RobotSuiteFile file) {
   final Optional<RobotCasesSection> section = file.findSection(RobotCasesSection.class);
   return section.get().getChildren().get(0).getLinkedElement();
 }
 private RobotCasesSection getSection() {
   return fileModel.findSection(RobotCasesSection.class).orNull();
 }
Exemple #11
0
 private static boolean isNonFileModel(final RobotSuiteFile model) {
   // e.g. history revision
   return model.getFile() == null;
 }