java-decompiler: post-import cleanup (formatting and copyright)
This commit is contained in:
@@ -1,186 +1,186 @@
|
||||
/*
|
||||
* Fernflower - The Analytical Java Decompiler
|
||||
* http://www.reversed-java.com
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* (C) 2008 - 2010, Stiver
|
||||
* 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
|
||||
*
|
||||
* This software is NEITHER public domain NOR free software
|
||||
* as per GNU License. See license.txt for more details.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* This software is distributed WITHOUT ANY WARRANTY; without
|
||||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE.
|
||||
* 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.struct.lazy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider;
|
||||
import org.jetbrains.java.decompiler.struct.StructMethod;
|
||||
import org.jetbrains.java.decompiler.struct.attr.StructGeneralAttribute;
|
||||
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
|
||||
import org.jetbrains.java.decompiler.util.DataInputFullStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LazyLoader {
|
||||
|
||||
private HashMap<String, Link> mapClassLinks = new HashMap<String, Link>();
|
||||
|
||||
private IBytecodeProvider provider;
|
||||
|
||||
public LazyLoader(IBytecodeProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public void addClassLink(String classname, Link link) {
|
||||
mapClassLinks.put(classname, link);
|
||||
}
|
||||
private HashMap<String, Link> mapClassLinks = new HashMap<String, Link>();
|
||||
|
||||
public void removeClassLink(String classname) {
|
||||
mapClassLinks.remove(classname);
|
||||
}
|
||||
|
||||
public Link getClassLink(String classname) {
|
||||
return mapClassLinks.get(classname);
|
||||
}
|
||||
|
||||
|
||||
public ConstantPool loadPool(String classname) {
|
||||
private IBytecodeProvider provider;
|
||||
|
||||
try {
|
||||
|
||||
DataInputFullStream in = getClassStream(classname);
|
||||
if(in == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
in.skip(8);
|
||||
|
||||
return new ConstantPool(in);
|
||||
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] loadBytecode(StructMethod mt, int code_fulllength) {
|
||||
|
||||
try {
|
||||
public LazyLoader(IBytecodeProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
DataInputFullStream in = getClassStream(mt.getClassStruct().qualifiedName);
|
||||
if(in == null) {
|
||||
return null;
|
||||
}
|
||||
public void addClassLink(String classname, Link link) {
|
||||
mapClassLinks.put(classname, link);
|
||||
}
|
||||
|
||||
byte[] res = null;
|
||||
|
||||
in.skip(8);
|
||||
public void removeClassLink(String classname) {
|
||||
mapClassLinks.remove(classname);
|
||||
}
|
||||
|
||||
ConstantPool pool = mt.getClassStruct().getPool();
|
||||
if(pool == null) {
|
||||
pool = new ConstantPool(in);
|
||||
} else {
|
||||
ConstantPool.skipPool(in);
|
||||
}
|
||||
public Link getClassLink(String classname) {
|
||||
return mapClassLinks.get(classname);
|
||||
}
|
||||
|
||||
in.skip(2);
|
||||
int this_class = in.readUnsignedShort();
|
||||
in.skip(2);
|
||||
|
||||
// interfaces
|
||||
in.skip(in.readUnsignedShort() * 2);
|
||||
|
||||
// fields
|
||||
int size = in.readUnsignedShort();
|
||||
for (int i = 0; i < size; i++) {
|
||||
in.skip(6);
|
||||
skipAttributes(in);
|
||||
}
|
||||
public ConstantPool loadPool(String classname) {
|
||||
|
||||
// methods
|
||||
size = in.readUnsignedShort();
|
||||
for (int i = 0; i < size; i++) {
|
||||
in.skip(2);
|
||||
try {
|
||||
|
||||
int name_index = in.readUnsignedShort();
|
||||
int descriptor_index = in.readUnsignedShort();
|
||||
DataInputFullStream in = getClassStream(classname);
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String elem_arr[] = pool.getClassElement(ConstantPool.METHOD, this_class, name_index, descriptor_index);
|
||||
String name = elem_arr[0];
|
||||
|
||||
if(mt.getName().equals(name)) {
|
||||
String descriptor = elem_arr[1];
|
||||
if(mt.getDescriptor().equals(descriptor)) {
|
||||
in.skip(8);
|
||||
|
||||
int len = in.readUnsignedShort();
|
||||
for(int j=0;j<len;j++) {
|
||||
return new ConstantPool(in);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
int attr_nameindex = in.readUnsignedShort();
|
||||
String attrname = pool.getPrimitiveConstant(attr_nameindex).getString();
|
||||
public byte[] loadBytecode(StructMethod mt, int code_fulllength) {
|
||||
|
||||
if(StructGeneralAttribute.ATTRIBUTE_CODE.equals(attrname)) {
|
||||
in.skip(12);
|
||||
try {
|
||||
|
||||
res = new byte[code_fulllength];
|
||||
in.readFull(res);
|
||||
return res;
|
||||
} else {
|
||||
in.skip(in.readInt());
|
||||
}
|
||||
}
|
||||
DataInputFullStream in = getClassStream(mt.getClassStruct().qualifiedName);
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
byte[] res = null;
|
||||
|
||||
skipAttributes(in);
|
||||
}
|
||||
in.skip(8);
|
||||
|
||||
return null;
|
||||
ConstantPool pool = mt.getClassStruct().getPool();
|
||||
if (pool == null) {
|
||||
pool = new ConstantPool(in);
|
||||
}
|
||||
else {
|
||||
ConstantPool.skipPool(in);
|
||||
}
|
||||
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
in.skip(2);
|
||||
int this_class = in.readUnsignedShort();
|
||||
in.skip(2);
|
||||
|
||||
public DataInputFullStream getClassStream(String externPath, String internPath) throws IOException {
|
||||
InputStream instream = provider.getBytecodeStream(externPath, internPath);
|
||||
return instream == null?null:new DataInputFullStream(instream);
|
||||
}
|
||||
// interfaces
|
||||
in.skip(in.readUnsignedShort() * 2);
|
||||
|
||||
public DataInputFullStream getClassStream(String qualifiedClassName) throws IOException {
|
||||
Link link = mapClassLinks.get(qualifiedClassName);
|
||||
return link == null?null:getClassStream(link.externPath, link.internPath);
|
||||
}
|
||||
|
||||
private void skipAttributes(DataInputFullStream in) throws IOException {
|
||||
// fields
|
||||
int size = in.readUnsignedShort();
|
||||
for (int i = 0; i < size; i++) {
|
||||
in.skip(6);
|
||||
skipAttributes(in);
|
||||
}
|
||||
|
||||
int length = in.readUnsignedShort();
|
||||
for (int i = 0; i < length; i++) {
|
||||
in.skip(2);
|
||||
in.skip(in.readInt());
|
||||
}
|
||||
|
||||
}
|
||||
// methods
|
||||
size = in.readUnsignedShort();
|
||||
for (int i = 0; i < size; i++) {
|
||||
in.skip(2);
|
||||
|
||||
|
||||
public static class Link {
|
||||
|
||||
public static final int CLASS = 1;
|
||||
public static final int ENTRY = 2;
|
||||
|
||||
public int type;
|
||||
public String externPath;
|
||||
public String internPath;
|
||||
|
||||
public Link(int type, String externPath, String internPath) {
|
||||
this.type = type;
|
||||
this.externPath = externPath;
|
||||
this.internPath = internPath;
|
||||
}
|
||||
}
|
||||
|
||||
int name_index = in.readUnsignedShort();
|
||||
int descriptor_index = in.readUnsignedShort();
|
||||
|
||||
String elem_arr[] = pool.getClassElement(ConstantPool.METHOD, this_class, name_index, descriptor_index);
|
||||
String name = elem_arr[0];
|
||||
|
||||
if (mt.getName().equals(name)) {
|
||||
String descriptor = elem_arr[1];
|
||||
if (mt.getDescriptor().equals(descriptor)) {
|
||||
|
||||
int len = in.readUnsignedShort();
|
||||
for (int j = 0; j < len; j++) {
|
||||
|
||||
int attr_nameindex = in.readUnsignedShort();
|
||||
String attrname = pool.getPrimitiveConstant(attr_nameindex).getString();
|
||||
|
||||
if (StructGeneralAttribute.ATTRIBUTE_CODE.equals(attrname)) {
|
||||
in.skip(12);
|
||||
|
||||
res = new byte[code_fulllength];
|
||||
in.readFull(res);
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
in.skip(in.readInt());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
skipAttributes(in);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public DataInputFullStream getClassStream(String externPath, String internPath) throws IOException {
|
||||
InputStream instream = provider.getBytecodeStream(externPath, internPath);
|
||||
return instream == null ? null : new DataInputFullStream(instream);
|
||||
}
|
||||
|
||||
public DataInputFullStream getClassStream(String qualifiedClassName) throws IOException {
|
||||
Link link = mapClassLinks.get(qualifiedClassName);
|
||||
return link == null ? null : getClassStream(link.externPath, link.internPath);
|
||||
}
|
||||
|
||||
private void skipAttributes(DataInputFullStream in) throws IOException {
|
||||
|
||||
int length = in.readUnsignedShort();
|
||||
for (int i = 0; i < length; i++) {
|
||||
in.skip(2);
|
||||
in.skip(in.readInt());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Link {
|
||||
|
||||
public static final int CLASS = 1;
|
||||
public static final int ENTRY = 2;
|
||||
|
||||
public int type;
|
||||
public String externPath;
|
||||
public String internPath;
|
||||
|
||||
public Link(int type, String externPath, String internPath) {
|
||||
this.type = type;
|
||||
this.externPath = externPath;
|
||||
this.internPath = internPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user