/**
     * Checks whether or not a processor's source version is compatible with the compilation source
     * version. The processor's source version needs to be greater than or equal to the source
     * version of the compile.
     */
    private void checkSourceVersionCompatibility(Source source, Log log) {
      SourceVersion procSourceVersion = processor.getSupportedSourceVersion();

      if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0) {
        log.warning(
            "proc.processor.incompatible.source.version",
            procSourceVersion,
            processor.getClass().getName(),
            source.name);
      }
    }
 @Override
 public SourceVersion getSupportedSourceVersion() {
   // support version 6 or 7
   // we can't compile against RELEASE_6 and maintain Java 7 compatibility, but the
   // processor is Java 7-compatible. We have not tested against Java 8, however.
   SourceVersion[] versions = SourceVersion.values();
   SourceVersion v6 = SourceVersion.RELEASE_6;
   if (versions.length > v6.ordinal() + 1) {
     // the runtime supports release 7, let's use it
     return versions[v6.ordinal() + 1];
   } else {
     return v6;
   }
 }
 public static JavacOptions parse(
     OptionChecker primary, OptionChecker secondary, String... arguments) {
   List<String> recognizedOptions = new ArrayList<String>();
   List<String> unrecognizedOptions = new ArrayList<String>();
   List<String> classNames = new ArrayList<String>();
   List<File> files = new ArrayList<File>();
   for (int i = 0; i < arguments.length; i++) {
     String argument = arguments[i];
     int optionCount = primary.isSupportedOption(argument);
     if (optionCount < 0) {
       optionCount = secondary.isSupportedOption(argument);
     }
     if (optionCount < 0) {
       File file = new File(argument);
       if (file.exists()) files.add(file);
       else if (SourceVersion.isName(argument)) classNames.add(argument);
       else unrecognizedOptions.add(argument);
     } else {
       for (int j = 0; j < optionCount + 1; j++) {
         int index = i + j;
         if (index == arguments.length) throw new IllegalArgumentException(argument);
         recognizedOptions.add(arguments[index]);
       }
       i += optionCount;
     }
   }
   return new JavacOptions(recognizedOptions, classNames, files, unrecognizedOptions);
 }
 /** @throws Exception */
 public void delete() throws Exception {
   Connection delConnection = null;
   String sName = (String) oInput.get("archetype");
   if (!SourceVersion.isName(sName))
     throw new Exception("name " + sName + " is not a valid java identifier");
   PreparedStatement oStmt = null;
   try {
     delConnection = OpenShiftDerbySource.getConnection();
     oStmt = delConnection.prepareStatement("DELETE FROM " + sName + " WHERE id" + sName + " = ?");
     oStmt.setString(1, (String) oInput.get("id" + sName));
     int nRows = oStmt.executeUpdate();
     if (nRows == 0) throw new Exception("no rows deleted");
   } finally {
     if (delConnection != null)
       try {
         delConnection.close();
       } catch (SQLException logOrIgnore) {
       }
     if (oStmt != null)
       try {
         oStmt.close();
       } catch (SQLException logOrIgnore) {
       }
   }
 }
Beispiel #5
0
 @Override
 @DefinedBy(Api.ANNOTATION_PROCESSING)
 public SourceVersion getSupportedSourceVersion() {
   // since this is co-bundled with javac, we can assume it supports
   // the latest source version
   return SourceVersion.latest();
 }
  /**
   * Return true if the argument string is a valid import-style string specifying claimed
   * annotations; return false otherwise.
   */
  public static boolean isValidImportString(String s) {
    if (s.equals("*")) return true;

    boolean valid = true;
    String t = s;
    int index = t.indexOf('*');

    if (index != -1) {
      // '*' must be last character...
      if (index == t.length() - 1) {
        // ... any and preceding character must be '.'
        if (index - 1 >= 0) {
          valid = t.charAt(index - 1) == '.';
          // Strip off ".*$" for identifier checks
          t = t.substring(0, t.length() - 2);
        }
      } else return false;
    }

    // Verify string is off the form (javaId \.)+ or javaId
    if (valid) {
      String[] javaIds = t.split("\\.", t.length() + 2);
      for (String javaId : javaIds) valid &= SourceVersion.isIdentifier(javaId);
    }
    return valid;
  }
