リファクタリングの名前の変更

Visual COBOL では、ネイティブ COBOL の変数、セクション、段落、およびマネージ COBOL の識別子の名前を変更できます。

名前を変更するには、次の操作を行います。

  1. エディターで名前を変更する項目を右クリックし、[Refactor >Rename] をクリックします。

    名前変更ダイアログ ボックスが開きます。

  2. 名前を変更する識別子の [New Name] を指定します。
  3. 名前を変更する範囲を、現在のプロジェクトのみにするか、ソリューション全体にするかを指定します。次のように、[Search Scope] を設定します。
    • Current COBOL program (現在の COBOL プログラム)
    • Current project only (現在のプロジェクトのみ)
    • All COBOL projects in solution (ソリューション内のすべての COBOL プロジェクト)
  4. [Preview] をクリックして、提示された変更を確認し、承認します。

    必要に応じて、[Skip preview changes if references are all confirmed] をオンにします。

  5. [Apply] をクリックして、提示された変更を行います。

変更の適用後、[Edit > Undo] または [Edit > Global Undo *Global Rename] をクリックすると、変更を元に戻すことができます。

ソリューション エクスプローラーからマネージ プロジェクトのクラス ファイルの名前を変更するには、次の操作を行います。

  1. ソリューション エクスプローラーでプロジェクトのクラス ファイルを右クリックし、[Rename] をクリックします。
  2. 新しいファイル名を指定し、Enter を押します。

    [Suggested Rename] ダイアログ ボックスが開きます。必要に応じ、コード内における変更するクラス名のすべてのインスタンスについて名前を変更できます。

  3. このクラスに対する参照の名前を変更する範囲を、現在のプロジェクトのみにするか、ソリューション全体にするかを指定し、[Yes] をクリックします。
    ヒント: Micro Focus では、エラーが発生する可能性を低減するために、常にソリューション全体で識別子の名前を変更することをお奨めします。

COBOL 予約語への名前の変更

COBOL 予約語でもある新しい名前を指定できます。Visual COBOL では、そのような名前をコードに挿入すると、# をプレフィックスとして使用してエスケープされます。たとえば、変数または識別子の名前を name という語に変更すると、古い名前は #name に置き換えられます。

コード内で識別子が :: 表記によって参照されている場合、エスケープ文字は必要ありません。次の例は、COBOL 予約語である新しい名前が 2 つの変数に対して指定されたクラスを示しています。このコードでは、これらの変数を :: を使用して直接参照しています。

       class-id SomeClass.
       working-storage section.
       01 #name   binary-long.
       01 #accept binary-long.
       01 var-a   binary-long.

       method-id SomeMethod.
           set #name to 0
           set self::accept to 0
           set var-a to 0
           set self::var-a to 0

           declare x as type SomeClass.
           set x::name to 0
       end method.
       end class.

COBOL アプリケーションを他の言語に公開する場合、エスケープ文字 # は考慮されません。たとえば、C# から、この 2 つの変数に name および accept としてアクセスできます。

制約事項

The following restrictions apply to rename refactoring:

  • When renaming variables in a copybook, the copybook must be shown inline in the referencing program in the expanded copybook view.It is not possible to rename in copybooks opened as stand-alone files in the editor.
  • It is not possible to rename identifiers in copybooks referenced using a COPY...使用すべきではありません。
  • It is not possible to rename typedef members.
  • It is not possible to rename identifiers in any resources that are outside the current solution.

The following restrictions apply to native COBOL only:

  • Renaming only works in the current program.
  • It is not possible to rename a program or an entry-point.
  • It is not possible to rename copybooks from the editor.You can rename copybooks from Solution Explorer.This, however, does not change any of the references to the copybooks in the code.

The following restrictions apply to managed COBOL only:

  • It is only possible to rename identifiers that are defined in the COBOL projects within the current solution.
  • It is not possible to rename namespaces.
  • It is not possible to rename a COBOL type from another .NET language and vice versa - it is not possible to rename .NET types from a COBOL project.