@Override
  protected void facts(final SortedSet<String> facts) {
    final ValueProperty property = context(ValueProperty.class);
    final NumericRange range = property.getAnnotation(NumericRange.class);
    final String min = range.min();
    final String max = range.max();

    if (min.length() > 0) {
      facts.add(minValueStatement.format(new ValueSnapshot(property, min)));
    }

    if (max.length() > 0) {
      facts.add(maxValueStatement.format(new ValueSnapshot(property, max)));
    }
  }
  @Override
  public void init(final Property property) {
    super.init(property);

    this.possibleTypesService = property.service(PossibleTypesService.class);

    this.possibleTypesServiceListener =
        new Listener() {
          @Override
          public void handle(final Event event) {
            try {
              initBindingMetadata();
            } catch (Exception e) {
              final String msg =
                  failure.format(
                      property.element().type().getSimpleName(), property.name(), e.getMessage());
              Sapphire.service(LoggingService.class).logError(msg);
            }
          }
        };

    this.possibleTypesService.attach(this.possibleTypesServiceListener);

    try {
      initBindingMetadata();
    } catch (Exception e) {
      final String msg =
          failure.format(
              property.element().type().getSimpleName(), property.name(), e.getMessage());
      throw new RuntimeException(msg, e);
    }
  }
  @Override
  protected void facts(final SortedSet<String> facts) {
    final Value<?> value = context(Value.class);
    final String def = value.getDefaultText();

    if (def != null) {
      if (value.definition().hasAnnotation(SensitiveData.class)) {
        facts.add(statementForSensitive.text());
      } else {
        facts.add(statement.format(new ValueSnapshot(value.definition(), def)));
      }
    }
  }
  @Override
  protected Status compute() {
    if (!this.versionCompatibilityService.compatible() && !context(Property.class).empty()) {
      final String message;

      final Version version = this.versionCompatibilityService.version();
      final String versioned = this.versionCompatibilityService.versioned();

      if (version == null) {
        message = versionConstraintTargetNotFoundMessage.text();
      } else {
        message = notCompatibleWithVersionMessage.format(version.toString(), versioned);
      }

      return Status.createErrorStatus(message);
    }

    return Status.createOkStatus();
  }
Пример #5
0
 @Override
 public String getMessage() {
   return cycleDetectedMessage.format(convertToString(this.cycle));
 }
Пример #6
0
 @Override
 public void handleCycle(final List<Entity> cycle) {
   this.stream.println(cycleDetectedMessage.format(convertToString(cycle)));
 }
Пример #7
0
  protected final Status validateExtensions(final Path path) {
    if (this.fileExtensionsService != null) {
      final String fileName = path.lastSegment();

      if (fileName != null) {
        final List<String> extensions = this.fileExtensionsService.extensions();
        final int count = (extensions == null ? 0 : extensions.size());

        if (count > 0) {
          final String trimmedFileName = fileName.trim();
          final int lastdot = trimmedFileName.lastIndexOf('.');
          final String extension;

          if (lastdot == -1) {
            extension = "";
          } else {
            extension = trimmedFileName.substring(lastdot + 1);
          }

          boolean match = false;

          if (extension != null && extension.length() != 0) {
            for (String ext : extensions) {
              if (extension.equalsIgnoreCase(ext)) {
                match = true;
                break;
              }
            }
          }

          if (!match) {
            final String message;

            if (count == 1) {
              message = invalidFileExtensionOne.format(trimmedFileName, extensions.get(0));
            } else if (count == 2) {
              message =
                  invalidFileExtensionTwo.format(
                      trimmedFileName, extensions.get(0), extensions.get(1));
            } else {
              final StringBuilder buf = new StringBuilder();

              for (String ext : extensions) {
                if (buf.length() != 0) {
                  buf.append(", ");
                }

                buf.append(ext);
              }

              message = invalidFileExtensionMultiple.format(trimmedFileName, buf.toString());
            }

            return Status.createErrorStatus(message);
          }
        }
      }
    }

    return Status.createOkStatus();
  }
  @Override
  public String browse(final Presentation context) {
    final Property property = property();

    final EnumSet<JavaTypeKind> kinds = EnumSet.noneOf(JavaTypeKind.class);

    if (this.paramKinds != null) {
      for (String kindString : this.paramKinds.split(",")) {
        kindString = kindString.trim();

        if (kindString.equalsIgnoreCase(JavaTypeKind.CLASS.name())) {
          kinds.add(JavaTypeKind.CLASS);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.ABSTRACT_CLASS.name())) {
          kinds.add(JavaTypeKind.ABSTRACT_CLASS);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.INTERFACE.name())) {
          kinds.add(JavaTypeKind.INTERFACE);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.ANNOTATION.name())) {
          kinds.add(JavaTypeKind.ANNOTATION);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.ENUM.name())) {
          kinds.add(JavaTypeKind.ENUM);
        } else {
          final String msg = typeKindNotRecognized.format(kindString);
          Sapphire.service(LoggingService.class).logError(msg);
        }
      }
    } else {
      final JavaTypeConstraintService javaTypeConstraintService =
          property.service(JavaTypeConstraintService.class);

      if (javaTypeConstraintService != null) {
        kinds.addAll(javaTypeConstraintService.kinds());
      }
    }

    int browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
    int count = kinds.size();

    if (count == 1) {
      final JavaTypeKind kind = kinds.iterator().next();

      switch (kind) {
        case CLASS:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES;
          break;
        case ABSTRACT_CLASS:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES;
          break;
        case INTERFACE:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_INTERFACES;
          break;
        case ANNOTATION:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES;
          break;
        case ENUM:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ENUMS;
          break;
        default:
          throw new IllegalStateException();
      }
    } else if (count == 2) {
      if (kinds.contains(JavaTypeKind.CLASS) || kinds.contains(JavaTypeKind.ABSTRACT_CLASS)) {
        if (kinds.contains(JavaTypeKind.INTERFACE)) {
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES;
        } else if (kinds.contains(JavaTypeKind.ENUM)) {
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS;
        }
      }
    }

    final IProject project = property.element().adapt(IProject.class);

    try {
      final SelectionDialog dlg =
          JavaUI.createTypeDialog(
              ((FormComponentPresentation) context).shell(),
              null,
              project,
              browseDialogStyle,
              false);

      dlg.setTitle(
          dialogTitle.format(
              property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false)));

      if (dlg.open() == SelectionDialog.OK) {
        Object results[] = dlg.getResult();
        assert results != null && results.length == 1;
        if (results[0] instanceof IType) {
          return ((IType) results[0]).getFullyQualifiedName();
        }
      }
    } catch (JavaModelException e) {
      Sapphire.service(LoggingService.class).log(e);
    }

    return null;
  }