Beispiel #7
0
 private static String extractMemberName(String part) {
   checkArgument(Character.isJavaIdentifierStart(part.charAt(0)), "not an identifier: %s", part);
   for (int i = 1; i <= part.length(); i++) {
     if (!SourceVersion.isIdentifier(part.substring(0, i))) {
       return part.substring(0, i - 1);
     }
   }
   return part;
 }
 @Override
 public SourceVersion getSupportedSourceVersion() {
   @Nullable
   SupportedSourceVersion sourceVersion =
       this.getClass().getAnnotation(SupportedSourceVersion.class);
   if (sourceVersion != null) {
     return sourceVersion.value();
   }
   return SourceVersion.latestSupported();
 }
 private static void render(StringBuilder b, Object value) {
   if (value == null) {
     b.append("null");
     return;
   }
   Class<?> valueC = value.getClass();
   if (valueC == String.class || valueC == Character.class) {
     String text = String.valueOf(value);
     if (text.contains("\n")) {
       b.append("'''").append(text.replace("\\", "\\\\").replace("'", "\\'")).append("'''");
     } else {
       b.append('\'').append(text.replace("\\", "\\\\").replace("'", "\\'")).append('\'');
     }
   } else if (valueC == Boolean.class || valueC == Integer.class || valueC == Long.class) {
     b.append(value);
   } else if (value instanceof List) {
     List<?> list = (List<?>) value;
     b.append('[');
     boolean first = true;
     for (Object elt : list) {
       if (first) {
         first = false;
       } else {
         b.append(", ");
       }
       render(b, elt);
     }
     b.append(']');
   } else if (value instanceof Map) {
     Map<?, ?> map = (Map) value;
     b.append('[');
     boolean first = true;
     for (Map.Entry<?, ?> entry : map.entrySet()) {
       if (first) {
         first = false;
       } else {
         b.append(", ");
       }
       Object key = entry.getKey();
       if (key instanceof String && SourceVersion.isName((String) key)) {
         b.append(key);
       } else {
         render(b, key);
       }
       b.append(": ");
       render(b, entry.getValue());
     }
     b.append(']');
   } else {
     b.append("<object of type ").append(valueC.getCanonicalName()).append('>');
   }
 }
 @Override
 public SourceVersion getSourceVersion() {
   if (this._compiler.options.sourceLevel <= ClassFileConstants.JDK1_5) {
     return SourceVersion.RELEASE_5;
   }
   if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_6) {
     return SourceVersion.RELEASE_6;
   }
   try {
     return SourceVersion.valueOf("RELEASE_7"); // $NON-NLS-1$
   } catch (IllegalArgumentException e) {
     // handle call on a JDK 6
     return SourceVersion.RELEASE_6;
   }
 }
  @Override
  protected void doRefactoringAction() {
    final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected();

    final String fqName = getCurrentValue();
    if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) {
      setErrorText("Duplicate language name");
      return;
    }
    if (!((SourceVersion.isName(fqName)))) {
      setErrorText("Language namespace should be valid Java package");
      return;
    }
    final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName);
    ModelAccess modelAccess = myProject.getRepository().getModelAccess();
    modelAccess.executeCommand(
        new Runnable() {
          public void run() {
            renamer.rename(needToRegenerate);
            renamer.update();
          }
        });
    if (needToRegenerate) {
      final Map<SModule, List<SModel>> langs = new LinkedHashMap<SModule, List<SModel>>();
      modelAccess.runReadAction(
          new Runnable() {
            public void run() {
              RefactoringUtil.fillLanguageAndItsExtendingLanguageModels(myLanguage, langs);
            }
          });
      for (final List<SModel> models : langs.values()) {
        ModuleContext context = new ModuleContext(myLanguage, myProject);
        MakeSession sess = new MakeSession(context);
        if (IMakeService.INSTANCE.get().openNewSession(sess)) {
          IMakeService.INSTANCE
              .get()
              .make(sess, new ModelsToResources(context, models).resources(false));
        }
        //         GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage,
        // myProject), params.getModelDescriptors(),
        // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false);
      }
    }
    super.doRefactoringAction();
  }
 @Override
 public SourceVersion getSupportedSourceVersion() {
   return SourceVersion.latestSupported();
 }
