Cleanup (typos; formatting)

This commit is contained in:
Roman Shevchenko
2018-08-27 20:15:00 +03:00
parent bddc620954
commit 4baeb745d0
2 changed files with 38 additions and 79 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed 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 copy 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.util;
import com.intellij.openapi.util.text.StringUtil;
@@ -174,11 +160,8 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
buffer.append('(');
PsiParameter[] params = method.getParameterList().getParameters();
for (int i = 0; i < Math.min(params.length, maxParametersToShow); i++) {
PsiParameter parm = params[i];
if (i > 0) {
buffer.append(", ");
}
buffer.append(formatVariable(parm, parameterOptions, substitutor));
if (i > 0) buffer.append(", ");
buffer.append(formatVariable(params[i], parameterOptions, substitutor));
}
if (params.length > maxParametersToShow) {
buffer.append(", ...");
@@ -188,9 +171,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
if (BitUtil.isSet(options, SHOW_TYPE) && BitUtil.isSet(options, TYPE_AFTER)) {
PsiType type = method.getReturnType();
if (type != null) {
if (buffer.length() > 0) {
buffer.append(':');
}
if (buffer.length() > 0) buffer.append(':');
buffer.append(formatType(type, options, substitutor));
}
}
@@ -201,8 +182,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
String throwsText = formatReferenceList(method.getThrowsList(), options);
if (!throwsText.isEmpty()) {
appendSpaceIfNeeded(buffer);
buffer.append("throws ");
buffer.append(throwsText);
buffer.append("throws ").append(throwsText);
}
}
}
@@ -217,7 +197,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
if (BitUtil.isSet(options, SHOW_NAME)) {
if (aClass instanceof PsiAnonymousClass && BitUtil.isSet(options, SHOW_ANONYMOUS_CLASS_VERBOSE)) {
final PsiClassType baseClassReference = ((PsiAnonymousClass)aClass).getBaseClassType();
PsiClassType baseClassReference = ((PsiAnonymousClass)aClass).getBaseClassType();
PsiClass baseClass = baseClassReference.resolve();
String name = baseClass == null ? baseClassReference.getPresentableText() : formatClass(baseClass, options);
buffer.append(PsiBundle.message("anonymous.class.derived.display", name));
@@ -252,8 +232,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
String extendsText = formatReferenceList(extendsList, options);
if (!extendsText.isEmpty()) {
appendSpaceIfNeeded(buffer);
buffer.append("extends ");
buffer.append(extendsText);
buffer.append("extends ").append(extendsText);
}
}
@@ -262,8 +241,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
String implementsText = formatReferenceList(implementsList, options);
if (!implementsText.isEmpty()) {
appendSpaceIfNeeded(buffer);
buffer.append("implements ");
buffer.append(implementsText);
buffer.append("implements ").append(implementsText);
}
}
}
@@ -298,7 +276,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
if (!BitUtil.isSet(options, SHOW_REDUNDANT_MODIFIERS)
? list.hasExplicitModifier(PsiModifier.PACKAGE_LOCAL)
: list.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
if (element instanceof PsiClass && element.getParent() instanceof PsiDeclarationStatement) {// local class
if (element instanceof PsiClass && element.getParent() instanceof PsiDeclarationStatement) { // local class
append(buffer, PsiBundle.message("local.class.preposition"));
}
else {
@@ -329,9 +307,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
if (list.hasModifierProperty(PsiModifier.STRICTFP) && !BitUtil.isSet(options, JAVADOC_MODIFIERS_ONLY)) {
appendModifier(buffer, PsiModifier.STRICTFP);
}
if (list.hasModifierProperty(PsiModifier.TRANSIENT) &&
element instanceof PsiVariable // javac 5 puts transient attr for methods
) {
if (list.hasModifierProperty(PsiModifier.TRANSIENT) && element instanceof PsiVariable) { // javac 5 puts transient attr for methods
appendModifier(buffer, PsiModifier.TRANSIENT);
}
if (list.hasModifierProperty(PsiModifier.VOLATILE)) {
@@ -339,7 +315,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
}
}
private static void appendModifier(final StringBuilder buffer, @PsiModifier.ModifierConstant @NotNull String modifier) {
private static void appendModifier(StringBuilder buffer, @PsiModifier.ModifierConstant @NotNull String modifier) {
append(buffer, VisibilityUtil.toPresentableText(modifier));
}
@@ -351,12 +327,9 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
public static String formatReferenceList(PsiReferenceList list, int options) {
StringBuilder buffer = new StringBuilder();
PsiJavaCodeReferenceElement[] refs = list.getReferenceElements();
for(int i = 0; i < refs.length; i++) {
PsiJavaCodeReferenceElement ref = refs[i];
if (i > 0) {
buffer.append(", ");
}
buffer.append(formatReference(ref, options));
for (int i = 0; i < refs.length; i++) {
if (i > 0) buffer.append(", ");
buffer.append(formatReference(refs[i], options));
}
return buffer.toString();
}
@@ -368,7 +341,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
}
else if (BitUtil.isSet(options, SHOW_RAW_NON_TOP_TYPE)) {
if (!(PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter)) {
final boolean preserveEllipsis = type instanceof PsiEllipsisType;
boolean preserveEllipsis = type instanceof PsiEllipsisType;
type = TypeConversionUtil.erasure(type);
if (preserveEllipsis && type instanceof PsiArrayType) {
type = new PsiEllipsisType(((PsiArrayType)type).getComponentType());
@@ -382,7 +355,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
}
public static String formatReference(PsiJavaCodeReferenceElement ref, int options) {
return !BitUtil.isSet(options, SHOW_FQ_CLASS_NAMES) ? ref.getText() : ref.getCanonicalText();
return BitUtil.isSet(options, SHOW_FQ_CLASS_NAMES) ? ref.getCanonicalText() : ref.getText();
}
@Nullable
@@ -391,41 +364,43 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
}
@Nullable
public static String getExternalName(PsiModifierListOwner owner, final boolean showParamName) {
public static String getExternalName(PsiModifierListOwner owner, boolean showParamName) {
return getExternalName(owner, showParamName, MAX_PARAMS_TO_SHOW);
}
@Nullable
public static String getExternalName(PsiModifierListOwner owner, final boolean showParamName, int maxParamsToShow) {
final StringBuilder builder = new StringBuilder();
public static String getExternalName(PsiModifierListOwner owner, boolean showParamName, int maxParamsToShow) {
StringBuilder builder = new StringBuilder();
if (owner instanceof PsiClass) {
ClassUtil.formatClassName((PsiClass)owner, builder);
return builder.toString();
}
final PsiClass psiClass = PsiTreeUtil.getParentOfType(owner, PsiClass.class, false);
PsiClass psiClass = PsiTreeUtil.getParentOfType(owner, PsiClass.class, false);
if (psiClass == null) return null;
ClassUtil.formatClassName(psiClass, builder);
if (owner instanceof PsiMethod) {
builder.append(" ");
formatMethod((PsiMethod)owner, PsiSubstitutor.EMPTY,
SHOW_NAME | SHOW_FQ_NAME | SHOW_TYPE | SHOW_PARAMETERS | SHOW_FQ_CLASS_NAMES,
showParamName ? SHOW_NAME | SHOW_TYPE | SHOW_FQ_CLASS_NAMES : SHOW_TYPE | SHOW_FQ_CLASS_NAMES, maxParamsToShow, builder);
builder.append(' ');
int options = SHOW_NAME | SHOW_FQ_NAME | SHOW_TYPE | SHOW_PARAMETERS | SHOW_FQ_CLASS_NAMES;
int parameterOptions = showParamName ? SHOW_NAME | SHOW_TYPE | SHOW_FQ_CLASS_NAMES : SHOW_TYPE | SHOW_FQ_CLASS_NAMES;
formatMethod((PsiMethod)owner, PsiSubstitutor.EMPTY, options, parameterOptions, maxParamsToShow, builder);
}
else if (owner instanceof PsiField) {
builder.append(" ").append(((PsiField)owner).getName());
builder.append(' ').append(((PsiField)owner).getName());
}
else if (owner instanceof PsiParameter) {
final PsiElement declarationScope = ((PsiParameter)owner).getDeclarationScope();
PsiElement declarationScope = ((PsiParameter)owner).getDeclarationScope();
if (!(declarationScope instanceof PsiMethod)) {
return null;
}
final PsiMethod psiMethod = (PsiMethod)declarationScope;
PsiMethod psiMethod = (PsiMethod)declarationScope;
builder.append(" ");
formatMethod(psiMethod, PsiSubstitutor.EMPTY,
SHOW_NAME | SHOW_FQ_NAME | SHOW_TYPE | SHOW_PARAMETERS | SHOW_FQ_CLASS_NAMES,
showParamName ? SHOW_NAME | SHOW_TYPE | SHOW_FQ_CLASS_NAMES : SHOW_TYPE | SHOW_FQ_CLASS_NAMES, maxParamsToShow, builder);
builder.append(" ");
builder.append(' ');
int options = SHOW_NAME | SHOW_FQ_NAME | SHOW_TYPE | SHOW_PARAMETERS | SHOW_FQ_CLASS_NAMES;
int parameterOptions = showParamName ? SHOW_NAME | SHOW_TYPE | SHOW_FQ_CLASS_NAMES : SHOW_TYPE | SHOW_FQ_CLASS_NAMES;
formatMethod(psiMethod, PsiSubstitutor.EMPTY, options, parameterOptions, maxParamsToShow, builder);
builder.append(' ');
if (showParamName) {
formatVariable((PsiVariable)owner, SHOW_NAME, PsiSubstitutor.EMPTY, builder);
@@ -437,10 +412,11 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
else {
return null;
}
return builder.toString();
}
public static String getPackageDisplayName(@NotNull final PsiClass psiClass) {
public static String getPackageDisplayName(@NotNull PsiClass psiClass) {
if (psiClass instanceof PsiTypeParameter) {
PsiTypeParameterListOwner owner = ((PsiTypeParameter)psiClass).getOwner();
String ownerName = null;
@@ -1,26 +1,10 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed 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 copy 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.util;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.BitUtil;
public abstract class PsiFormatUtilBase {
public static final int SHOW_NAME = 0x0001; // variable, method, class
public static final int SHOW_TYPE = 0x0002; // variable, method
public static final int TYPE_AFTER = 0x0004; // variable, method
@@ -65,5 +49,4 @@ public abstract class PsiFormatUtilBase {
}
return true;
}
}
}