⑴ java代碼如何快速添加作者描述的注釋最好能有詳細的圖解
Window -->Preferences->Java->Editor->Templates ,
在這里new一個自己的插入注釋的快捷方式名稱,具體設置如下:
Name處輸入 remark (任意你喜歡的名稱)
context處選 java 後邊勾選Automatically insert復選框
Description 這里可以任意輸入描述
Pattern :(自定義格式)
/**
* @author ${user}
* @date : ${date} ${time}
*/
到這里全部設置完畢,下面 OK,找個java類,找個空白處測試一下, 輸入remark(前面寫的那個Name名稱),
再alt+/ 應該按一下就能看到剛才的Description的內容。
⑵ 如何給JAVA源代碼文件統一地添加licence信息頭
下面就直接上代碼吧!當然懂得就跳過。
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding right ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.apdplat.platform.util;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* 給JAVA源代碼文件統一地添加licence信息頭
* 檢查文件package、import、類級別注釋、是否有public class
* 用到了Java7的新特性,強大
* @author ysc
*/
public class AddLicenceForJavaFile {
private static int count = 0;
private static List<String> fail = new ArrayList<>();
private static List<String> wrong = new ArrayList<>();
public static void main(String[] args) {
String licence="/**\n" +
" * Licensed to the Apache Software Foundation (ASF) under one or more\n" +
" * contributor license agreements. See the NOTICE file distributed with\n" +
" * this work for additional information regarding right ownership.\n" +
" * The ASF licenses this file to You under the Apache License, Version 2.0\n" +
" * (the \"License\"); you may not use this file except in compliance with\n" +
" * the License. You may obtain a of the License at\n" +
" *\n" +
" * http://www.apache.org/licenses/LICENSE-2.0\n" +
" *\n" +
" * Unless required by applicable law or agreed to in writing, software\n" +
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
" * See the License for the specific language governing permissions and\n" +
" * limitations under the License.\n" +
" */";
addLicenceForJavaFile(new File("D:\\Workspaces\\NetBeansProjects\\APDPlat"),licence);
System.out.println("為 "+count+" 個Java源代碼文件添加licence信息頭");
if(fail.size()>0){
System.out.println("處理失敗個數 "+fail.size());
for(String f : fail){
System.out.println(" "+f);
}
}
if(wrong.size()>0){
System.out.println("JAVA源代碼錯誤個數 "+wrong.size());
for(String w : wrong){
System.out.println(" "+w);
}
}
}
/**
* 給JAVA源代碼文件統一地添加licence信息頭
* @param path 源碼所處的根目錄
* @param licence 許可證信息(在netbeans中復制一段文本粘貼到變數的雙引號內,IDE自動格式化,相當贊)
*/
private static void addLicenceForJavaFile(File path, String licence) {
if (path != null && path.exists()) {
//處理文件夾
if (path.isDirectory()) {
String[] children = path.list();
for (int i = 0; i < children.length; i++) {
File child = new File(path.getPath() + System.getProperty("file.separator") + children[i]);
//遞歸處理
addLicenceForJavaFile(child, licence);
}
} else {
//處理java文件
if (path.getName()。toLowerCase()。endsWith(".java")) {
System.out.println(path.getAbsolutePath());
count++;
try {
byte[] content;
try (RandomAccessFile f = new RandomAccessFile(path, "rw")) {
content = new byte[ (int) f.length()];
f.readFully(content);
}
String text = new String(content);
text = text.trim();
while (text.startsWith("/n")) {
text = text.substring(1);
}
//如果已經有同樣的licence,則忽略
int pos = text.indexOf(licence);
if(pos!=-1){
return;
}
//有package聲明的,保留package以後的內容
if (text.indexOf("package") != -1) {
text = text.substring(text.indexOf("package"));
}
//沒有package聲明的,有import聲明的,保留import以後的內容
else if (text.indexOf("package") == -1 && text.indexOf("import") != -1) {
text = text.substring(text.indexOf("import"));
}
//沒有package聲明也沒有import聲明的,有類級別注釋的,則保留類級別注釋以後的內容
else if (text.indexOf("package") == -1 && text.indexOf("import") == -1 && text.indexOf("/**") != -1 && text.indexOf("public class") != -1 && text.indexOf("/**")<text.indexOf("public class") ) {
text = text.substring(text.indexOf("/**"));
}
//沒有package聲明也沒有import聲明的,也沒有類級別注釋的則保留public class以後的內容
else if (text.indexOf("package") == -1 && text.indexOf("import") == -1 && text.indexOf("public class") != -1 && ( text.indexOf("/**")>text.indexOf("public class") || text.indexOf("/**")==-1 )) {
text = text.substring(text.indexOf("public class"));
}else{
wrong.add(path.getAbsolutePath());
return;
}
try (FileWriter writer = new FileWriter(path)) {
writer.write(licence);
writer.write("\n\n");
writer.write(text);
}
}
catch (Exception ex) {
fail.add(path.getAbsolutePath());
}
}
}
}
}
}
⑶ vs 如何將自己的代碼自動添加版權信息
把那些在Common7\IDE\ItemTemplates\CSharp\2052下面的壓縮復文件復制到制C:\Documents and Settings\用戶名\My Documents\Visual Studio 2005\Templates\ItemTemplates\Visual C#(或者是web版)中去,再對其進行修改.當我們再添加新項的時候,那些模板就出現在"我的模板"下面了. 如果在另外一台機器上寫代碼,只需要把這些模板放到用戶自己的文件夾就可以了,也很方便攜帶.
⑷ 如何在VS中自動添加自定義版權信息
找到 安裝目復錄:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\Web\CSharp
\2052\Class.zip
打開制Class.zip中的 Class.cs文件 就會看到如下所示代碼:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Web;
/// <summary>
///$safeitemrootname$ 的摘要說明
/// </summary>
public class $safeitemrootname$
{
public $safeitemrootname$()
{
//
//TODO: 在此處添加構造函數邏輯
//
}
}
然後只要在其頂部加入版權信息代碼就可以了
⑸ 如何在自己的代碼中聲明版權
菜單工程來-工程1(改成自己的)屬性源-生成-修改對應的內容。 不過網上的vb6企業版對應的是亂碼! 建議用記事本直接更改vbp文件內容。 回答者: ynzsvt - 經理 四級 5-2 11:03工具欄-工程-屬性-生成 就可以看到並修改版權信息
⑹ 當別人復制你的文章時怎麼自動在最後加上版權信息
這個可以通過JS來實現。舉例:
把代碼插入到HTML文件中
<body>
<script type="text/javascript">
document.body.on = function () {
setTimeout( function () {
var text = clipboardData.getData("text");
if (text) {
text = text + "\r\n本文來自:XX網(具體網址)具體網址:"+location.href; clipboardData.setData("text", text);
}
}, 100 )
}
</script>
</body>
即可實現。
⑺ 如何將自己的代碼自動添加版權信息的及其擴展
找到 安裝目錄:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\Web\CSharp \2052\Class.zip 打開Class.zip中的 Class.cs文件 就會看到如下所示回代答碼: using System; using System.Collections.Generic;
⑻ 代碼注釋中怎樣添加版權信息,版權信息都包含什麼內容
代碼注釋中添加版權信息主要包括以下幾項:
1、文件名
2、文件功能描
3、author(作者)
4、時間版
5、創建標識權
6、修改標識
7、修改描述。

(8)java如何將自己的代碼自動添加版權信息擴展閱讀:
法律規定:
根據著作權法的規定,版權所有人可以根據法律在法律規定的年限內對作品享有獨占權。一般而言,其他人需要使用作品,應當事先取得版權所有人的許可,並向其支付報酬。
但是著作權法也規定了若干情形,在法律規定的使用方式下,該種使用無需取得版權所有人的許可,或者無需向其支付報酬。版權的期限,簡單來說,對個人而言,是死後五十年,署名權等精神權利期限無限制;對單位和法人而言,使作品首次發表後五十年。
外國人或者外國在中國國內首次出版的,受我國法律保護,其他的根據國際條約確定,多數重要國家已經和中國一起參加了共同的國際條約,在這些締約國境內產生的作品同樣受到我國著作權法的保護。
⑼ 如何設置 Eclipse 創建類時自動添加 自動生成的 作者以及日期注釋
使用Eclipse 編寫Java代碼時,自動生成的注釋信息都是按照預先設置好的格式
生成的。
修改作者、日期注釋格式:
打開Windows->Preferences->Java->Code Style->Code Templates,
點擊右邊窗口中的Comments,可以看到有很多選項,
我們便可對此注釋信息模板進行編輯。
如我們希望在一個Java文件的開頭設置作者信息、日期信息。
選擇Types,點擊Edit,將
/**
* @author ${user}
* ${tags}
*/
將${user}刪除,改成你希望顯示的名字
將${tags}刪除,
點擊Insert Variable,選擇Date,這樣就會自動生成日期信息。
在你需要添加註釋的地方點擊Sources->Ganarate Element Comment,
或者使用快捷鍵 Alt+Shift+J ,則 eclipse 自動在該類前面添加註釋。