Beispiel #13
0
 public static Builder builder(TypeName type, String name, Modifier... modifiers) {
   checkNotNull(type, "type == null");
   checkArgument(SourceVersion.isName(name), "not a valid name: %s", name);
   return new Builder(type, name).addModifiers(modifiers);
 }
  @Override
  protected void doRefactoringAction() {
    final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected();

    final String fqName = getCurrentValue();
    if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) {
      setErrorText("Duplicate language name");
      return;
    }
    if (!((SourceVersion.isName(fqName)))) {
      setErrorText("Language namespace should be valid Java package");
      return;
    }
    final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName);
    ModelAccess.instance()
        .runWriteActionInCommand(
            new Runnable() {
              public void run() {
                renamer.rename(needToRegenerate);
                renamer.update();
              }
            });
    if (needToRegenerate) {
      final Set<Language> langs = new LinkedHashSet<Language>();
      ModelAccess.instance()
          .runReadAction(
              new Runnable() {
                @Override
                public void run() {
                  langs.add(myLanguage);
                  langs.addAll(
                      ModuleRepositoryFacade.getInstance().getAllExtendingLanguages(myLanguage));
                }
              });
      for (final Language l : langs) {
        GenParameters params =
            ModelAccess.instance()
                .runReadAction(
                    new Computable<GenParameters>() {
                      @Override
                      public GenParameters compute() {
                        ModuleTestConfiguration languageConfig = new ModuleTestConfiguration();
                        languageConfig.setModuleRef(l.getModuleReference());
                        languageConfig.setName("tmp");
                        try {
                          return languageConfig.getGenParams(
                              myProject.getComponent(MPSProject.class), true);
                        } catch (IllegalGeneratorConfigurationException e) {
                          return null;
                        }
                      }
                    });
        if (params == null) {
          setErrorText("Rebuild configuration is invalid");
          return;
        }
        ModuleContext context =
            new ModuleContext(myLanguage, ProjectHelper.toMPSProject(myProject));
        MakeSession sess = new MakeSession(context);
        if (IMakeService.INSTANCE.get().openNewSession(sess)) {
          IMakeService.INSTANCE
              .get()
              .make(
                  sess,
                  new ModelsToResources(
                          context,
                          ListSequence.fromListWithValues(
                              new ArrayList<SModel>(),
                              (Iterable<SModel>) params.getModelDescriptors()))
                      .resources(false));
        }
        //         GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage,
        // myProject), params.getModelDescriptors(),
        // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false);
      }
    }
    super.doRefactoringAction();
  }
Beispiel #15
0
 public SourceVersion getSupportedSourceVersion() {
   return SourceVersion.latest();
 }
 public static boolean isValidOptionName(String optionName) {
   for (String s : optionName.split("\\.", -1)) {
     if (!SourceVersion.isIdentifier(s)) return false;
   }
   return true;
 }
Beispiel #17
0
 /**
  * We just return the latest version of whatever JDK we run on. Stupid? Yeah, but it's either that
  * or warnings on all versions but 1.
  */
 @Override
 public SourceVersion getSupportedSourceVersion() {
   return SourceVersion.values()[SourceVersion.values().length - 1];
 }