java-comment-preprocessor

授权协议 Apache-2.0 License
开发语言 JavaScript
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 穆乐逸
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Changelog

7.0.5 (SNAPSHOT)

  • added support of build under JDK 16
  • updated dependencies

7.0.4 (26-sep-2020)

  • fixed default flag state keep comments for start in CLImode #24
  • fixed working directory detection in CLI mode

7.0.3 (13-sep-2020)

  • added way to get info about all input and produced files from preprocessor context
  • reworked Gradle plug-in, removed extension and now properties should be directly provided fortask #21
  • refactoring, removed some auxiliary plugins from build process and extra code

Full changelog

Introduction

Initially the tool developed for J2ME game development in 2002. It was too expensive for me to support multiple sources for many J2ME devices especially if it was needed just change position of several calls for different devices. So the preprocessor was born and because Java is the main technology in use, it is sharpened for use with C/Java family languages (which have import sections and C-comment style). For long time the preprocessor was proprietary project but since 2011 it was opened as an OSS project.

I guess, at present it is the most powerful two-pass Java preprocessor which aware for document structure (prefix, body and postfix), loops and even can use XML files as data sources (I used to generate static web-sites with it). At present the preprocessor represented as a solid uber-jar including Maven, ANT and Gradle interface code and can be used with these tools as their plugin. Minimal required JDK is 1.8

Some Linux repositories provide the preprocessor just out of the box as package libcomment-preprocessor-java.

Mind map with all options

How to use

The Preprocessor can work as:

The preprocessor has been published in the Maven Central.

    <build>
        <plugins>
...
           <plugin>
                <groupId>com.igormaznitsa</groupId>
                <artifactId>jcp</artifactId>
                <version>7.0.4</version>
                <executions>
                    <execution>
                        <id>preprocessSources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>preprocess</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
...
        </plugins>
    </build>    

How to use from command line

The uber-jar can be started directly under Java through CLI interface. Let's take a look at short example below how to start it in command line under Linux:

java -jar jcp-7.0.4.jar  --i:./test --o:./result

The example above just preprocessing files from ./test folder (which extensions allowed to be preprocessed by default), and placing result files into ./result folder. Keep in your mind that the preprocessor processing not all files, for instance XML files will not be preprocessed by default. Files which extension not marked for preprocessing will be just copied (of course if the extensions is not in the excluded extension list)

More complex example:

java -jar jcp-7.0.4.jar  --c --r --v --f:java,xml --ef:none --i:./test --o:./result  '--p:HelloWorld=$Hello world$'
  • --c clear the destination folder before work
  • --r remove all Java-style comments from preprocessed result files
  • --v show verbose log about preprocessing process
  • --f include .java and .xml files into preprocessing (by default the preprocessor doesn't preprocess XNL files and the extension should to be defined explicitly)
  • --ef don't exclude any extension from preprocessing
  • --i use ./test as source folder
  • --o use ./result as destination folder
  • --p define named global variable HelloWorld? with the 'Hello world' content
  • --z turn on checking of file content before replacement, if the same content then preprocessor will not replace the file
  • --es allow whitespace between comment and directive (by default it is turned off)

Some examples

Example of Java sources with directives

In Java the only allowed way to inject directives and to not break work of tools and compilers - is to use commented space, so that the preprocessor uses it.

//#local TESTVAR="TEST LOCAL VARIABLE"
//#echo TESTVAR=/*$TESTVAR$*/
//#include "./test/_MainProcedure.java"

public static final void testproc()
{
 System.out.println(/*$VARHELLO$*/);
 System.out.println("// Hello commentaries");
 //#local counter=10
        //#while counter!=0
        System.out.println("Number /*$counter$*/");
        //#local counter=counter-1
        //#end
 System.out.println("Current file name is /*$SRV_CUR_FILE$*/");
 System.out.println("Output dir is /*$SRV_OUT_DIR$*/");
 //#if issubstr("Hello","Hello world")
 System.out.println("Substring found");
 //#endif
}

Multi-sectioned documents

In opposite a regular document, a Java document has as minimum two sections - prefix (where situated import and special information) and body. For access to such sections there are special preprocessing directives //#prefix[-|+], //#postfix[-|+]. They allow turning on or off output into prefix and postfix sections.

//#prefix+
 import java.lang.*;
 //#prefix-
 public class Main {
  //#prefix+
  import java.util.*;
  //#prefix-
  public static void main(String ... args){}
 }

How to remove all comments from sources

Sometimes it is very useful to remove totally all comments from sources, such possibility included into JCP and can be activated with either a special flag or command line switcher. The example below shows how to remove all comments with CLI use:

java -jar ./jcp-7.0.4.jar --i:/sourceFolder --o:/resultFolder -ef:none --r
  • 在将一个Eclipse的项目转移到AndroidStudio的过程中,碰到了的问题如下: Error:Execution failed for task ':learnChinese:mergeDebugResources'. > Error: java.util.concurrent.ExecutionException:com.android.ide.common.process.Proces

  • 问题发现: 早上修改dto的属性时,看到在controller中存在这样的注解: * Description:查询客户订单信息 <br> * * @author li.xueru<br> * @param request <br> * @return String <br> * @throws BaseAppException <br> */ @ApiOperation(value =

  • #pragma comment ( lib,"wpcap.lib" ) 表示链接wpcap.lib这个库。 和在工程设置里写上链入wpcap.lib的效果一样,不过这种方法写的 程序别人在使用你的代码的时候就 不用再设置工程settings了。告诉连接器连接的时候要找ws2_32.lib,这样你就不用在linker的lib设置 里指定这个lib了。 比如: #include "Mwic_32.h"

  • 内容 在学习 C/C++ Windows程序设计时,看到了这条代码 #pragma comment(lib,"xxx.lib") 百度百科:在所有的预处理指令中,#pragma指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作。 #pragma comment的作用就是链接文件,文件可以是compiler,exestr,lib 和 linker文件。 这里#prag

  • #pragma 的使用 我们经常用到的是#pragma comment(lib,"*.lib")这类的。 #pragma comment(lib,“Ws2_32.lib”)表示链接Ws2_32.lib这个库。 和在工程设置里写上链入Ws2_32.lib的效果一样,不过这种方法写的 程序别人在使用你的代码的时候就不用再设置工程settings了 尽管 C 和 C++ 都已经有标准,但是几乎每个编译器

  • Error:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:Error:Execution failed for task':app:mergeDebugResources'.>Error:java.util.concurrent.ExecutionException:c

  • Java 注释(Java Doc Comment)与注解(Annotation) 注解(Annotation):又称为 标注,即 Java 标注,是 JDK5.0 引入的一种注释机制。 Java 语言中的类、方法、变量、参数和包等都可以被标注,用来对这些元素进行说明,注释。 和 Javadoc(文档注释) 不同,Java 标注可以通过反射获取标注内容。 也叫元数据。一种代码级别的说明。 它不会直接

  • 注解能被用来为程序元素( 类、 方法、 成员变量等) 设置元数据。 值得指出的是, 注解不影响程序代码的执行, 无论增加、 删除注解, 代码都始终如一地执行。 如果希望让程序中的注解在运行时起一定的作用, 只有通过某种配套的工具对注解中的信息进行访问和处理, 访问和处理注解的工具统称 APT( Annotation Processing Tool )。 基本注解 Java 提供了5 个基本注解:

  • http://code.google.com/p/pre-processor-java/ http://code.google.com/p/java-comment-preprocessor/ http://prebop.sourceforge.net/ (http://boldinventions.com/index.php?option=com_content&view=article&id=

  • Android Studio在修改添加完项目内容时候,再运行编译出现 错误:Error:Execution failed for task ':app:mergeDebugResources'. > Error: Java.util.concurrent.ExecutionException: com.Android.ide.common.process.ProcessException:   

  • Error:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:Error:Execution failed for task':app:mergeDebugResources'.>Error:java.util.concurrent.ExecutionException:c

  • 集成第三方代码出现此错误Execution failed for task ':app:javaPreCompileDebug' 解决方式如下: 在app的build.gradle中,添加如下代码: javaCompileOptions { annotationProcessorOptions { includeCompile

  • Java_基础_注释(comment) /** * 用来测试注释的用法(文档注释) * @author creep creep creep * */ public class A_comment { public static void main(String[] args) { //单行注释 /* * 多行注释(行内注释) */ } }

  • 过期的 @SuppressWarnings(“deprecation”)表示不检测过期的方法 假设: List list = {“1”,“2”} ; @SuppressWarnings(“deprecation”) list.count(); 在这里假设 list.count() 这个方法是被弃用了的方法,加上这个注解就表示不去检测这个方法是否被弃用

 相关资料
  • 钩子名称 comment 钩子类型 前台模板钩子 钩子参数 object_id:你要评论内容的 id; table_name:你要评论内容所在表名,不带表前缀; object_title:你要评论内容的标题或名称; url:你要评论内容加密过后的URL,用cmf_url_encode方法生成; user_id:文章作者id,(5.0.180123新增) 插件返回结果 类型:string 渲染后评论

  • COMMENT方法 用于在生成的SQL语句中添加注释内容,例如: Db::table('think_score')->comment('查询考试前十名分数') ->field('username,score') ->limit(10) ->order('score desc') ->select(); 最终生成的SQL语句是: SELECT username,sco

  • 评论模块 增加网站互动,用户评论管理 评论模块的使用 下载安装 评论模块配置 评论管理 1、下载安装 从ZTBCMS 模块->模块->模块仓库 中找到评论模块,点击下载。 下载完成后,解压出来,并命名为“Comments”,然后将它copy至项目目录中 接着在后台本地模块中进行安装。 2、评论模块配置 可对评论模块进行配置,是否开启评论、是否允许游客评论、是否需要审核等选项 3、评论管理 在后台的

  • https://github.com/miniframework/rest_comment python 生成rest 接口文档

  • caozha-comment,一个功能强大的评论系统,采用原生PHP编写,不依赖任何框架,特点:易上手,零门槛,界面清爽极简,极便于二次开发。 可以自动适配电脑、平板和手机等不同客户端。 演示地址 http://caozha.com/git/demo/caozha-admin/public/index/comment/index 其他版本 1、此为原生PHP编写的评论系统,如需要thinkphp版

  • Comment Remover 用来删除各种源码文件中的注释,支持的语言包括:汇编, Pascal, Java, C, C++, D, and Python.