Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

メソッドファイルとフィールドファイルの名前生成部分にひどい重複 #131

Open
YoshikiHigo opened this issue Mar 8, 2019 · 0 comments

Comments

@YoshikiHigo
Copy link
Member

できればまとめたい.

フィールドファイルの名前生成部分.

// フィールドモジュールの名前を生成
final StringBuilder fieldFileName = new StringBuilder();
if (this.config.isAccessModifierIncluded()) { // アクセス修飾子を名前に入れる場合
final int modifiers = node.getModifiers();
if (Modifier.isPublic(modifiers)) {
fieldFileName.append("public_");
} else if (Modifier.isProtected(modifiers)) {
fieldFileName.append("protected_");
} else if (Modifier.isPrivate(modifiers)) {
fieldFileName.append("private_");
}
}
final String type = node.getType()
.toString()
.replace(' ', '-') // avoiding space existences
.replace('?', '#') // for window's file system
.replace('<', '[') // for window's file system
.replace('>', ']'); // for window's file system
fieldFileName.append(type);
fieldFileName.append("_");
fieldFileName.append(((VariableDeclarationFragment) fragments.get(0)).getName());
for (int index = 1; index < fragments.size(); index++) {
fieldFileName.append("_");
fieldFileName.append(((VariableDeclarationFragment) fragments.get(index)).getName());
}

メソッドファイルの名前生成部分.

// メソッドモジュールの名前を生成
final StringBuilder methodFileName = new StringBuilder();
if (this.config.isAccessModifierIncluded()) { // アクセス修飾子を名前に入れる場合
final int modifiers = node.getModifiers();
if (Modifier.isPublic(modifiers)) {
methodFileName.append("public_");
} else if (Modifier.isProtected(modifiers)) {
methodFileName.append("protected_");
} else if (Modifier.isPrivate(modifiers)) {
methodFileName.append("private_");
}
}
if (this.config.isMethodTypeErasureIncluded()) { // Erasure を名前に入れる場合
if (null != typeParameters && !typeParameters.isEmpty()) {
methodFileName.append("[");
final List<String> erasures = new ArrayList<>();
for (final Object o : node.typeParameters()) {
final TypeParameter typeParameter = (TypeParameter) o;
final String type = typeParameter.toString()
.replace(' ', '-') // avoiding space existences
.replace('?', '#') // for window's file system
.replace('<', '[') // for window's file system
.replace('>', ']'); // for window's file system
erasures.add(type);
}
methodFileName.append(String.join(",", erasures));
methodFileName.append("]_");
}
}
if (this.config.isReturnTypeIncluded()) { // 返り値の型を名前に入れる場合
if (null != returnType) {
final String type = returnType.toString()
.replace(' ', '-') // avoiding space existences
.replace('?', '#') // for window's file system
.replace('<', '[') // for window's file system
.replace('>', ']'); // for window's file system
methodFileName.append(type);
methodFileName.append("_");
}
}
final String methodName = node.getName()
.getIdentifier();
methodFileName.append(methodName);
methodFileName.append("(");
final List<String> types = new ArrayList<>();
for (final Object parameter : node.parameters()) {
final SingleVariableDeclaration svd = (SingleVariableDeclaration) parameter;
final StringBuilder typeText = new StringBuilder();
typeText.append(svd.getType());
for (int i = 0; i < svd.getExtraDimensions(); i++) { // "int a[]"のような表記に対応するため
typeText.append("[]");
}
if (svd.isVarargs()) {
typeText.append("...");
}
final String type = typeText.toString()
.replace(' ', '-') // avoiding space existences
.replace('?', '#') // for window's file system
.replace('<', '[') // for window's file system
.replace('>', ']'); // for window's file system
types.add(type);
}
methodFileName.append(String.join(",", types));
methodFileName.append(")");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant