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

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

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

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

    これにより、その変数のすべての出現箇所がエディターで強調表示され、[Rename] ウィジェットが開きます。

  2. 名前を変更する範囲を、現在のプロジェクトのみにするか、ソリューション全体にするかを指定します。次のように、[Search Scope] を設定します。
    • [Current COBOL program]
    • [Current project only]
    • [All COBOL projects in solution]
  3. [Preview] をオンにして内容を確認し、提示された変更を承認します。
  4. 名前を変更する変数のいずれかの出現箇所で新しい名前の入力を開始します。
  5. [Rename] ウィジェットで [Apply] をクリックします。

    [Preview] をオンにした場合は、名前が変更される変数のすべてのファイルと出現箇所のリストが表示されます。

  6. [Apply] をもう一度クリックします。

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

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

  1. 名前を変更する変数の出現箇所で入力を開始します。
  2. 変更している行の余白に電球が表示されます。
  3. 電球をクリックすると、使用できるクイック アクションが表示されます。
  4. 使用できるいずれかのアクションを選択して、現在のプロジェクトまたはソリューション全体で名前を変更します。

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

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

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

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

COBOL 予約語への名前の変更

COBOL 予約語でもある新しい名前を指定できます。Enterprise Developer では、そのような名前をコードに挿入すると、# をプレフィックスとして使用してエスケープされます。たとえば、変数または識別子の名前を 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 data items in JCL or BMS files.
  • 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.