mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
[java-decompiler] IDEA-346312 adapt patches
- clean-up GitOrigin-RevId: 2e17885d0357d94ce1461766a0ebe3c7f48e4eac
This commit is contained in:
committed by
intellij-monorepo-bot
parent
919ddba333
commit
893d54aab6
@@ -426,8 +426,7 @@ public final class SecondaryFunctionsHelper {
|
||||
for (IMatchable obj : objects) {
|
||||
if (obj instanceof Statement) {
|
||||
updateAssignments((Statement) obj);
|
||||
} else if (obj instanceof Exprent) {
|
||||
Exprent exprent = (Exprent) obj;
|
||||
} else if (obj instanceof Exprent exprent) {
|
||||
|
||||
if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
|
||||
AssignmentExprent assignment = (AssignmentExprent) exprent;
|
||||
|
||||
@@ -98,28 +98,28 @@ public final class TryHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Mostly use for java version less than 11.
|
||||
* Used for java version less than 11.
|
||||
* Try to find the next synthetic example and convert it to try-with-resource
|
||||
* <pre>
|
||||
* {@code
|
||||
* Some some = new Some();
|
||||
* Throwable var2 = null;
|
||||
* Some some = new Some(); //required
|
||||
* Throwable var2 = null; //required
|
||||
* try {
|
||||
* } catch (Throwable var11) {
|
||||
* var2 = var11;
|
||||
* throw var11;
|
||||
* } finally {
|
||||
* if (some != null) {
|
||||
* if (var2 != null) {
|
||||
* if (some != null) { //required
|
||||
* if (var2 != null) { //required
|
||||
* try {
|
||||
* some.close();
|
||||
* some.close(); //required
|
||||
* } catch (Throwable var10) {
|
||||
* var2.addSuppressed(var10);
|
||||
* }
|
||||
* } else {
|
||||
* some.close();
|
||||
* } else { //required
|
||||
* some.close(); //required
|
||||
* }
|
||||
* }
|
||||
* } //required
|
||||
*
|
||||
* }
|
||||
* }
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.jetbrains.java.decompiler.struct.StructMethod;
|
||||
import org.jetbrains.java.decompiler.struct.attr.StructLocalVariableTableAttribute.LocalVariable;
|
||||
import org.jetbrains.java.decompiler.struct.gen.MethodDescriptor;
|
||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||
import org.jetbrains.java.decompiler.util.StartEndPair;
|
||||
import org.jetbrains.java.decompiler.util.TextUtil;
|
||||
|
||||
import java.util.*;
|
||||
@@ -200,37 +199,10 @@ public class VarProcessor {
|
||||
.filter(v -> v.getVersion().var == exprent.getIndex() && v.getStart() == start).findFirst().ifPresent(exprent::setLVTEntry);
|
||||
}
|
||||
|
||||
public void copyVarInfo(VarVersion from, VarVersion to) {
|
||||
setVarName(to, getVarName(from));
|
||||
setVarFinal(to, getVarFinal(from));
|
||||
setVarType(to, getVarType(from));
|
||||
varVersions.getMapOriginalVarIndices().put(to.var, varVersions.getMapOriginalVarIndices().get(from.var));
|
||||
}
|
||||
|
||||
public boolean hasLVT() {
|
||||
return method.getLocalVariableAttr() != null;
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer, LocalVariable> getLocalVariables(Statement stat) {
|
||||
if (!hasLVT() || stat == null)
|
||||
return new HashMap<>();
|
||||
|
||||
final StartEndPair sep = stat.getStartEndRange();
|
||||
final Set<Integer> blacklist = new HashSet<>();
|
||||
Map<Integer, LocalVariable> ret = method.getLocalVariableAttr().getVariables().filter(lv -> lv.getEnd() > sep.start && lv.getStart() <= sep.end)
|
||||
.collect(Collectors.toMap(lv -> lv.getVersion().var, lv -> lv,
|
||||
(lv1, lv2) ->
|
||||
{
|
||||
//System.out.println("DUPLICATE INDEX FOR SCOPE: (" +sep +") " + lv1.toString() + " " + lv2.toString());
|
||||
blacklist.add(lv1.getVersion().var);
|
||||
return lv1;
|
||||
}
|
||||
));
|
||||
|
||||
ret.keySet().removeAll(blacklist);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public VarVersionsProcessor getVarVersions() {
|
||||
return varVersions;
|
||||
|
||||
@@ -154,35 +154,6 @@ public class StructClass extends StructMember {
|
||||
return methods.getWithKey(InterpreterUtil.makeUniqueKey(name, descriptor));
|
||||
}
|
||||
|
||||
public StructMethod getMethodRecursive(String name, String descriptor) {
|
||||
StructMethod ret = getMethod(name, descriptor);
|
||||
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (superClass != null) {
|
||||
StructClass cls = DecompilerContext.getStructContext().getClass((String)superClass.value);
|
||||
if (cls != null) {
|
||||
ret = cls.getMethodRecursive(name, descriptor);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String intf : getInterfaceNames()) {
|
||||
StructClass cls = DecompilerContext.getStructContext().getClass(intf);
|
||||
if (cls != null) {
|
||||
ret = cls.getMethodRecursive(name, descriptor);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getInterface(int i) {
|
||||
return interfaceNames[i];
|
||||
}
|
||||
@@ -296,10 +267,6 @@ public class StructClass extends StructMember {
|
||||
return isVersion21();
|
||||
}
|
||||
|
||||
public boolean isVersion(int minVersion) {
|
||||
return majorVersion >= minVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return qualifiedName;
|
||||
@@ -333,10 +300,10 @@ public class StructClass extends StructMember {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Map<String, Map<VarType, VarType>> genericHiarachy;
|
||||
private Map<String, Map<VarType, VarType>> genericHierarchy;
|
||||
public Map<String, Map<VarType, VarType>> getAllGenerics() {
|
||||
if (genericHiarachy != null) {
|
||||
return genericHiarachy;
|
||||
if (genericHierarchy != null) {
|
||||
return genericHierarchy;
|
||||
}
|
||||
|
||||
Map<String, Map<VarType, VarType>> ret = new HashMap<>();
|
||||
@@ -408,7 +375,7 @@ public class StructClass extends StructMember {
|
||||
}
|
||||
}
|
||||
|
||||
this.genericHiarachy = ret.isEmpty() ? Collections.emptyMap() : ret;
|
||||
return this.genericHiarachy;
|
||||
this.genericHierarchy = ret.isEmpty() ? Collections.emptyMap() : ret;
|
||||
return this.genericHierarchy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.java.decompiler.struct.consts;
|
||||
|
||||
import org.jetbrains.java.decompiler.code.CodeConstants;
|
||||
@@ -77,6 +77,6 @@ public class LinkConstant extends PooledConstant {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (className == null ? "" : className + '.') + elementName + descriptor;
|
||||
return (className == null ? "" : className + '.') + elementName + descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.java.decompiler.struct.consts;
|
||||
|
||||
import org.jetbrains.java.decompiler.code.CodeConstants;
|
||||
@@ -23,7 +23,8 @@ public class PrimitiveConstant extends PooledConstant {
|
||||
private void initConstant() {
|
||||
if (type == CodeConstants.CONSTANT_Class) {
|
||||
String className = getString();
|
||||
isArray = (!className.isEmpty() && className.charAt(0) == '['); // empty string for a class name seems to be possible in some android files
|
||||
isArray =
|
||||
(!className.isEmpty() && className.charAt(0) == '['); // empty string for a class name seems to be possible in some android files
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +53,6 @@ public class PrimitiveConstant extends PooledConstant {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.java.decompiler.struct.gen.Type;
|
||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GenericType extends VarType implements Type {
|
||||
|
||||
@@ -18,8 +17,6 @@ public class GenericType extends VarType implements Type {
|
||||
public static final int WILDCARD_UNBOUND = 3;
|
||||
public static final int WILDCARD_NO = 4;
|
||||
|
||||
private static final Pattern DOT_SPLIT = Pattern.compile("\\.");
|
||||
|
||||
private final VarType parent;
|
||||
private final List<VarType> arguments;
|
||||
private final int wildcard;
|
||||
@@ -95,7 +92,7 @@ public class GenericType extends VarType implements Type {
|
||||
}
|
||||
else {
|
||||
if (parent == null && params == null) {
|
||||
parent = GenericType.parse("L" + value + ";");
|
||||
parent = parse("L" + value + ";");
|
||||
}
|
||||
else {
|
||||
parent = new GenericType(CodeConstants.TYPE_OBJECT, 0, value, parent, params, wildcard);
|
||||
@@ -110,7 +107,7 @@ public class GenericType extends VarType implements Type {
|
||||
|
||||
default:
|
||||
value = signature.substring(index, index + 1);
|
||||
type = VarType.getType(value.charAt(0));
|
||||
type = getType(value.charAt(0));
|
||||
}
|
||||
|
||||
index++;
|
||||
@@ -175,7 +172,7 @@ public class GenericType extends VarType implements Type {
|
||||
typeStr = typeStr.substring(1);
|
||||
}
|
||||
|
||||
args.add(typeStr.isEmpty() ? null : GenericType.parse(typeStr, wildcard));
|
||||
args.add(typeStr.isEmpty() ? null : parse(typeStr, wildcard));
|
||||
|
||||
value = value.substring(len);
|
||||
}
|
||||
@@ -267,7 +264,8 @@ public class GenericType extends VarType implements Type {
|
||||
return appendTypeArguments(clsName, typeAnnWriteHelpers);
|
||||
}
|
||||
else {
|
||||
List<String> nestedTypes = Arrays.asList(DOT_SPLIT.split(DecompilerContext.getImportCollector().getNestedName(getValue().replace('/', '.'))));
|
||||
String stringTypes = DecompilerContext.getImportCollector().getNestedName(getValue().replace('/', '.'));
|
||||
List<String> nestedTypes = Arrays.asList(stringTypes.split("\\."));
|
||||
typeAnnWriteHelpers = ExprProcessor.writeNestedClass(clsName, this, nestedTypes, typeAnnWriteHelpers);
|
||||
appendTypeArguments(clsName, typeAnnWriteHelpers);
|
||||
ExprProcessor.popNestedTypeAnnotation(typeAnnWriteHelpers);
|
||||
@@ -295,10 +293,10 @@ public class GenericType extends VarType implements Type {
|
||||
else if (par.isGeneric()) {
|
||||
GenericType gen = (GenericType)par;
|
||||
switch (gen.getWildcard()) {
|
||||
case GenericType.WILDCARD_EXTENDS:
|
||||
case WILDCARD_EXTENDS:
|
||||
buffer.append("? extends ");
|
||||
break;
|
||||
case GenericType.WILDCARD_SUPER:
|
||||
case WILDCARD_SUPER:
|
||||
buffer.append("? super ");
|
||||
break;
|
||||
}
|
||||
@@ -319,10 +317,10 @@ public class GenericType extends VarType implements Type {
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
switch(getWildcard()) {
|
||||
case GenericType.WILDCARD_EXTENDS:
|
||||
case WILDCARD_EXTENDS:
|
||||
buf.append("? extends ");
|
||||
break;
|
||||
case GenericType.WILDCARD_SUPER:
|
||||
case WILDCARD_SUPER:
|
||||
buf.append("? super ");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -65,12 +65,18 @@ public class JADNameProvider implements IVariableNameProvider {
|
||||
public final List<String> names = new ArrayList<>();
|
||||
|
||||
private Holder(int t1, boolean skip_zero, String... names) {
|
||||
if (names.length == 0) {
|
||||
throw new IllegalArgumentException("names must not be empty");
|
||||
}
|
||||
this.id = t1;
|
||||
this.skip_zero = skip_zero;
|
||||
Collections.addAll(this.names, names);
|
||||
}
|
||||
|
||||
private Holder(int t1, boolean skip_zero, List<String> names) {
|
||||
if (names.isEmpty()) {
|
||||
throw new IllegalArgumentException("names must not be empty");
|
||||
}
|
||||
this.id = t1;
|
||||
this.skip_zero = skip_zero;
|
||||
this.names.addAll(names);
|
||||
@@ -99,7 +105,7 @@ public class JADNameProvider implements IVariableNameProvider {
|
||||
}
|
||||
|
||||
List<VarVersion> keys = new ArrayList<>(entries.keySet());
|
||||
Collections.sort(keys, (o1, o2) -> (o1.var != o2.var) ? o1.var - o2.var : o1.version - o2.version);
|
||||
Collections.sort(keys);
|
||||
|
||||
Map<VarVersion, String> result = new LinkedHashMap<>();
|
||||
for (VarVersion ver : keys) {
|
||||
@@ -131,7 +137,7 @@ public class JADNameProvider implements IVariableNameProvider {
|
||||
String findtype = type;
|
||||
|
||||
while (findtype.contains("[][]")) {
|
||||
findtype = findtype.replaceAll("\\[]\\[]", "[]");
|
||||
findtype = findtype.replace("[][]", "[]");
|
||||
}
|
||||
if (last.containsKey(findtype)) {
|
||||
index = findtype;
|
||||
@@ -147,15 +153,15 @@ public class JADNameProvider implements IVariableNameProvider {
|
||||
type = type.replace("...", "[]");
|
||||
|
||||
while (type.contains("[][]")) {
|
||||
type = type.replaceAll("\\[]\\[]", "[]");
|
||||
type = type.replace("[][]", "[]");
|
||||
}
|
||||
|
||||
String name = type.toLowerCase(Locale.ENGLISH);
|
||||
// Strip single dots that might happen because of inner class references
|
||||
name = name.replace(".", "");
|
||||
boolean skip_zero = true;
|
||||
boolean skip_zero = false;
|
||||
|
||||
if (Pattern.compile("\\[").matcher(type).find()) {
|
||||
if (type.contains("[")) {
|
||||
skip_zero = true;
|
||||
name = "a" + name.replace("[]", "").replace("...", "");
|
||||
}
|
||||
@@ -172,15 +178,15 @@ public class JADNameProvider implements IVariableNameProvider {
|
||||
int id = holder.id;
|
||||
List<String> names = holder.names;
|
||||
|
||||
int ammount = names.size();
|
||||
int amount = names.size();
|
||||
|
||||
String name;
|
||||
if (ammount == 1) {
|
||||
if (amount == 1) {
|
||||
name = names.get(0) + (id == 0 && holder.skip_zero ? "" : id);
|
||||
}
|
||||
else {
|
||||
int num = id / ammount;
|
||||
name = names.get(id % ammount) + (id < ammount && holder.skip_zero ? "" : num);
|
||||
int num = id / amount;
|
||||
name = names.get(id % amount) + (id < amount && holder.skip_zero ? "" : num);
|
||||
}
|
||||
|
||||
holder.id++;
|
||||
|
||||
@@ -1,37 +1,20 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.java.decompiler.util;
|
||||
|
||||
public class StartEndPair {
|
||||
public final int start;
|
||||
public final int end;
|
||||
public StartEndPair(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof StartEndPair)) return false;
|
||||
return ((StartEndPair)obj).start == start && ((StartEndPair)obj).end == end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return start * 31 + end;
|
||||
}
|
||||
public record StartEndPair(int start, int end) {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%d->%d",start,end);
|
||||
return String.format("%d->%d", start, end);
|
||||
}
|
||||
|
||||
public static StartEndPair join(StartEndPair... pairs) {
|
||||
int start = Integer.MAX_VALUE;
|
||||
int end = Integer.MIN_VALUE;
|
||||
for (StartEndPair pair : pairs) {
|
||||
if (pair == null) continue;
|
||||
start = Math.min(start, pair.start);
|
||||
end = Math.max(end, pair.end);
|
||||
if (pair == null) continue;
|
||||
start = Math.min(start, pair.start);
|
||||
end = Math.max(end, pair.end);
|
||||
}
|
||||
return new StartEndPair(start, end);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user