|
|
@ -1,28 +1,14 @@ |
|
|
|
/* |
|
|
|
// Copyright 2000-2017 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.
|
|
|
|
* 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. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
package org.jetbrains.java.decompiler.modules.renamer; |
|
|
|
package org.jetbrains.java.decompiler.modules.renamer; |
|
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.java.decompiler.main.extern.IIdentifierRenamer; |
|
|
|
import org.jetbrains.java.decompiler.main.extern.IIdentifierRenamer; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
public class ConverterHelper implements IIdentifierRenamer { |
|
|
|
public class ConverterHelper implements IIdentifierRenamer { |
|
|
|
|
|
|
|
|
|
|
|
private static final Set<String> KEYWORDS = new HashSet<>(Arrays.asList( |
|
|
|
private static final Set<String> KEYWORDS = new HashSet<>(Arrays.asList( |
|
|
|
"abstract", "do", "if", "package", "synchronized", "boolean", "double", "implements", "private", "this", "break", "else", "import", |
|
|
|
"abstract", "do", "if", "package", "synchronized", "boolean", "double", "implements", "private", "this", "break", "else", "import", |
|
|
|
"protected", "throw", "byte", "extends", "instanceof", "public", "throws", "case", "false", "int", "return", "transient", "catch", |
|
|
|
"protected", "throw", "byte", "extends", "instanceof", "public", "throws", "case", "false", "int", "return", "transient", "catch", |
|
|
@ -41,15 +27,19 @@ public class ConverterHelper implements IIdentifierRenamer { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean toBeRenamed(Type elementType, String className, String element, String descriptor) { |
|
|
|
public boolean toBeRenamed(Type elementType, String className, String element, String descriptor) { |
|
|
|
String value = elementType == Type.ELEMENT_CLASS ? className : element; |
|
|
|
String value = elementType == Type.ELEMENT_CLASS ? className : element; |
|
|
|
return value == null || value.length() == 0 || value.length() <= 2 || KEYWORDS.contains(value) || Character.isDigit(value.charAt(0)) |
|
|
|
return value == null || |
|
|
|
|| elementType == Type.ELEMENT_CLASS && (RESERVED_WINDOWS_NAMESPACE.contains(value.toLowerCase()) || value.length() > 255 - ".class".length()); |
|
|
|
value.length() <= 2 || |
|
|
|
|
|
|
|
Character.isDigit(value.charAt(0)) || |
|
|
|
|
|
|
|
KEYWORDS.contains(value) || |
|
|
|
|
|
|
|
elementType == Type.ELEMENT_CLASS && ( |
|
|
|
|
|
|
|
RESERVED_WINDOWS_NAMESPACE.contains(value.toLowerCase(Locale.US)) || |
|
|
|
|
|
|
|
value.length() > 255 - ".class".length()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: consider possible conflicts with not renamed classes, fields and methods!
|
|
|
|
// TODO: consider possible conflicts with not renamed classes, fields and methods!
|
|
|
|
// We should get all relevant information here.
|
|
|
|
// We should get all relevant information here.
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getNextClassName(String fullName, String shortName) { |
|
|
|
public String getNextClassName(String fullName, String shortName) { |
|
|
|
|
|
|
|
|
|
|
|
if (shortName == null) { |
|
|
|
if (shortName == null) { |
|
|
|
return "class_" + (classCounter++); |
|
|
|
return "class_" + (classCounter++); |
|
|
|
} |
|
|
|
} |
|
|
@ -64,7 +54,6 @@ public class ConverterHelper implements IIdentifierRenamer { |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
String name = shortName.substring(index); |
|
|
|
String name = shortName.substring(index); |
|
|
|
|
|
|
|
|
|
|
|
if (setNonStandardClassNames.contains(name)) { |
|
|
|
if (setNonStandardClassNames.contains(name)) { |
|
|
|
return "Inner" + name + "_" + (classCounter++); |
|
|
|
return "Inner" + name + "_" + (classCounter++); |
|
|
|
} |
|
|
|
} |
|
|
@ -96,4 +85,4 @@ public class ConverterHelper implements IIdentifierRenamer { |
|
|
|
public static String replaceSimpleClassName(String fullName, String newName) { |
|
|
|
public static String replaceSimpleClassName(String fullName, String newName) { |
|
|
|
return fullName.substring(0, fullName.lastIndexOf('/') + 1) + newName; |
|
|
|
return fullName.substring(0, fullName.lastIndexOf('/') + 1) + newName; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |