Refactoring Patterns (Third Part)

部署运行你感兴趣的模型镜像
refactoring Patterns:第三部分
内容:
应用Refactoring需要考虑的问题
数据库
接口改变和Published Interface
用Refactoring思想武装自己的设计
编程语言
支持Refactoring的语言特点和编程风格
使Refactoring复杂化的语言特点和编程风格
解析引用的方式
反射、Meta级程序分析和变更
一个小结
关于作者
相关内容:
该系列的其他部分
应用 Refactoring 需要考虑的问题

石一楹 (shiyiying@hotmail.com)
浙江大学灵峰科技开发公司技术总监
2001 年 12 月

本文紧接 第二部分,继续讲述应用 refactoring 应该考虑的问题。


任何一种技术都可能有它自己的麻烦。但是往往在我们使用一种新技术的时候,可能还不能深入到发现它带来的问题,正如Martin Fowler所说:
在学习一种能够极大提高生产力的新技术时,你很难看到它不能应用的场合。

他把Refactoring的情景和面向对象出现使得情景相比较:
情况恰如10年前的对象。不是我不考虑对象有限制。只是因为我不知道那些限制是什么,虽然我知道他带来的好处。

但是Martin Fowler和其他人确实观察到了Refactoring可能引发的某些问题,我们可以来看一下:

数据库
很多应用程序的代码可能与数据库结构绑定得非常严密。如果要修改这些代码,需要改变还有数据库结构和原先已经存在的数据。

O/R mapping可以用来解决这个问题。使用专业的O/R mapping工具能够实现关系数据库的迁移。但是,就算这样,迁移也需要付出额外的代价。

如果你使用的并非关系数据库,而是直接采用OO数据库,这一点的影响可能会变得更小。

所以,我建议每一个使用数据库的应用程序都应该采用O/R mapping或者OO数据库。目前出现的各种企业级应用解决方案如J2EE本身就提供这样的构架。

如果你的代码没有这样一个隔离层,那么你必须手工或编写专用的代码来实现这些迁移功能。

接口改变和Published Interface
有很多Refactoring操作(如rename method name)确实改变了接口。面向对象承诺在接口不变的情况下给你以实现变化的自由。但如果接口发生改变,那么你就不得不非常小心了。

为了保证系统的可观察行为不变,你必须保证这些接口的改变不会影响到你无法取得的代码。如果你拥有了所有使用该接口的类的源代码,你只要把这些地方同时也改变即可。

但是,如果你没有办法得到所有这些使用的代码,那么你就不得不采取额外的途径。事实上,如果你的代码是一个代码库(如Sun JDK的集合框架)或者是一个Framework,那么这一点几乎是不可避免的。

要使得这些依赖于你老接口的代码能够继续工作,你必须保留老接口。现在你有两套接口,一套是老的,一套是经过Refactoring的新接口。你必须把对老接口的调用分派到新接口。千万不要拷贝整个函数体,因为这会产生大量的重复代码。

这种方法虽然能够解决问题,但是却非常麻烦。由于Refactoring通常会涉及到状态、行为在不同类之间的转移,如果一个方法从一个类移动到另一个类,那么使用这种分派的方法可能需要一些不必要的中间状态或者参数。这会使你的代码显得难以理解和维护,在一定程度上削减了Refactoring所应起到的作用。

因此,这种方法只应该用于过渡时期。给用户一定的时间,允许用户代码能够逐渐转移到新接口,在超过一定的期限后,删除老方法,不再支持老接口。这也是Java Deprecated API的意义所在。

像这样保护接口虽然可能,却非常困难。你至少需要在一段时间内维护两套接口,以保证原来使用你老接口的客户代码还能继续使用你的新代码,Martin Fowler把这些接口称之为Published Interface。虽然你不可能避免公布你的一部分接口,不然谁也不能使用你的代码,但是过早公布不必要的接口会造成不必要的麻烦,就像Martin Fowler给我们的提示:
Don't publish interface prematurely.

用Refactoring思想武装自己的设计
如果你不理解OO的思想,那么你就不可能真正地用好OO语言。同样,如果你没有把Refactoring的思想贯穿于你的开发过程,你也不可能用好Refactoring。

Refactoring包含两个方面的想法:它告诉你可以从简单的设计做起,因为即使代码已经实现,你还是可以用它来改进你的设计。然而,另一方面,它绝不是告诉你可以信手涂鸦。我给你的忠告是:
Started simple but not stupid。

如果你一开始就设计了愚蠢的接口,甚至是错误的接口。在程序演变的过程中,这一部分可能变成系统的核心。对之进行Refactoring可能需要花费大量的精力,而改变接口和类的操作可能会是这些Refactoring主要内容。对核心类接口的变化可能会迅速波及到系统的各个层面,如果你的总体结构是好的,那么这种涟漪可能会在某一个层次消失。(譬如环状和层次性的体系结构。)如果你没有这样的抽象机制和保护体系,那么对核心类的修改将会直接导致整个系统的变更,这是不能接受的。

所以,在设计一个类的时候,你需要问自己几个问题,如果事情发生了这种变化,我会如何修改来适应?如果发生了那种变化,我会怎样来适应?如果你能够想到可能的Refactoring方法,那么证明你的设计是可行的。这并不意味着你要去实现这样的设计,而是保证自己的设计不会把自己逼入到死角。如果你发现自己的代码几乎没有办法Refactoring来适应新的需求,那么你要仔细考虑考虑别的思路。

每次公司的程序员问我一个设计是否合理,我总是反问几个问题:你如何适应这种变化,适应那种可能的变化。我同时指出现在没有必要去实现这些变化。我很少直接回答他好坏或者给他一个答案,但在思考了我反问他们的问题以后,程序员总能对自己的设计做出好的评判,从而找到很好的解决方案。所以,使用Refactoring的思想考虑你的设计。

编程语言
虽然Refactoring是一种独立于编程语言的方法,但你所使用的编程语言往往会或多或少地影响到Refactoring的效率,从而影响你采用Refactoring的积极性.

Refactoring最初的研究是从Smalltalk开始的.随着Refactoring在Smalltalk上的极端成功,更多的面向对象社团开始把Refactoring扩展到其他语言环境.但是不同语言的不同特点有时会对应用Refactoring提供便利,有时却会制造障碍.

支持Refactoring的语言特点和编程风格

.静态类型检查和存取保护
静态类型检查可以缩小对你想要refactoring的程序部分的可能引用范围.举个例子,如果你想要改变一个类的成员函数名,那么你必须改变函数的声明和所有对该函数的引用.如果程序很大,那么查找这样和改变这样的引用就比较困难.

和Smalltalk这样的动态类型语言不同,对静态类型进行检查的语言(C++,Java,Delphi等等)通常具有类继承和相关的存取保护(private,protected,public),这些特点使得寻找对某一个函数的引用变得相对简单.如果重命名的函数原先声明为private,那么对该函数的引用只能是在他所在的类或者该类的友类(C++)等等.如果声明为protected,那么只有本类,子类和友员类(同包类)才能引用到该成员函数.如果声明为public,那么还只需要在本类、子类、友类和明确引入该类的其他类即可(include,import)。

我想提起大家注意的另外一个问题。在软件的最初开发和整个开发流程中尽可能早地应用好的设计原则是一个软件项目成功的重要因素。不管是从封装的角度还是从Refactoring的角度来看,定义成员变量和成员函数应当从最高的保护级别开始。除了非常明显的例子之外,你最好首先把成员变量和函数定义为private。随着软件开发的进一步深入,当其他类对该类提出"额外"的请求,你慢慢地放宽保护。原则是:如果能够放在private,就不要放在protected,能够放在protected,就不要放在public。

使Refactoring复杂化的语言特点和编程风格

预处理指令
某些语言环境通常提供预处理指令,如C++。因为预处理不是C++语言的一部分,这通常使得Refactoring工具实现变得困难。有研究指出,程序往往需要在预处理之后才能进行更好的结构分析,而在这一点上预处理指令信息已经不存在。而refactoring一旦没有和源代码的直接联系,程序员将不太可能对理解Refactoring的结果。

依赖对象尺寸和实现格式的代码
C++继承自C,这使得C++很快流行起来,程序员的学习难度也大大减小。但这是一把双面刃。C++因此而支持很多编程风格,而其中的某些违反了优雅设计的基本原则。

使用C++的指针、cast操作和sizeof(Object)这些依赖对象尺寸和实现格式的代码很难refactor。指针和cast介入别名的概念,这使得你要查找所有对此Object有引用的代码变得非常困难。这些特征的一个共同特点就是它们暴露了对象的内部表达格式,从而违反了抽象的基本原则。

举个例子,C++使用V-table机制来表达可执行程序中的成员变量。继承得来的成员变量在前,本类定义的在后。一个我们经常使用,并且认为安全的refactoring是push up fields,也就是把子类中的一个成员变量移到父类。因为现在变量从父类继承而非本类定义,经过refactoring后的可执行程序之中变量的实际位置已经发生了变化。

如果程序中所有的变量引用都是通过类接口来存取的,那么这样的变化不会有问题。但是,如果变量是通过指针运算(譬如,一个程序员有一个指向对象的指针,知道变量在类的第9个字节,然后使用指针运算给第9个字节赋值),上面的refacoting过程就会改变程序的行为。类似情况,如果程序员使用if (sizeof(object)==15)这样的条件判断,refactoring的结果很可能会对该对象的大小产生影响,从而变得不再安全。

语言复杂度
语言越复杂,对语言语义的形式化就更加困难。相对Smalltalk和稍微复杂的Java而言,C++可称得上是一种非常复杂的语言,这使得对C++程序refactoring工具的研究大大滞后于smalltalk和Java。

解析引用的方式
由于C++绝大部分是在编译是解析引用,所以在refactoring一个程序之后通常至少需要编译程序的一部分,把可执行程序连接起来才能看到测试refactoring的影响。相反,smalltalk和CLOS提供解释执行和增量编译的技术。Java虽然没有解释执行,但它明确把一个公共类放在一个单元内的要求,使得执行一系列refactoring的成本减小。由于refactoring的基本方法就是每一步小小变化,每一步测试,对于C++而言,每一个迭代的成本相对较高,从而程序员变得不太愿意做这些小变化。

反射、Meta级程序分析和变更
这一点可能更让研究者关心而不是实践者的问题。C++并没有提供对meta级程序分析和变更的很好支持,你无法找到象CLOS这样的metaobject协议。这些协议有时对refactoring非常有用,譬如我们可以把一个类的选定实例改变为另一个类的实例,这时候可以利用这些反射协议实现把所有对旧对象的引用自动变更为指向新的实例。

Java虽然还没有像CLOS这样强大的meta级功能,但是JDK的发展已经显示了Java在这方面非常强劲的实力。象上面的例子,我们也可以在Java上做到。

一个小结
基于上面的比较,我们认为Java是应用Refactoring的最佳语言。最近的观察也证实了这一点[Lance Tokuda]。

从实践者的角度来看,目前最流行的refactoring文献基本上都采用Java语言作为范例,其中包括Martin的《Refactoring》。目前市场上有数种支持Java和Smalltalk的Refactoring工具,而C++的工具却几乎没有。这里面,语言本身的复杂性有很大的影响。

当然,这并不意味着C++程序员就不应该使用refactoring技术,只不过需要更多的努力。Refactoring技术已经证明自己是OO系统演化的最佳方法之一,不要放弃。

关于作者
石一楹,现任浙江大学灵峰科技开发公司技术总监。多年从事OO系统分析、设计。现主要研究方向为Refactoring和分析模式。你可以通过shiyiying@hotmail.com和我联系。

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

Language support for Java ™ for Visual Studio Code Visual Studio Marketplace Installs Join the chat at https://gitter.im/redhat-developer/vscode-java Build Status License Provides Java ™ language support via Eclipse ™ JDT Language Server, which utilizes Eclipse ™ JDT, M2Eclipse and Buildship. Quick Start Install the Extension On the following platforms, the extension should activate without any setup : win32-x64, darwin-x64, darwin-arm64, linux-x64, linux-arm64. If on another platform, or using the "universal" version, you can set a Java Development Kit. It must be Java 21 or above. Optionally, download and install a Java Development Kit for your project (Java 1.8 or above is supported). See Project JDKs for more details Extension is activated when you first access a Java file Recognizes projects with Maven or Gradle build files in the directory hierarchy. Features screencast Supports code from Java 1.8 to Java 24 Maven pom.xml project support Gradle project support (with experimental Android project import support) Standalone Java files support As-you-type reporting of parsing and compilation errors Code completion Code/Source actions / Refactoring Javadoc hovers Organize imports triggered manually or on save when pasting code into a java file with Ctrl+Shift+v (Cmd+Shift+v on Mac). Type search Code outline Code folding Code navigation Code lens (references/implementations) Highlights Code formatting (on-type/selection/file) Code snippets Annotation processing support (automatic for Maven projects) Semantic selection Diagnostic tags Call Hierarchy Type Hierarchy To launch and debug your Java programs, it's recommended you install Java Debug Extension for Visual Studio Code. See the changelog for the latest release. You might also find useful information in the project Wiki. Setting the JDK Java Tooling JDK Now that Java extension will publish platform specific versions, it will embed a JRE for supported platforms such as win32-x64, linux-x64, linux-arm64, darwin-x64, darwin-arm64. The embedded JRE is used to launch the Language Server for Java. Users are only responsible for configuring Project JDKs to compile your Java projects. The following part is only kept for the universal version without embedded JRE. The tooling JDK will be used to launch the Language Server for Java. And by default, will also be used to compile your projects. Java 21 is the minimum required version. The path to the Java Development Kit can be specified by the java.jdt.ls.java.home setting in VS Code settings (workspace/user settings). If not specified, it is searched in the following order until a JDK meets current minimum requirement. the JDK_HOME environment variable the JAVA_HOME environment variable on the current system path Project JDKs If you need to compile your projects against a different JDK version, it's recommended you configure the java.configuration.runtimes property in your user settings, eg: "java.configuration.runtimes": [ { "name": "JavaSE-1.8", "path": "/path/to/jdk-8", }, { "name": "JavaSE-11", "path": "/path/to/jdk-11", }, { "name": "JavaSE-24", "path": "/path/to/jdk-24", "default": true }, ] The default runtime will be used when you open standalone Java files. Available commands The following commands are available: Switch to Standard Mode: switches the Java Language Server to Standard mode. This command is only available when the Java Language Server is in LightWeight mode. Java: Reload Projects (Shift+Alt+U): It forces project configuration / classpath updates (eg. dependency changes or Java compilation level), according to the project build descriptor. Java: Import Java Projects into Workspace: detects and imports all the Java projects into the Java Language Server workspace. Java: Open Java Language Server Log File: opens the Java Language Server log file, useful for troubleshooting problems. Java: Open Java Extension Log File: opens the Java extension log file, useful for troubleshooting problems. Java: Open All Log Files: opens both the Java Language Server log file and the Java extension log file. Java: Force Java Compilation (Shift+Alt+B): manually triggers compilation of the workspace. Java: Rebuild Projects: manually triggers a full build of the selected projects. Java: Open Java Formatter Settings: opens the Eclipse formatter settings. Creates a new settings file if none exists. Java: Clean Java Language Server Workspace: cleans the Java language server workspace. Java: Attach Source: attaches a jar/zip source to the currently opened binary class file. This command is only available in the editor context menu. Java: Add Folder to Java Source Path: adds the selected folder to its project source path. This command is only available in the file explorer context menu and only works for unmanaged folders. Java: Remove Folder from Java Source Path: removes the selected folder from its project source path. This command is only available in the file explorer context menu and only works for unmanaged folders. Java: List All Java Source Paths: lists all the Java source paths recognized by the Java Language Server workspace. Java: Show Build Job Status: shows the Java Language Server job status in Visual Studio Code terminal. Java: Go to Super Implementation: goes to the super implementation for the current selected symbol in editor. Java: Restart Java Language Server: restarts the Java language server. Supported VS Code settings The following settings are supported: java.home : Deprecated, please use 'java.jdt.ls.java.home' instead. Absolute path to JDK home folder used to launch the Java Language Server. Requires VS Code restart. java.jdt.ls.lombokSupport.enabled: Whether to enable lombok support. Defaults to true. java.jdt.ls.vmargs : Extra VM arguments used to launch the Java Language Server. Requires VS Code restart. java.errors.incompleteClasspath.severity : Specifies the severity of the message when the classpath is incomplete for a Java file. Supported values are ignore, info, warning, error. java.trace.server : Traces the communication between VS Code and the Java language server. java.configuration.updateBuildConfiguration : Specifies how modifications on build files update the Java classpath/configuration. Supported values are disabled (nothing happens), interactive (asks about updating on every modification), automatic (updating is automatically triggered). java.configuration.maven.userSettings : Path to Maven's user settings.xml. java.configuration.checkProjectSettingsExclusions: Deprecated, please use 'java.import.generatesMetadataFilesAtProjectRoot' to control whether to generate the project metadata files at the project root. And use 'files.exclude' to control whether to hide the project metadata files from the file explorer. Controls whether to exclude extension-generated project settings files (.project, .classpath, .factorypath, .settings/) from the file explorer. Defaults to false. java.referencesCodeLens.enabled : Enable/disable the references code lenses. java.implementationCodeLens : Enable/disable the implementations code lens for the provided categories. java.signatureHelp.enabled : Enable/disable signature help support (triggered on (). java.signatureHelp.description.enabled : Enable/disable to show the description in signature help. Defaults to false. java.contentProvider.preferred : Preferred content provider (see 3rd party decompilers available in vscode-java-decompiler). java.import.exclusions : Exclude folders from import via glob patterns. Use ! to negate patterns to allow subfolders imports. You have to include a parent directory. The order is important. java.import.gradle.enabled : Enable/disable the Gradle importer. Specify the Gradle distribution used by the Java extension: java.import.gradle.wrapper.enabled: Use Gradle from the 'gradle-wrapper.properties' file. Defaults to true. java.import.gradle.version: Use Gradle from the specific version if the Gradle wrapper is missing or disabled. java.import.gradle.home: Use Gradle from the specified local installation directory or GRADLE_HOME if the Gradle wrapper is missing or disabled and no 'java.import.gradle.version' is specified. java.import.gradle.arguments: Arguments to pass to Gradle. java.import.gradle.jvmArguments: JVM arguments to pass to Gradle. java.import.gradle.user.home: setting for GRADLE_USER_HOME. java.import.gradle.offline.enabled: Enable/disable the Gradle offline mode. Defaults to false. java.import.maven.enabled : Enable/disable the Maven importer. java.autobuild.enabled : Enable/disable the 'auto build'. java.maxConcurrentBuilds: Set max simultaneous project builds. java.completion.enabled : Enable/disable code completion support. java.completion.guessMethodArguments : Specify how the arguments will be filled during completion. Defaults to auto. auto: Use off only when using Visual Studio Code - Insiders, other platform will defaults to insertBestGuessedArguments. off: Method arguments will not be inserted during completion. insertParameterNames: The parameter names will be inserted during completion. insertBestGuessedArguments: The best guessed arguments will be inserted during completion according to the code context. java.completion.filteredTypes: Defines the type filters. All types whose fully qualified name matches the selected filter strings will be ignored in content assist or quick fix proposals and when organizing imports. For example 'java.awt.*' will hide all types from the awt packages. java.completion.favoriteStaticMembers : Defines a list of static members or types with static members. java.completion.importOrder : Defines the sorting order of import statements. java.format.enabled : Enable/disable the default Java formatter. java.format.settings.url : Specifies the url or file path to the Eclipse formatter xml settings. java.format.settings.profile : Optional formatter profile name from the Eclipse formatter settings. java.format.comments.enabled : Includes the comments during code formatting. java.format.onType.enabled : Enable/disable on-type formatting (triggered on ;, } or <return>). java.foldingRange.enabled: Enable/disable smart folding range support. If disabled, it will use the default indentation-based folding range provided by VS Code. java.maven.downloadSources: Enable/disable download of Maven source artifacts as part of importing Maven projects. java.maven.updateSnapshots: Force update of Snapshots/Releases. Defaults to false. java.codeGeneration.hashCodeEquals.useInstanceof: Use 'instanceof' to compare types when generating the hashCode and equals methods. Defaults to false. java.codeGeneration.hashCodeEquals.useJava7Objects: Use Objects.hash and Objects.equals when generating the hashCode and equals methods. This setting only applies to Java 7 and higher. Defaults to false. java.codeGeneration.useBlocks: Use blocks in 'if' statements when generating the methods. Defaults to false. java.codeGeneration.generateComments: Generate method comments when generating the methods. Defaults to false. java.codeGeneration.toString.template: The template for generating the toString method. Defaults to ${object.className} [${member.name()}=${member.value}, ${otherMembers}]. java.codeGeneration.toString.codeStyle: The code style for generating the toString method. Defaults to STRING_CONCATENATION. java.codeGeneration.toString.skipNullValues: Skip null values when generating the toString method. Defaults to false. java.codeGeneration.toString.listArrayContents: List contents of arrays instead of using native toString(). Defaults to true. java.codeGeneration.toString.limitElements: Limit number of items in arrays/collections/maps to list, if 0 then list all. Defaults to 0. java.selectionRange.enabled: Enable/disable Smart Selection support for Java. Disabling this option will not affect the VS Code built-in word-based and bracket-based smart selection. java.showBuildStatusOnStart.enabled: Automatically show build status on startup, defaults to notification. notification: Show the build status via progress notification. terminal: Show the build status via terminal. off: Do not show any build status. For backward compatibility, this setting also accepts boolean value, where true has the same meaning as notification and false has the same meaning as off. java.project.outputPath: A relative path to the workspace where stores the compiled output. Only effective in the WORKSPACE scope. The setting will NOT affect Maven or Gradle project. java.project.referencedLibraries: Configure glob patterns for referencing local libraries to a Java project. java.completion.maxResults: Maximum number of completion results (not including snippets). 0 (the default value) disables the limit, all results are returned. In case of performance problems, consider setting a sensible limit. java.configuration.runtimes: Map Java Execution Environments to local JDKs. java.server.launchMode: Standard: Provides full features such as intellisense, refactoring, building, Maven/Gradle support etc. LightWeight: Starts a syntax server with lower start-up cost. Only provides syntax features such as outline, navigation, javadoc, syntax errors. The lightweight mode won't load thirdparty extensions, such as java test runner, java debugger, etc. Hybrid: Provides full features with better responsiveness. It starts a standard language server and a secondary syntax server. The syntax server provides syntax features until the standard server is ready. And the syntax server will be shutdown automatically after the standard server is fully ready. Default launch mode is Hybrid. Legacy mode is Standard java.sources.organizeImports.starThreshold: Specifies the number of imports added before a star-import declaration is used, default is 99. java.sources.organizeImports.staticStarThreshold: Specifies the number of static imports added before a star-import declaration is used, default is 99. java.imports.gradle.wrapper.checksums: Defines allowed/disallowed SHA-256 checksums of Gradle Wrappers. java.project.importOnFirstTimeStartup: Specifies whether to import the Java projects, when opening the folder in Hybrid mode for the first time. Supported values are disabled (never imports), interactive (asks to import or not), automatic (always imports). Default to automatic. java.project.importHint: Enable/disable the server-mode switch information, when Java projects import is skipped on startup. Defaults to true. java.import.gradle.java.home: Specifies the location to the JVM used to run the Gradle daemon. java.project.resourceFilters: Excludes files and folders from being refreshed by the Java Language Server, which can improve the overall performance. For example, ["node_modules",".git"] will exclude all files and folders named 'node_modules' or '.git'. Pattern expressions must be compatible with java.util.regex.Pattern. Defaults to ["node_modules",".git"]. java.templates.fileHeader: Specifies the file header comment for new Java file. Supports configuring multi-line comments with an array of strings, and using ${variable} to reference the predefined variables. java.templates.typeComment: Specifies the type comment for new Java type. Supports configuring multi-line comments with an array of strings, and using ${variable} to reference the predefined variables. java.references.includeAccessors: Include getter, setter and builder/constructor when finding references. Default to true. java.configuration.maven.globalSettings : Path to Maven's global settings.xml. java.configuration.maven.lifecycleMappings : Path to Maven's lifecycle mappings xml. java.eclipse.downloadSources : Enable/disable download of Maven source artifacts for Eclipse projects. java.references.includeDecompiledSources : Include the decompiled sources when finding references. Default to true. java.project.sourcePaths: Relative paths to the workspace where stores the source files. Only effective in the WORKSPACE scope. The setting will NOT affect Maven or Gradle project. java.typeHierarchy.lazyLoad: Enable/disable lazy loading the content in type hierarchy. Lazy loading could save a lot of loading time but every type should be expanded manually to load its content. java.codeGeneration.insertionLocation: Specifies the insertion location of the code generated by source actions. Defaults to afterCursor. afterCursor: Insert the generated code after the member where the cursor is located. beforeCursor: Insert the generated code before the member where the cursor is located. lastMember: Insert the generated code as the last member of the target type. java.codeGeneration.addFinalForNewDeclaration: Whether to generate the 'final' modifer for code actions that create new declarations. Defaults to none. none: Do not generate final modifier fields: Generate 'final' modifier only for new field declarations variables: Generate 'final' modifier only for new variable declarations all: Generate 'final' modifier for all new declarations java.settings.url : Specifies the url or file path to the workspace Java settings. See Setting Global Preferences java.symbols.includeSourceMethodDeclarations : Include method declarations from source files in symbol search. Defaults to false. java.quickfix.showAt : Show quickfixes at the problem or line level. java.configuration.workspaceCacheLimit : The number of days (if enabled) to keep unused workspace cache data. Beyond this limit, cached workspace data may be removed. java.import.generatesMetadataFilesAtProjectRoot : Specify whether the project metadata files(.project, .classpath, .factorypath, .settings/) will be generated at the project root. Defaults to false. java.inlayHints.parameterNames.enabled: Enable/disable inlay hints for parameter names. Supported values are: none(disable parameter name hints), literals(Enable parameter name hints only for literal arguments) and all(Enable parameter name hints for literal and non-literal arguments). Defaults to literals. java.compile.nullAnalysis.nonnull: Specify the Nonnull annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if java.compile.nullAnalysis.mode is set to disabled. java.compile.nullAnalysis.nullable: Specify the Nullable annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if java.compile.nullAnalysis.mode is set to disabled. java.compile.nullAnalysis.nonnullbydefault: Specify the NonNullByDefault annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if java.compile.nullAnalysis.mode is set to disabled. java.import.maven.offline.enabled: Enable/disable the Maven offline mode. Defaults to false. java.codeAction.sortMembers.avoidVolatileChanges: Reordering of fields, enum constants, and initializers can result in semantic and runtime changes due to different initialization and persistence order. This setting prevents this from occurring. Defaults to true. java.jdt.ls.protobufSupport.enabled: Specify whether to automatically add Protobuf output source directories to the classpath. Note: Only works for Gradle com.google.protobuf plugin 0.8.4 or higher. Defaults to true. java.jdt.ls.androidSupport.enabled: [Experimental] Specify whether to enable Android project importing. When set to auto, the Android support will be enabled in Visual Studio Code - Insiders. Note: Only works for Android Gradle Plugin 3.2.0 or higher. Defaults to auto. java.completion.postfix.enabled: Enable/disable postfix completion support. Defaults to true. java.completion.chain.enabled: Enable/disable chain completion support. Defaults to false. java.completion.matchCase: Specify whether to match case for code completion. Defaults to firstLetter. java.compile.nullAnalysis.mode: Specify how to enable the annotation-based null analysis. Supported values are disabled (disable the null analysis), interactive (asks when null annotation types are detected), automatic (automatically enable null analysis when null annotation types are detected). Defaults to interactive. java.cleanup.actionsOnSave: Deprecated, please use 'java.cleanup.actions' instead. The list of clean ups to be run on the current document when it's saved. Clean ups can automatically fix code style or programming mistakes. Click here to learn more about what each clean up does. java.cleanup.actions: The list of clean ups to be run on the current document when it's saved or when the cleanup command is issued. Clean ups can automatically fix code style or programming mistakes. Click here to learn more about what each clean up does. java.saveActions.cleanup: Enable/disable cleanup actions on save. java.import.gradle.annotationProcessing.enabled: Enable/disable the annotation processing on Gradle projects and delegate to JDT APT. Only works for Gradle 5.2 or higher. java.sharedIndexes.enabled: [Experimental] Specify whether to share indexes between different workspaces. Defaults to auto and the shared indexes is automatically enabled in Visual Studio Code - Insiders. auto on off java.sharedIndexes.location: Specifies a common index location for all workspaces. See default values as follows: Windows: First use "$APPDATA\\.jdt\\index", or "~\\.jdt\\index" if it does not exist macOS: "~/Library/Caches/.jdt/index" Linux: First use "$XDG_CACHE_HOME/.jdt/index", or "~/.cache/.jdt/index" if it does not exist java.refactoring.extract.interface.replace: Specify whether to replace all the occurrences of the subtype with the new extracted interface. Defaults to true. java.import.maven.disableTestClasspathFlag : Enable/disable test classpath segregation. When enabled, this permits the usage of test resources within a Maven project as dependencies within the compile scope of other projects. Defaults to false. java.configuration.maven.defaultMojoExecutionAction : Specifies default mojo execution action when no associated metadata can be detected. Defaults to ignore. java.completion.lazyResolveTextEdit.enabled: [Experimental] Enable/disable lazily resolving text edits for code completion. Defaults to true. java.edit.validateAllOpenBuffersOnChanges: Specifies whether to recheck all open Java files for diagnostics when editing a Java file. Defaults to false. java.editor.reloadChangedSources: Specifies whether to reload the sources of the open class files when their source jar files are changed. Defaults to ask. ask: Ask to reload the sources of the open class files auto: Automatically reload the sources of the open class files manual: Manually reload the sources of the open class files java.edit.smartSemicolonDetection.enabled: Defines the smart semicolon detection. Defaults to false. java.configuration.detectJdksAtStart: Automatically detect JDKs installed on local machine at startup. If you have specified the same JDK version in java.configuration.runtimes, the extension will use that version first. Defaults to true. java.completion.collapseCompletionItems: Enable/disable the collapse of overloaded methods in completion items. Overrides java.completion.guessMethodArguments. Defaults to false. java.diagnostic.filter: Specifies a list of file patterns for which matching documents should not have their diagnostics reported (eg. '**/Foo.java'). java.search.scope: Specifies the scope which must be used for search operation like Find Reference Call Hierarchy Workspace Symbols java.jdt.ls.javac.enabled: [Experimental] Specify whether to enable Javac-based compilation in the language server. Requires running this extension with Java 24. Defaults to off. java.completion.engine: [Experimental] Select code completion engine. Defaults to ecj. java.references.includeDeclarations: Include declarations when finding references. Defaults to true java.jdt.ls.appcds.enabled : [Experimental] Enable Java AppCDS (Application Class Data Sharing) for improvements to extension activation. When set to auto, AppCDS will be enabled in Visual Studio Code - Insiders, and for pre-release versions. Semantic Highlighting Semantic Highlighting fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the editor.semanticHighlighting.enabled setting, or for Java only using language-specific editor settings. Troubleshooting Check the status of the language tools on the lower right corner (marked with A on image below). It should show ready (thumbs up) as on the image below. You can click on the status and open the language tool logs for further information in case of a failure. status indicator Read the troubleshooting guide for collecting informations about issues you might encounter. Report any problems you face to the project. Contributing This is an open source project open to anyone. Contributions are extremely welcome! For information on getting started, refer to the CONTRIBUTING instructions. Continuous Integration builds can be installed from http://download.jboss.org/jbosstools/jdt.ls/staging/. Download the most recent java-<version>.vsix file and install it by following the instructions here. Stable releases are archived under http://download.jboss.org/jbosstools/static/jdt.ls/stable/. Also, you can contribute your own VS Code extension to enhance the existing features by following the instructions here. Feedback Have a question? Start a discussion on GitHub Discussions, File a bug in GitHub Issues, Chat with us on Gitter, Tweet us with other feedback. License EPL 2.0, See LICENSE for more information.
最新发布
09-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值