⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generator.java

📁 JAVA的加密库之一
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			Node n = node.getTypeSuf();
			if (n != null && n instanceof ASizeTypeSuf)
				superType += "_OF";

			outBuiltInClass(isPublic, className, superType);

			data.clear();

			state = REFERENCE_ONLY;
			break;

		case REFERENCE_ONLY:
			break;
		}
	}

	public void outASetAuxType(ASetAuxType node) {
		defaultOut(node);
		switch (state) {
		case GENERATING:
			break;
		case REFERENCE_ONLY:
			//
			// should handle inner classes here
			//
			String superType = "SET";
			Node n = node.getTypeSuf();
			if (n != null && n instanceof ASizeTypeSuf)
				superType += "_OF";

			if (data.isEmpty())
				generateCompound(type);
			else
				generateCompound(data);

			type = superType;

			state = NOT_GENERATING;
			break;
		}
	}

	public void inASequenceOfAuxType(ASequenceOfAuxType node) {
		defaultIn(node);
		switch (state) {
		case GENERATING:
			boolean isPublic = ast.isPublic(moduleName, className);
			outBuiltInClass(isPublic, className, "SEQUENCE_OF");

			data.clear();

			state = REFERENCE_ONLY;
			break;
		case REFERENCE_ONLY:
			break;
		}
	}

	public void outASequenceOfAuxType(ASequenceOfAuxType node) {
		defaultOut(node);
		switch (state) {
		case GENERATING:
			break;
		case REFERENCE_ONLY:
			//
			// should handle inner classes here
			//
			if (data.isEmpty())
				generateCompound(type);
			else
				generateCompound(data);

			type = "SEQUENCE_OF";

			state = NOT_GENERATING;
			break;
		}
	}

	public void inASequenceAuxType(ASequenceAuxType node) {
		defaultIn(node);
		switch (state) {
		case GENERATING:
			boolean isPublic = ast.isPublic(moduleName, className);
			Node n = node.getTypeSuf();
			String superType = "SEQUENCE";
			if (n != null && n instanceof ASizeTypeSuf)
				superType += "_OF";

			outBuiltInClass(isPublic, className, superType);

			data.clear();

			state = REFERENCE_ONLY;
			break;
		case REFERENCE_ONLY:
			break;
		}
	}

	public void outASequenceAuxType(ASequenceAuxType node) {
		defaultOut(node);
		switch (state) {
		case GENERATING:
			break;
		case REFERENCE_ONLY:
			//
			// should handle inner classes here
			//
//			boolean isPublic = ast.isPublic(moduleName, className);
			String superType = "SEQUENCE";
			Node n = node.getTypeSuf();
			if (n != null && n instanceof ASizeTypeSuf)
				superType += "_OF";
//
//			outBuiltInClass(isPublic, className, superType);

			if (data.isEmpty())
				generateCompound(type);
			else
				generateCompound(data);

			type = superType;

			state = NOT_GENERATING;
			break;
		}
	}

	public void inANamedElementType(ANamedElementType node) {
		defaultIn(node);
		lower = null;
		type = null;
		tag = null;
		switch (state) {
		case GENERATING:
			break;
		case REFERENCE_ONLY:
			break;
		}
	}

	public void outANamedElementType(ANamedElementType node) {
		defaultOut(node);
		switch (state) {
		case GENERATING:
			break;
		case REFERENCE_ONLY:
			try {
				NodeInfo lastLower = (NodeInfo) data.getLast();
				if (lastLower.getElementName().equals(lower))
					data.removeLast();
			} catch (NoSuchElementException ignored) {
			}

			data.add(new NodeInfo(lower, type, tag, node.getElementTypeSuf()));
			break;
		}
	}

	public void outAUpperType(AUpperType node) {
		defaultOut(node);
		type = node.getUpper().getText().trim();
		Node at = node.getAccessType();
		if (at != null)
			type += "."+((AAccessType) at).getUpper().getText().trim();

		switch (state) {
		case GENERATING:
			boolean isPublic = ast.isPublic(moduleName, className);

			outClass(isPublic, className, type);
			outUpperConstructors(className, type);

			state = REFERENCE_ONLY;
			break;
		case REFERENCE_ONLY:
			break;
		}
	}

	public void outALowerNamedType(ALowerNamedType node) {
		defaultOut(node);
		switch (state) {
		case GENERATING:
			break;
		case REFERENCE_ONLY:
			lower = node.getLower().getText().trim();
			data.add(new NodeInfo(lower, type, tag, null));
			break;
		}
	}

	// Other instance methods -- Java source code generation per-se
	// -------------------------------------------------------------------------

	private void activate(PrintWriter pw) {
		if (this.pw != null)
			throw new IllegalStateException();

		this.pw = pw;
	}

	private void passivate() {
		if (pw != null)
			pw.close();

		pw = null;
	}

	private void outBeginClass(String pkg) {
	   cat.info("==> outBeginClass("+String.valueOf(pkg)+")");

		out("package "+pkg+"; // machine generated code. DO NOT EDIT");
		out();
		out("import cryptix.asn1.lang.*;");
		out();

	   cat.info("<== outBeginClass()");
	}

	private void outBuiltInClass(boolean isPublic, String className, String type) {
	   cat.info("==> outBuiltInClass("+String.valueOf(isPublic)+", "+String.valueOf(className)+", "+String.valueOf(type)+")");

		outClass(isPublic, className, type);
		outConstructors(className, type);

	   cat.info("<== outBuiltInClass()");
	}

	private void outClass(boolean isPublic, String className, String type) {
	   cat.info("==> outClass("+String.valueOf(isPublic)+", "+String.valueOf(className)+", "+String.valueOf(type)+")");

		String superclass = superclassFromType(type);
		StringBuffer sb = new StringBuffer();
		if (isPublic)
			sb.append("public ");

		sb.append("class ").append(className).append(" extends ").append(superclass).append(" {");
		out(sb.toString());
		out();

	   cat.info("<== outClass()");
	}

	private void outEndClass() {
	   cat.info("==> outEndClass()");

		out("}");
		out();
		out("// Generated by the cryptix ASN.1 kit on "+String.valueOf(new Date()));

	   cat.info("<== outEndClass()");
	}

	private void outConstructors(String className, String type) {
	   cat.info("==> outConstructors("+String.valueOf(className)+", "+String.valueOf(type)+")");
	   cat.info("    tag: "+String.valueOf(tag));

		String superclass = superclassFromType(type);

		out("   // Constructor(s)");
		out("   // -------------------------------------------------------------------------");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a blank Name.");
		out("    */");
		out("   public "+className+"() {");
		if (type.equals("CHOICE") || type.equals("ANY"))
			out("      super(\"\", null);");
		else
         if (tag != null)
   			out("      super(\"\", "+tag+");");
   		else
   			out("      super(\"\", new Tag(Tag."+type+"));");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a designated Name.");
		out("    *");
		out("    * @param name the designated Name for this new instance.");
		out("    */");
		out("   public "+className+"(String name) {");
		if (type.equals("CHOICE") || type.equals("ANY"))
			out("      super(name, null);");
		else
         if (tag != null)
   			out("      super(name, "+tag+");");
   		else
   			out("      super(name, new Tag(Tag."+type+"));");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a designated Name and Tag.");
		out("    *");
		out("    * @param name the designated Name for this new instance.");
		out("    * @param tag the designated tag for this new instance.");
		out("    */");
		out("   public "+className+"(String name, Tag tag) {");
		out("      super(name, tag);");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a trivial Name and an");
		out("    * initial value.");
		out("    *");
		out("    * @param value the initial value of this instance.");
		out("    */");
		out("   public "+className+"("+superclass+" value) {");
		out("      this(\"\", value);");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a designated Name and an");
		out("    * initial value.");
		out("    *");
		out("    * @param name the designated Name for this new instance.");
		out("    * @param value the initial value of this instance.");
		out("    */");
		out("   public "+className+"(String name, "+superclass+" value) {");
		if (type.equals("CHOICE") || type.equals("ANY"))
			out("      this(name, null, value);");
		else
         if (tag != null)
   			out("      this(name, "+tag+", value);");
   		else
   			out("      this(name, new Tag(Tag."+type+"), value);");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type given its Name, Tag and initial");
		out("    * value.");
		out("    *");
		out("    * @param name the designated Name for this new instance.");
		out("    * @param tag the specific tag for this instance.");
		out("    * @param value the initial value for this instance.");
		out("    */");
		out("   public "+className+"(String name, Tag tag, "+superclass+" value) {");
		out("      super(name, tag, value == null ? null : value.value());");
		out("   }");
		out();

		outBeginAttributes();

	   cat.info("<== outConstructors()");
	}

	private void outUpperConstructors(String className, String type) {
	   cat.info("==> outUpperConstructors("+String.valueOf(className)+", "+String.valueOf(type)+")");

		String superclass = superclassFromType(type);

		out("   // Constructor(s)");
		out("   // -------------------------------------------------------------------------");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a blank Name.");
		out("    */");
		out("   public "+className+"() {");
		out("      super();");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a designated Name.");
		out("    *");
		out("    * @param name the designated Name for this new instance.");
		out("    */");
		out("   public "+className+"(String name) {");
		out("      super(name);");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a designated Name and Tag.");
		out("    *");
		out("    * @param name the designated Name for this new instance.");
		out("    * @param tag the designated tag for this new instance.");
		out("    */");
		out("   public "+className+"(String name, Tag tag) {");
		out("      super(name, tag);");
		out("   }");
		out();
		out("   /**");
		out("    * Constructs a new instance of this type with a trivial Name and an ");
		out("    * initial value.");
		out("    *");
		out("    * @param value the initial value of this instance.");
		out("    */");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -