Пример #1
0
  /**
   * Processes "import" PI. Checks syntax of the identifier
   *
   * @param data
   */
  @NbBundle.Messages({
    "ERR_importNotJavaIdentifier=Imported symbol must be a class or package name.",
    "ERR_importInsideElement=Imports must be at top level, not nested in elements",
    "ERR_importFollowsRoot=Import must not follow the root element",
    "ERR_missingImportIdentifier=Identifier missing in ?import instruction"
  })
  private FxNode handleFxImport(String data) {
    if (data.endsWith("?")) {
      // recovery from unterminated ?> -- the lexer will report ? as part of PI data.
      data = data.substring(0, data.length() - 1);
    }
    if ("".equals(data)) {
      addError("missing-import-identifier", ERR_missingImportIdentifier());
      return null;
    }
    int lastDot = data.lastIndexOf('.');
    boolean starImport = false;

    if (lastDot != -1 && lastDot < data.length() - 1) {
      if (FX_IMPORT_STAR.equals(data.substring(lastDot + 1))) {
        starImport = true;
        data = data.substring(0, lastDot);
      }
    }
    ImportDecl decl = accessor.createImport(data, starImport);
    if (!FxXmlSymbols.isQualifiedIdentifier(data)) {
      addAttributeError(
          ContentLocator.ATTRIBUTE_DATA,
          "import-not-java-identifier",
          ERR_importNotJavaIdentifier(),
          data);
      accessor.makeBroken(decl);
    }

    imports.add(decl);

    return decl;
  }