mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
store dependency info in memory more compactly: use int instead of wrapper; TIntHashSet instead of HashSet when applicable
fixed integrate problem: : filenames were cleared from dependencies instead of class names
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package org.jetbrains.ether;
|
||||
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import gnu.trove.TIntProcedure;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -35,6 +35,27 @@ public class RW {
|
||||
}
|
||||
}
|
||||
|
||||
public static <X> void save(final TIntHashSet x, final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(x.size());
|
||||
x.forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int value) {
|
||||
try {
|
||||
out.writeInt(value);
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException c) {
|
||||
throw new RuntimeException(c);
|
||||
}
|
||||
}
|
||||
|
||||
public static <X> void save(final Collection<X> x, final DataExternalizer<X> e, final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(x.size());
|
||||
@@ -76,6 +97,21 @@ public class RW {
|
||||
}
|
||||
}
|
||||
|
||||
public static TIntHashSet read(final TIntHashSet acc, final DataInput in) {
|
||||
try {
|
||||
final int size = in.readInt();
|
||||
|
||||
for (int i = 0; i<size; i++) {
|
||||
acc.add(in.readInt());
|
||||
}
|
||||
|
||||
return acc;
|
||||
}
|
||||
catch (IOException x) {
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
|
||||
public static <X> Collection<X> read(final DataExternalizer<X> e, final Collection<X> acc, final DataInput in) {
|
||||
try {
|
||||
final int size = in.readInt();
|
||||
|
||||
@@ -4,13 +4,15 @@ import com.intellij.util.io.DataExternalizer;
|
||||
import groovyjarjarasm.asm.Opcodes;
|
||||
import org.jetbrains.ether.RW;
|
||||
|
||||
import javax.sql.rowset.Predicate;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -21,8 +23,8 @@ import java.util.*;
|
||||
*/
|
||||
public class ClassRepr extends Proto {
|
||||
private final DependencyContext context;
|
||||
public final DependencyContext.S sourceFileName;
|
||||
public final DependencyContext.S fileName;
|
||||
public final int sourceFileName;
|
||||
public final int fileName;
|
||||
public final TypeRepr.AbstractType superClass;
|
||||
public final Set<TypeRepr.AbstractType> interfaces;
|
||||
public final Set<TypeRepr.AbstractType> nestedClasses;
|
||||
@@ -32,7 +34,7 @@ public class ClassRepr extends Proto {
|
||||
public final Set<FieldRepr> fields;
|
||||
public final Set<MethodRepr> methods;
|
||||
|
||||
public final DependencyContext.S outerClassName;
|
||||
public final int outerClassName;
|
||||
public final boolean isLocal;
|
||||
|
||||
public String getFileName() {
|
||||
@@ -142,8 +144,8 @@ public class ClassRepr extends Proto {
|
||||
};
|
||||
}
|
||||
|
||||
public DependencyContext.S[] getSupers() {
|
||||
final DependencyContext.S[] result = new DependencyContext.S[interfaces.size() + 1];
|
||||
public int[] getSupers() {
|
||||
final int[] result = new int[interfaces.size() + 1];
|
||||
|
||||
result[0] = ((TypeRepr.ClassType)superClass).className;
|
||||
|
||||
@@ -171,20 +173,15 @@ public class ClassRepr extends Proto {
|
||||
}
|
||||
}
|
||||
|
||||
public ClassRepr(final DependencyContext context,
|
||||
final int a,
|
||||
final DependencyContext.S sn,
|
||||
final DependencyContext.S fn,
|
||||
final DependencyContext.S n,
|
||||
final DependencyContext.S sig,
|
||||
final DependencyContext.S sup,
|
||||
public ClassRepr(final DependencyContext context, final int a, final int sn, final int fn, final int n, final int sig,
|
||||
final int sup,
|
||||
final String[] i,
|
||||
final Collection<String> ns,
|
||||
final Set<FieldRepr> f,
|
||||
final Set<MethodRepr> m,
|
||||
final Set<ElementType> targets,
|
||||
final RetentionPolicy policy,
|
||||
final DependencyContext.S outerClassName,
|
||||
final int outerClassName,
|
||||
final boolean localClassFlag) {
|
||||
super(a, sig, n);
|
||||
this.context = context;
|
||||
@@ -205,8 +202,8 @@ public class ClassRepr extends Proto {
|
||||
super(in);
|
||||
try {
|
||||
this.context = context;
|
||||
fileName = new DependencyContext.S(in);
|
||||
sourceFileName = new DependencyContext.S(in);
|
||||
fileName = in.readInt();
|
||||
sourceFileName = in.readInt();
|
||||
superClass = TypeRepr.externalizer(context).read(in);
|
||||
interfaces = (Set<TypeRepr.AbstractType>)RW.read(TypeRepr.externalizer(context), new HashSet<TypeRepr.AbstractType>(), in);
|
||||
nestedClasses = (Set<TypeRepr.AbstractType>)RW.read(TypeRepr.externalizer(context), new HashSet<TypeRepr.AbstractType>(), in);
|
||||
@@ -218,7 +215,7 @@ public class ClassRepr extends Proto {
|
||||
|
||||
policy = s.length() == 0 ? null : RetentionPolicy.valueOf(s);
|
||||
|
||||
outerClassName = new DependencyContext.S(in);
|
||||
outerClassName = in.readInt();
|
||||
isLocal = in.readBoolean();
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -230,8 +227,8 @@ public class ClassRepr extends Proto {
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
super.save(out);
|
||||
fileName.save(out);
|
||||
sourceFileName.save(out);
|
||||
out.writeInt(fileName);
|
||||
out.writeInt(sourceFileName);
|
||||
superClass.save(out);
|
||||
RW.save(interfaces, out);
|
||||
RW.save(nestedClasses, out);
|
||||
@@ -239,7 +236,7 @@ public class ClassRepr extends Proto {
|
||||
RW.save(methods, out);
|
||||
RW.save(targets, UsageRepr.AnnotationUsage.elementTypeExternalizer, out);
|
||||
out.writeUTF(policy == null ? "" : policy.toString());
|
||||
outerClassName.save(out);
|
||||
out.writeInt(outerClassName);
|
||||
out.writeBoolean(isLocal);
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -258,24 +255,22 @@ public class ClassRepr extends Proto {
|
||||
|
||||
ClassRepr classRepr = (ClassRepr)o;
|
||||
|
||||
if (fileName != null ? !fileName.equals(classRepr.fileName) : classRepr.fileName != null) return false;
|
||||
if (name != null ? !name.equals(classRepr.name) : classRepr.name != null) return false;
|
||||
if (fileName != classRepr.fileName) return false;
|
||||
if (name != classRepr.name) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = fileName != null ? fileName.hashCode() : 0;
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
return result;
|
||||
return 31 * fileName + name;
|
||||
}
|
||||
|
||||
public UsageRepr.Usage createUsage() {
|
||||
return UsageRepr.createClassUsage(context, name);
|
||||
}
|
||||
|
||||
public DependencyContext.S getSourceFileName() {
|
||||
public int getSourceFileName() {
|
||||
return sourceFileName;
|
||||
}
|
||||
|
||||
@@ -283,7 +278,7 @@ public class ClassRepr extends Proto {
|
||||
return getPackageName(name);
|
||||
}
|
||||
|
||||
public String getPackageName(final DependencyContext.S s) {
|
||||
public String getPackageName(final int s) {
|
||||
return getPackageName(context.getValue(s));
|
||||
|
||||
}
|
||||
@@ -298,9 +293,9 @@ public class ClassRepr extends Proto {
|
||||
return raw.substring(0, index);
|
||||
}
|
||||
|
||||
public FieldRepr findField(final DependencyContext.S name) {
|
||||
public FieldRepr findField(final int name) {
|
||||
for (FieldRepr f : fields) {
|
||||
if (f.name.equals(name)) {
|
||||
if (f.name == name) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import org.jetbrains.asm4.*;
|
||||
import org.jetbrains.asm4.signature.SignatureReader;
|
||||
import org.jetbrains.asm4.signature.SignatureVisitor;
|
||||
@@ -89,13 +90,19 @@ class ClassfileAnalyzer {
|
||||
private final TypeRepr.ClassType type;
|
||||
private final ElementType target;
|
||||
|
||||
private final Set<DependencyContext.S> usedArguments = new HashSet<DependencyContext.S>();
|
||||
private final TIntHashSet myUsedArguments = new TIntHashSet();
|
||||
|
||||
private AnnotationCrawler(final TypeRepr.ClassType type, final ElementType target) {
|
||||
super(Opcodes.ASM4);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
annotationTargets.put(type, target);
|
||||
final Set<ElementType> targets = myAnnotationTargets.get(type);
|
||||
if (targets == null) {
|
||||
myAnnotationTargets.put(type, EnumSet.of(target));
|
||||
}
|
||||
else {
|
||||
targets.add(target);
|
||||
}
|
||||
usages.addUsage(context.get(classNameHolder.get()), UsageRepr.createClassUsage(context, type.className));
|
||||
}
|
||||
|
||||
@@ -144,25 +151,25 @@ class ClassfileAnalyzer {
|
||||
}
|
||||
|
||||
public void visit(String name, Object value) {
|
||||
final DependencyContext.S residence = context.get(classNameHolder.get());
|
||||
final int residence = context.get(classNameHolder.get());
|
||||
final String methodDescr = getMethodDescr(value);
|
||||
final DependencyContext.S methodName = context.get(name);
|
||||
final int methodName = context.get(name);
|
||||
|
||||
usages.addUsage(residence, UsageRepr.createMethodUsage(context, methodName, type.className, methodDescr));
|
||||
usages.addUsage(residence, UsageRepr.createMetaMethodUsage(context, methodName, type.className, methodDescr));
|
||||
|
||||
usedArguments.add(methodName);
|
||||
myUsedArguments.add(methodName);
|
||||
}
|
||||
|
||||
public void visitEnum(String name, String desc, String value) {
|
||||
final DependencyContext.S residence = context.get(classNameHolder.get());
|
||||
final DependencyContext.S methodName = context.get(name);
|
||||
final int residence = context.get(classNameHolder.get());
|
||||
final int methodName = context.get(name);
|
||||
final String methodDescr = "()" + desc;
|
||||
|
||||
usages.addUsage(residence, UsageRepr.createMethodUsage(context, methodName, type.className, methodDescr));
|
||||
usages.addUsage(residence, UsageRepr.createMetaMethodUsage(context, methodName, type.className, methodDescr));
|
||||
|
||||
usedArguments.add(methodName);
|
||||
myUsedArguments.add(methodName);
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitAnnotation(String name, String desc) {
|
||||
@@ -170,18 +177,18 @@ class ClassfileAnalyzer {
|
||||
}
|
||||
|
||||
public AnnotationVisitor visitArray(String name) {
|
||||
usedArguments.add(context.get(name));
|
||||
myUsedArguments.add(context.get(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void visitEnd() {
|
||||
final Set<DependencyContext.S> s = annotationArguments.get(type);
|
||||
final TIntHashSet s = myAnnotationArguments.get(type);
|
||||
|
||||
if (s == null) {
|
||||
annotationArguments.put(type, usedArguments);
|
||||
myAnnotationArguments.put(type, myUsedArguments);
|
||||
}
|
||||
else {
|
||||
s.retainAll(usedArguments);
|
||||
s.retainAll(myUsedArguments.toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,13 +264,13 @@ class ClassfileAnalyzer {
|
||||
|
||||
Boolean takeIntoAccount = false;
|
||||
|
||||
final DependencyContext.S fileName;
|
||||
final int fileName;
|
||||
int access;
|
||||
DependencyContext.S name;
|
||||
int name;
|
||||
String superClass;
|
||||
String[] interfaces;
|
||||
String signature;
|
||||
DependencyContext.S sourceFile;
|
||||
int sourceFile;
|
||||
|
||||
final Holder<String> classNameHolder = new Holder<String>();
|
||||
final Holder<String> outerClassName = new Holder<String>();
|
||||
@@ -281,17 +288,10 @@ class ClassfileAnalyzer {
|
||||
final Set<ElementType> targets = new HashSet<ElementType>();
|
||||
RetentionPolicy policy = null;
|
||||
|
||||
private TransientMultiMaplet.CollectionConstructor<ElementType> elementTypeSetConstructor = new TransientMultiMaplet.CollectionConstructor<ElementType>() {
|
||||
public Set<ElementType> create() {
|
||||
return new HashSet<ElementType>();
|
||||
}
|
||||
};
|
||||
final Map<TypeRepr.ClassType, TIntHashSet> myAnnotationArguments = new HashMap<TypeRepr.ClassType, TIntHashSet>();
|
||||
final Map<TypeRepr.ClassType, Set<ElementType>> myAnnotationTargets = new HashMap<TypeRepr.ClassType, Set<ElementType>>();
|
||||
|
||||
final Map<TypeRepr.ClassType, Set<DependencyContext.S>> annotationArguments = new HashMap<TypeRepr.ClassType, Set<DependencyContext.S>>();
|
||||
final TransientMultiMaplet<TypeRepr.ClassType, ElementType> annotationTargets =
|
||||
new TransientMultiMaplet<TypeRepr.ClassType, ElementType>(elementTypeSetConstructor);
|
||||
|
||||
public ClassCrawler(final DependencyContext.S fn) {
|
||||
public ClassCrawler(final int fn) {
|
||||
super(Opcodes.ASM4);
|
||||
fileName = fn;
|
||||
}
|
||||
@@ -302,8 +302,8 @@ class ClassfileAnalyzer {
|
||||
|
||||
public Pair<ClassRepr, Pair<UsageRepr.Cluster, Set<UsageRepr.Usage>>> getResult() {
|
||||
final ClassRepr repr =
|
||||
takeIntoAccount ? new ClassRepr(context, access, sourceFile, fileName, name, context.get(signature), context.get(superClass), interfaces, nestedClasses, fields,
|
||||
methods, targets, policy, context.get(outerClassName.get()), localClassFlag.get()) : null;
|
||||
takeIntoAccount ? new ClassRepr(
|
||||
context, access, sourceFile, fileName, name, context.get(signature), context.get(superClass), interfaces, nestedClasses, fields, methods, targets, policy, context.get(outerClassName.get()), localClassFlag.get()) : null;
|
||||
|
||||
if (repr != null) {
|
||||
repr.updateClassUsages(context, usages);
|
||||
@@ -343,9 +343,10 @@ class ClassfileAnalyzer {
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
for (TypeRepr.ClassType type : annotationTargets.keyCollection()) {
|
||||
final Collection<ElementType> targets = annotationTargets.get(type);
|
||||
final Set<DependencyContext.S> usedArguments = annotationArguments.get(type);
|
||||
for (Map.Entry<TypeRepr.ClassType, Set<ElementType>> entry : myAnnotationTargets.entrySet()) {
|
||||
final TypeRepr.ClassType type = entry.getKey();
|
||||
final Collection<ElementType> targets = entry.getValue();
|
||||
final TIntHashSet usedArguments = myAnnotationArguments.get(type);
|
||||
|
||||
annotationUsages.add(UsageRepr.createAnnotationUsage(context, type, usedArguments, targets));
|
||||
}
|
||||
@@ -495,9 +496,9 @@ class ClassfileAnalyzer {
|
||||
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
|
||||
final DependencyContext.S residence = context.get(classNameHolder.get());
|
||||
final DependencyContext.S methodName = context.get(name);
|
||||
final DependencyContext.S methodOwner = context.get(owner);
|
||||
final int residence = context.get(classNameHolder.get());
|
||||
final int methodName = context.get(name);
|
||||
final int methodOwner = context.get(owner);
|
||||
|
||||
usages.addUsage(residence, UsageRepr.createMethodUsage(context, methodName, methodOwner, desc));
|
||||
usages.addUsage(residence, UsageRepr.createMetaMethodUsage(context, methodName, methodOwner, desc));
|
||||
@@ -524,7 +525,7 @@ class ClassfileAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<ClassRepr, Pair<UsageRepr.Cluster, Set<UsageRepr.Usage>>> analyze(final DependencyContext.S fileName, final ClassReader cr) {
|
||||
public Pair<ClassRepr, Pair<UsageRepr.Cluster, Set<UsageRepr.Usage>>> analyze(final int fileName, final ClassReader cr) {
|
||||
final ClassCrawler visitor = new ClassCrawler(fileName);
|
||||
|
||||
cr.accept(visitor, 0);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 4/3/12
|
||||
*/
|
||||
public interface CollectionFactory<X> {
|
||||
Collection<X> create();
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.io.InlineKeyDescriptor;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentStringEnumerator;
|
||||
import org.jetbrains.ether.RW;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -64,92 +62,20 @@ class DependencyContext {
|
||||
myEnumerator = new PersistentStringEnumerator(file, true);
|
||||
}
|
||||
|
||||
static KeyDescriptor<S> descriptorS = new InlineKeyDescriptor<S>() {
|
||||
@Override
|
||||
public S fromInt(int n) {
|
||||
return new S(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toInt(S s) {
|
||||
return s.index;
|
||||
}
|
||||
};
|
||||
|
||||
static class S implements Comparable<S>, RW.Writable {
|
||||
public final int index;
|
||||
|
||||
S(final DataInput in){
|
||||
try{
|
||||
index = in.readInt();
|
||||
}
|
||||
catch (IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private S(final int i) {
|
||||
index = i;
|
||||
}
|
||||
|
||||
public S(final BufferedReader r) {
|
||||
index = RW.readInt(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
S s = (S)o;
|
||||
|
||||
if (index != s.index) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public int compareTo(S o) {
|
||||
return index - o.index;
|
||||
}
|
||||
|
||||
public void write(BufferedWriter w) {
|
||||
RW.writeln(w, Integer.toString(index));
|
||||
}
|
||||
|
||||
public void save(final DataOutput out){
|
||||
try{
|
||||
out.writeInt(index);
|
||||
}
|
||||
catch (IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(index);
|
||||
}
|
||||
}
|
||||
|
||||
public String getValue(final S s) {
|
||||
public String getValue(final int s) {
|
||||
try {
|
||||
return myEnumerator.valueOf(s.index);
|
||||
return myEnumerator.valueOf(s);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public S get(final String s) {
|
||||
public int get(final String s) {
|
||||
try {
|
||||
final int i = s == null ? myEnumerator.enumerate("") : myEnumerator.enumerate(s);
|
||||
|
||||
return new S(i);
|
||||
return i;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -169,10 +95,10 @@ class DependencyContext {
|
||||
myEnumerator.force();
|
||||
}
|
||||
|
||||
public Logger<S> getLogger(final com.intellij.openapi.diagnostic.Logger log) {
|
||||
return new Logger<S>() {
|
||||
public Logger<Integer> getLogger(final com.intellij.openapi.diagnostic.Logger log) {
|
||||
return new Logger<Integer>() {
|
||||
@Override
|
||||
public void debug(String comment, S s) {
|
||||
public void debug(String comment, Integer s) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(comment + getValue(s));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import org.jetbrains.ether.RW;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
@@ -16,16 +14,11 @@ import java.io.IOException;
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class FieldRepr extends ProtoMember {
|
||||
public void updateClassUsages(final DependencyContext context, final DependencyContext.S owner, final UsageRepr.Cluster s) {
|
||||
public void updateClassUsages(final DependencyContext context, final int owner, final UsageRepr.Cluster s) {
|
||||
type.updateClassUsages(context, owner, s);
|
||||
}
|
||||
|
||||
public FieldRepr(final DependencyContext context,
|
||||
final int a,
|
||||
final DependencyContext.S n,
|
||||
final DependencyContext.S d,
|
||||
final DependencyContext.S s,
|
||||
final Object v) {
|
||||
public FieldRepr(final DependencyContext context, final int a, final int n, final int d, final int s, final Object v) {
|
||||
super(a, s, n, TypeRepr.getType(context, d), v);
|
||||
}
|
||||
|
||||
@@ -40,12 +33,12 @@ class FieldRepr extends ProtoMember {
|
||||
|
||||
final FieldRepr fieldRepr = (FieldRepr)o;
|
||||
|
||||
return name.equals(fieldRepr.name);
|
||||
return name == fieldRepr.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * name.hashCode();
|
||||
return 31 * name;
|
||||
}
|
||||
|
||||
public static DataExternalizer<FieldRepr> externalizer(final DependencyContext context) {
|
||||
@@ -62,11 +55,11 @@ class FieldRepr extends ProtoMember {
|
||||
};
|
||||
}
|
||||
|
||||
public UsageRepr.Usage createUsage(final DependencyContext context, final DependencyContext.S owner) {
|
||||
public UsageRepr.Usage createUsage(final DependencyContext context, final int owner) {
|
||||
return UsageRepr.createFieldUsage(context, name, owner, context.get(type.getDescr(context)));
|
||||
}
|
||||
|
||||
public UsageRepr.Usage createAssignUsage(final DependencyContext context, final DependencyContext.S owner) {
|
||||
public UsageRepr.Usage createAssignUsage(final DependencyContext context, final int owner) {
|
||||
return UsageRepr.createFieldAssignUsage(context, name, owner, context.get(type.getDescr(context)));
|
||||
}
|
||||
}
|
||||
|
||||
+8
-11
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import gnu.trove.TIntIntProcedure;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -25,15 +24,13 @@ import java.util.Map;
|
||||
* Time: 23:48
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
interface Maplet<K, V> {
|
||||
boolean containsKey(final Object key);
|
||||
V get(final Object key);
|
||||
void put(final K key, final V value);
|
||||
void putAll(Maplet<K, V> m);
|
||||
void remove(final Object key);
|
||||
interface IntIntMaplet {
|
||||
boolean containsKey(final int key);
|
||||
int get(final int key);
|
||||
void put(final int key, final int value);
|
||||
void putAll(IntIntMaplet m);
|
||||
void remove(final int key);
|
||||
void close();
|
||||
Collection<K> keyCollection();
|
||||
Collection<Map.Entry<K, V>> entrySet();
|
||||
|
||||
void forEachEntry(TIntIntProcedure proc);
|
||||
void flush(boolean memoryCachesOnly);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.ether.dependencyView;
|
||||
|
||||
import gnu.trove.TIntHashSet;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: db
|
||||
* Date: 03.11.11
|
||||
* Time: 21:01
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
interface IntIntMultiMaplet {
|
||||
boolean containsKey(final int key);
|
||||
TIntHashSet get(final int key);
|
||||
void put(final int key, final int value);
|
||||
void put(final int key, final TIntHashSet value);
|
||||
void replace(final int key, final TIntHashSet value);
|
||||
void putAll(IntIntMultiMaplet m);
|
||||
void replaceAll(IntIntMultiMaplet m);
|
||||
void remove(final int key);
|
||||
void removeFrom(final int key, final int value);
|
||||
void removeAll(final int key, final TIntHashSet values);
|
||||
void close();
|
||||
void forEachEntry(TIntObjectProcedure<TIntHashSet> proc);
|
||||
void flush(boolean memoryCachesOnly);
|
||||
}
|
||||
+50
-60
@@ -15,17 +15,18 @@
|
||||
*/
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import gnu.trove.TIntIntProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -34,21 +35,31 @@ import java.util.Map;
|
||||
* Time: 0:05
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PersistentMaplet<K, V> implements Maplet<K, V> {
|
||||
public class IntIntPersistentMaplet implements IntIntMaplet {
|
||||
private static final Object NULL_OBJ = new Object();
|
||||
private static final int CACHE_SIZE = 512;
|
||||
private final PersistentHashMap<K, V> myMap;
|
||||
private final SLRUCache<K, Object> myCache;
|
||||
private final PersistentHashMap<Integer, Integer> myMap;
|
||||
private final SLRUCache<Integer, Object> myCache;
|
||||
|
||||
public PersistentMaplet(final File file, final KeyDescriptor<K> k, final DataExternalizer<V> v) {
|
||||
public IntIntPersistentMaplet(final File file, final KeyDescriptor<Integer> k) {
|
||||
try {
|
||||
myMap = new PersistentHashMap<K, V>(file, k, v);
|
||||
myCache = new SLRUCache<K, Object>(CACHE_SIZE, CACHE_SIZE) {
|
||||
myMap = new PersistentHashMap<Integer, Integer>(file, k, new DataExternalizer<Integer>() {
|
||||
@Override
|
||||
public void save(DataOutput out, Integer value) throws IOException {
|
||||
out.writeInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer read(DataInput in) throws IOException {
|
||||
return in.readInt();
|
||||
}
|
||||
});
|
||||
myCache = new SLRUCache<Integer, Object>(CACHE_SIZE, CACHE_SIZE) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Object createValue(K key) {
|
||||
public Object createValue(Integer key) {
|
||||
try {
|
||||
final V v1 = myMap.get(key);
|
||||
final Integer v1 = myMap.get(key);
|
||||
return v1 == null? NULL_OBJ : v1;
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -63,9 +74,9 @@ public class PersistentMaplet<K, V> implements Maplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final Object key) {
|
||||
public boolean containsKey(final int key) {
|
||||
try {
|
||||
return myMap.containsMapping((K)key);
|
||||
return myMap.containsMapping(key);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -73,13 +84,13 @@ public class PersistentMaplet<K, V> implements Maplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(final Object key) {
|
||||
final Object obj = myCache.get((K)key);
|
||||
return obj == NULL_OBJ? null : (V)obj;
|
||||
public int get(final int key) {
|
||||
final Object obj = myCache.get(key);
|
||||
return obj == NULL_OBJ? -1 : (Integer)obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final K key, final V value) {
|
||||
public void put(final int key, final int value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.put(key, value);
|
||||
@@ -90,18 +101,21 @@ public class PersistentMaplet<K, V> implements Maplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(final Maplet<K, V> m) {
|
||||
for (Map.Entry<K, V> e : m.entrySet()) {
|
||||
put(e.getKey(), e.getValue());
|
||||
}
|
||||
public void putAll(final IntIntMaplet m) {
|
||||
m.forEachEntry(new TIntIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int key, int value) {
|
||||
put(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final Object key) {
|
||||
public void remove(final int key) {
|
||||
try {
|
||||
final K _key = (K)key;
|
||||
myCache.remove(_key);
|
||||
myMap.remove(_key);
|
||||
myCache.remove(key);
|
||||
myMap.remove(key);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -131,44 +145,20 @@ public class PersistentMaplet<K, V> implements Maplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<K> keyCollection() {
|
||||
public void forEachEntry(final TIntIntProcedure proc) {
|
||||
try {
|
||||
return myMap.getAllKeysWithExistingMapping();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Map.Entry<K, V>> entrySet() {
|
||||
final Collection<Map.Entry<K, V>> result = new LinkedList<Map.Entry<K, V>>();
|
||||
|
||||
try {
|
||||
for (final K key : myMap.getAllKeysWithExistingMapping()) {
|
||||
final V value = get(key);
|
||||
|
||||
final Map.Entry<K, V> entry = new Map.Entry<K, V>() {
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
|
||||
@Override
|
||||
public boolean process(Integer key) {
|
||||
try {
|
||||
final Integer value = myMap.get(key);
|
||||
return value == null? proc.execute(key, -1) : proc.execute(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
result.add(entry);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.ether.dependencyView;
|
||||
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
import gnu.trove.TIntProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: db
|
||||
* Date: 08.03.11
|
||||
* Time: 15:38
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class IntIntPersistentMultiMaplet implements IntIntMultiMaplet {
|
||||
private static final TIntHashSet NULL_COLLECTION = new TIntHashSet();
|
||||
private static final int CACHE_SIZE = 128;
|
||||
private final PersistentHashMap<Integer, TIntHashSet> myMap;
|
||||
private final SLRUCache<Integer, TIntHashSet> myCache;
|
||||
|
||||
public IntIntPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer) throws IOException {
|
||||
myMap = new PersistentHashMap<Integer, TIntHashSet>(file, keyExternalizer, new IntSetExternalizer());
|
||||
myCache = new SLRUCache<Integer, TIntHashSet>(CACHE_SIZE, CACHE_SIZE) {
|
||||
@NotNull
|
||||
@Override
|
||||
public TIntHashSet createValue(Integer key) {
|
||||
try {
|
||||
final TIntHashSet collection = myMap.get(key);
|
||||
return collection == null? NULL_COLLECTION : collection;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final int key) {
|
||||
try {
|
||||
return myMap.containsMapping(key);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TIntHashSet get(final int key) {
|
||||
final TIntHashSet collection = myCache.get(key);
|
||||
return collection == NULL_COLLECTION? null : collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(int key, TIntHashSet value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
if (value == null) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
else {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final int key, final TIntHashSet value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
|
||||
public void append(final DataOutput out) throws IOException {
|
||||
final Ref<IOException> exRef = new Ref<IOException>();
|
||||
value.forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int value) {
|
||||
try {
|
||||
out.writeInt(value);
|
||||
}
|
||||
catch (IOException e) {
|
||||
exRef.set(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
final IOException exception = exRef.get();
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final int key, final int value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
|
||||
public void append(final DataOutput out) throws IOException {
|
||||
out.writeInt(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(int key, TIntHashSet values) {
|
||||
try {
|
||||
final TIntHashSet collection = myCache.get(key);
|
||||
|
||||
if (collection != NULL_COLLECTION) {
|
||||
final Ref<Boolean> isChanged = new Ref<Boolean>(Boolean.FALSE);
|
||||
values.forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int value) {
|
||||
if (collection.remove(value)) {
|
||||
isChanged.set(Boolean.TRUE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (isChanged.get()) {
|
||||
myCache.remove(key);
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
else {
|
||||
myMap.put(key, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFrom(final int key, final int value) {
|
||||
try {
|
||||
final TIntHashSet collection = myCache.get(key);
|
||||
if (collection != NULL_COLLECTION) {
|
||||
if (collection.remove(value)) {
|
||||
myCache.remove(key);
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
else {
|
||||
myMap.put(key, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final int key) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.remove(key);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(IntIntMultiMaplet m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(int key, TIntHashSet value) {
|
||||
put(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(IntIntMultiMaplet m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(int key, TIntHashSet value) {
|
||||
replace(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
myCache.clear();
|
||||
myMap.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush(boolean memoryCachesOnly) {
|
||||
if (memoryCachesOnly) {
|
||||
if (myMap.isDirty()) {
|
||||
myMap.dropMemoryCaches();
|
||||
}
|
||||
}
|
||||
else {
|
||||
myMap.force();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachEntry(final TIntObjectProcedure<TIntHashSet> procedure) {
|
||||
try {
|
||||
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
|
||||
@Override
|
||||
public boolean process(Integer key) {
|
||||
try {
|
||||
return procedure.execute(key, myMap.get(key));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class IntSetExternalizer implements DataExternalizer<TIntHashSet> {
|
||||
|
||||
@Override
|
||||
public void save(final DataOutput out, final TIntHashSet value) throws IOException {
|
||||
final Ref<IOException> exRef = new Ref<IOException>(null);
|
||||
value.forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int elem) {
|
||||
try {
|
||||
out.writeInt(elem);
|
||||
}
|
||||
catch (IOException e) {
|
||||
exRef.set(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
final IOException exception = exRef.get();
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TIntHashSet read(final DataInput in) throws IOException {
|
||||
final TIntHashSet result = new TIntHashSet();
|
||||
final DataInputStream stream = (DataInputStream)in;
|
||||
while (stream.available() > 0) {
|
||||
result.add(in.readInt());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-21
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import gnu.trove.TIntIntHashMap;
|
||||
import gnu.trove.TIntIntProcedure;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -27,33 +25,37 @@ import java.util.Map;
|
||||
* Time: 0:00
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class TransientMaplet<K, V> implements Maplet<K, V>{
|
||||
private final Map<K, V> myMap = new HashMap<K, V>();
|
||||
public class IntIntTransientMaplet implements IntIntMaplet {
|
||||
private final TIntIntHashMap myMap = new TIntIntHashMap();
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final Object key) {
|
||||
public boolean containsKey(final int key) {
|
||||
return myMap.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(final Object key) {
|
||||
public int get(final int key) {
|
||||
return myMap.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final K key, final V value) {
|
||||
public void put(final int key, final int value) {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(final Maplet<K, V> m) {
|
||||
for (Map.Entry<K, V> e : m.entrySet()) {
|
||||
myMap.put(e.getKey(), e.getValue());
|
||||
}
|
||||
public void putAll(final IntIntMaplet m) {
|
||||
m.forEachEntry(new TIntIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int key, int value) {
|
||||
myMap.put(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final Object key) {
|
||||
public void remove(final int key) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
|
||||
@@ -66,12 +68,7 @@ public class TransientMaplet<K, V> implements Maplet<K, V>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<K> keyCollection() {
|
||||
return myMap.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Map.Entry<K, V>> entrySet() {
|
||||
return myMap.entrySet();
|
||||
public void forEachEntry(TIntIntProcedure proc) {
|
||||
myMap.forEachEntry(proc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import gnu.trove.TIntHashSet;
|
||||
import gnu.trove.TIntObjectHashMap;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
import gnu.trove.TIntProcedure;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: db
|
||||
* Date: 08.03.11
|
||||
* Time: 15:38
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class IntIntTransientMultiMaplet implements IntIntMultiMaplet {
|
||||
private final TIntObjectHashMap<TIntHashSet> myMap = new TIntObjectHashMap<TIntHashSet>();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final int key) {
|
||||
return myMap.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TIntHashSet get(final int key) {
|
||||
return myMap.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(IntIntMultiMaplet m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(int key, TIntHashSet values) {
|
||||
put(key, values);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final int key, final TIntHashSet value) {
|
||||
final TIntHashSet x = myMap.get(key);
|
||||
if (x == null) {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
else {
|
||||
value.forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int value) {
|
||||
x.add(value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(int key, TIntHashSet value) {
|
||||
if (value == null) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
else {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final int key, final int value) {
|
||||
final TIntHashSet collection = myMap.get(key);
|
||||
if (collection == null) {
|
||||
final TIntHashSet x = new TIntHashSet();
|
||||
x.add(value);
|
||||
myMap.put(key, x);
|
||||
}
|
||||
else {
|
||||
collection.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFrom(final int key, final int value) {
|
||||
final TIntHashSet collection = myMap.get(key);
|
||||
if (collection != null) {
|
||||
if (collection.remove(value)) {
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(int key, TIntHashSet values) {
|
||||
final TIntHashSet collection = myMap.get(key);
|
||||
if (collection != null) {
|
||||
values.forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int value) {
|
||||
collection.remove(value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final int key) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(IntIntMultiMaplet m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(int key, TIntHashSet value) {
|
||||
replace(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachEntry(TIntObjectProcedure<TIntHashSet> procedure) {
|
||||
myMap.forEachEntry(procedure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
myMap.clear(); // free memory
|
||||
}
|
||||
|
||||
public void flush(boolean memoryCachesOnly) {
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -25,20 +26,19 @@ import java.util.Map;
|
||||
* Time: 21:01
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
interface MultiMaplet<K, V> {
|
||||
boolean containsKey(final K key);
|
||||
Collection<V> get(final K key);
|
||||
void put(final K key, final V value);
|
||||
void put(final K key, final Collection<V> value);
|
||||
void replace(final K key, final Collection<V> value);
|
||||
void putAll(MultiMaplet<K,V> m);
|
||||
void replaceAll(MultiMaplet<K, V> m);
|
||||
void remove(final K key);
|
||||
void removeFrom(final K key, final V value);
|
||||
void removeAll(final K key, final Collection<V> value);
|
||||
interface IntObjectMultiMaplet<V> {
|
||||
boolean containsKey(final int key);
|
||||
Collection<V> get(final int key);
|
||||
void put(final int key, final V value);
|
||||
void put(final int key, final Collection<V> value);
|
||||
void replace(final int key, final Collection<V> value);
|
||||
void putAll(IntObjectMultiMaplet<V> m);
|
||||
void replaceAll(IntObjectMultiMaplet<V> m);
|
||||
void remove(final int key);
|
||||
void removeFrom(final int key, final V value);
|
||||
void removeAll(final int key, final Collection<V> value);
|
||||
void close();
|
||||
Collection<K> keyCollection();
|
||||
Collection<Map.Entry<K, Collection<V>>> entrySet();
|
||||
|
||||
void forEachEntry(TIntObjectProcedure<Collection<V>> procedure);
|
||||
void flush(boolean memoryCachesOnly);
|
||||
}
|
||||
+48
-64
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -34,23 +34,23 @@ import java.util.Map;
|
||||
* Time: 15:38
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
class IntObjectPersistentMultiMaplet<V> implements IntObjectMultiMaplet<V> {
|
||||
private static final Collection NULL_COLLECTION = Collections.emptySet();
|
||||
private static final int CACHE_SIZE = 128;
|
||||
private final PersistentHashMap<K, Collection<V>> myMap;
|
||||
private final PersistentHashMap<Integer, Collection<V>> myMap;
|
||||
private final DataExternalizer<V> myValueExternalizer;
|
||||
private final SLRUCache<K, Collection> myCache;
|
||||
private final SLRUCache<Integer, Collection> myCache;
|
||||
|
||||
public PersistentMultiMaplet(final File file,
|
||||
final KeyDescriptor<K> keyExternalizer,
|
||||
final DataExternalizer<V> valueExternalizer,
|
||||
final TransientMultiMaplet.CollectionConstructor<V> collectionFactory) throws IOException {
|
||||
public IntObjectPersistentMultiMaplet(final File file,
|
||||
final KeyDescriptor<Integer> keyExternalizer,
|
||||
final DataExternalizer<V> valueExternalizer,
|
||||
final CollectionFactory<V> collectionFactory) throws IOException {
|
||||
myValueExternalizer = valueExternalizer;
|
||||
myMap = new PersistentHashMap<K, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory));
|
||||
myCache = new SLRUCache<K, Collection>(CACHE_SIZE, CACHE_SIZE) {
|
||||
myMap = new PersistentHashMap<Integer, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory));
|
||||
myCache = new SLRUCache<Integer, Collection>(CACHE_SIZE, CACHE_SIZE) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection createValue(K key) {
|
||||
public Collection createValue(Integer key) {
|
||||
try {
|
||||
final Collection<V> collection = myMap.get(key);
|
||||
return collection == null? NULL_COLLECTION : collection;
|
||||
@@ -64,7 +64,7 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final K key) {
|
||||
public boolean containsKey(final int key) {
|
||||
try {
|
||||
return myMap.containsMapping(key);
|
||||
}
|
||||
@@ -74,13 +74,13 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> get(final K key) {
|
||||
public Collection<V> get(final int key) {
|
||||
final Collection<V> collection = myCache.get(key);
|
||||
return collection == NULL_COLLECTION? null : collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(K key, Collection<V> value) {
|
||||
public void replace(int key, Collection<V> value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
if (value == null) {
|
||||
@@ -96,7 +96,7 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final K key, final Collection<V> value) {
|
||||
public void put(final int key, final Collection<V> value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
|
||||
@@ -113,12 +113,12 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final K key, final V value) {
|
||||
public void put(final int key, final V value) {
|
||||
put(key, Collections.singleton(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(K key, Collection<V> values) {
|
||||
public void removeAll(int key, Collection<V> values) {
|
||||
try {
|
||||
final Collection collection = myCache.get(key);
|
||||
|
||||
@@ -140,7 +140,7 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFrom(final K key, final V value) {
|
||||
public void removeFrom(final int key, final V value) {
|
||||
try {
|
||||
final Collection collection = myCache.get(key);
|
||||
|
||||
@@ -162,7 +162,7 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final K key) {
|
||||
public void remove(final int key) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.remove(key);
|
||||
@@ -173,26 +173,25 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(MultiMaplet<K, V> m) {
|
||||
for (Map.Entry<K, Collection<V>> entry : m.entrySet()) {
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
public void putAll(IntObjectMultiMaplet<V> m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
|
||||
@Override
|
||||
public boolean execute(int key, Collection<V> value) {
|
||||
put(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(MultiMaplet<K, V> m) {
|
||||
for (Map.Entry<K, Collection<V>> entry : m.entrySet()) {
|
||||
replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<K> keyCollection() {
|
||||
try {
|
||||
return myMap.getAllKeysWithExistingMapping();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public void replaceAll(IntObjectMultiMaplet<V> m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
|
||||
@Override
|
||||
public boolean execute(int key, Collection<V> value) {
|
||||
replace(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,34 +217,19 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Map.Entry<K, Collection<V>>> entrySet() {
|
||||
final Collection<Map.Entry<K, Collection<V>>> result = new LinkedList<Map.Entry<K, Collection<V>>>();
|
||||
|
||||
public void forEachEntry(final TIntObjectProcedure<Collection<V>> procedure) {
|
||||
try {
|
||||
for (final K key : myMap.getAllKeysWithExistingMapping()) {
|
||||
final Collection<V> value = myMap.get(key);
|
||||
|
||||
final Map.Entry<K, Collection<V>> entry = new Map.Entry<K, Collection<V>>() {
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
|
||||
@Override
|
||||
public boolean process(Integer key) {
|
||||
try {
|
||||
return procedure.execute(key, myMap.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getValue() {
|
||||
return value;
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> setValue(Collection<V> value) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
result.add(entry);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -254,10 +238,10 @@ class PersistentMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
|
||||
private static class CollectionDataExternalizer<V> implements DataExternalizer<Collection<V>> {
|
||||
private final DataExternalizer<V> myElementExternalizer;
|
||||
private final TransientMultiMaplet.CollectionConstructor<V> myCollectionFactory;
|
||||
private final CollectionFactory<V> myCollectionFactory;
|
||||
|
||||
public CollectionDataExternalizer(DataExternalizer<V> elementExternalizer,
|
||||
TransientMultiMaplet.CollectionConstructor<V> collectionFactory) {
|
||||
CollectionFactory<V> collectionFactory) {
|
||||
myElementExternalizer = elementExternalizer;
|
||||
myCollectionFactory = collectionFactory;
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import gnu.trove.TIntObjectHashMap;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: db
|
||||
* Date: 08.03.11
|
||||
* Time: 15:38
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class IntObjectTransientMultiMaplet<V> implements IntObjectMultiMaplet<V> {
|
||||
|
||||
private final TIntObjectHashMap<Collection<V>> myMap = new TIntObjectHashMap<Collection<V>>();
|
||||
private final CollectionFactory<V> myCollectionFactory;
|
||||
|
||||
public IntObjectTransientMultiMaplet(CollectionFactory<V> collectionFactory) {
|
||||
myCollectionFactory = collectionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final int key) {
|
||||
return myMap.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> get(final int key) {
|
||||
return myMap.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(IntObjectMultiMaplet<V> m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
|
||||
@Override
|
||||
public boolean execute(int key, Collection<V> value) {
|
||||
put(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final int key, final Collection<V> value) {
|
||||
final Collection<V> x = myMap.get(key);
|
||||
if (x == null) {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
else {
|
||||
x.addAll(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(int key, Collection<V> value) {
|
||||
if (value == null) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
else {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final int key, final V value) {
|
||||
final Collection<V> collection = myMap.get(key);
|
||||
if (collection == null) {
|
||||
final Collection<V> x = myCollectionFactory.create();
|
||||
x.add(value);
|
||||
myMap.put(key, x);
|
||||
}
|
||||
else {
|
||||
collection.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFrom(final int key, final V value) {
|
||||
final Collection<V> collection = myMap.get(key);
|
||||
if (collection != null) {
|
||||
if (collection.remove(value)) {
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(int key, Collection<V> values) {
|
||||
final Collection<V> collection = myMap.get(key);
|
||||
if (collection != null) {
|
||||
if (collection.removeAll(values)) {
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final int key) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(IntObjectMultiMaplet<V> m) {
|
||||
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
|
||||
@Override
|
||||
public boolean execute(int key, Collection<V> value) {
|
||||
replace(key, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachEntry(TIntObjectProcedure<Collection<V>> procedure) {
|
||||
myMap.forEachEntry(procedure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
myMap.clear(); // free memory
|
||||
}
|
||||
|
||||
public void flush(boolean memoryCachesOnly) {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -88,7 +88,7 @@ class MethodRepr extends ProtoMember {
|
||||
};
|
||||
}
|
||||
|
||||
public void updateClassUsages(final DependencyContext context, final DependencyContext.S owner, final UsageRepr.Cluster s) {
|
||||
public void updateClassUsages(final DependencyContext context, final int owner, final UsageRepr.Cluster s) {
|
||||
type.updateClassUsages(context, owner, s);
|
||||
|
||||
for (int i = 0; i < argumentTypes.length; i++) {
|
||||
@@ -102,13 +102,7 @@ class MethodRepr extends ProtoMember {
|
||||
}
|
||||
}
|
||||
|
||||
public MethodRepr(final DependencyContext context,
|
||||
final int a,
|
||||
final DependencyContext.S n,
|
||||
final DependencyContext.S s,
|
||||
final String d,
|
||||
final String[] e,
|
||||
final Object value) {
|
||||
public MethodRepr(final DependencyContext context, final int a, final int n, final int s, final String d, final String[] e, final Object value) {
|
||||
super(a, s, n, TypeRepr.getType(context, Type.getReturnType(d)), value);
|
||||
exceptions = (Set<TypeRepr.AbstractType>)TypeRepr.createClassType(context, e, new HashSet<TypeRepr.AbstractType>());
|
||||
argumentTypes = TypeRepr.getType(context, Type.getArgumentTypes(d));
|
||||
@@ -152,7 +146,7 @@ class MethodRepr extends ProtoMember {
|
||||
@Override
|
||||
public boolean satisfy(MethodRepr that) {
|
||||
if (me == that) return true;
|
||||
return me.name.equals(that.name) && Arrays.equals(me.argumentTypes, that.argumentTypes);
|
||||
return me.name == that.name && Arrays.equals(me.argumentTypes, that.argumentTypes);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -164,12 +158,12 @@ class MethodRepr extends ProtoMember {
|
||||
|
||||
final MethodRepr that = (MethodRepr)o;
|
||||
|
||||
return name.equals(that.name) && type.equals(that.type) && Arrays.equals(argumentTypes, that.argumentTypes);
|
||||
return name == that.name && type.equals(that.type) && Arrays.equals(argumentTypes, that.argumentTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (31 * Arrays.hashCode(argumentTypes) + type.hashCode()) + name.hashCode();
|
||||
return 31 * (31 * Arrays.hashCode(argumentTypes) + type.hashCode()) + name;
|
||||
}
|
||||
|
||||
private String getDescr(final DependencyContext context) {
|
||||
@@ -187,11 +181,11 @@ class MethodRepr extends ProtoMember {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public UsageRepr.Usage createUsage(final DependencyContext context, final DependencyContext.S owner) {
|
||||
public UsageRepr.Usage createUsage(final DependencyContext context, final int owner) {
|
||||
return UsageRepr.createMethodUsage(context, name, owner, getDescr(context));
|
||||
}
|
||||
|
||||
public UsageRepr.Usage createMetaUsage(final DependencyContext context, final DependencyContext.S owner) {
|
||||
public UsageRepr.Usage createMetaUsage(final DependencyContext context, final int owner) {
|
||||
return UsageRepr.createMetaMethodUsage(context, name, owner, getDescr(context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package org.jetbrains.ether.dependencyView;
|
||||
import groovyjarjarasm.asm.Opcodes;
|
||||
import org.jetbrains.ether.RW;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -14,10 +16,10 @@ import java.io.*;
|
||||
*/
|
||||
class Proto implements RW.Savable {
|
||||
public final int access;
|
||||
public final DependencyContext.S signature;
|
||||
public final DependencyContext.S name;
|
||||
public final int signature;
|
||||
public final int name;
|
||||
|
||||
protected Proto(final int access, final DependencyContext.S signature, final DependencyContext.S name) {
|
||||
protected Proto(final int access, final int signature, final int name) {
|
||||
this.access = access;
|
||||
this.signature = signature;
|
||||
this.name = name;
|
||||
@@ -26,8 +28,8 @@ class Proto implements RW.Savable {
|
||||
protected Proto(final DataInput in) {
|
||||
try {
|
||||
access = in.readInt();
|
||||
signature = new DependencyContext.S(in);
|
||||
name = new DependencyContext.S(in);
|
||||
signature = in.readInt();
|
||||
name = in.readInt();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -38,8 +40,8 @@ class Proto implements RW.Savable {
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(access);
|
||||
signature.save(out);
|
||||
name.save(out);
|
||||
out.writeInt(signature);
|
||||
out.writeInt(name);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -53,7 +55,7 @@ class Proto implements RW.Savable {
|
||||
diff |= Difference.ACCESS;
|
||||
}
|
||||
|
||||
if (!past.signature.equals(signature)) {
|
||||
if (past.signature != signature) {
|
||||
diff |= Difference.SIGNATURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,7 @@ abstract class ProtoMember extends Proto {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
protected ProtoMember(final int access,
|
||||
final DependencyContext.S signature,
|
||||
final DependencyContext.S name,
|
||||
final TypeRepr.AbstractType t,
|
||||
final Object value) {
|
||||
protected ProtoMember(final int access, final int signature, final int name, final TypeRepr.AbstractType t, final Object value) {
|
||||
super(access, signature, name);
|
||||
this.type = t;
|
||||
this.value = value;
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import org.jetbrains.ether.RW;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: db
|
||||
* Date: 08.03.11
|
||||
* Time: 15:38
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class TransientMultiMaplet<K, V> implements MultiMaplet<K, V> {
|
||||
public static <X, Y> TransientMultiMaplet<X, Y> read(final BufferedReader r,
|
||||
final RW.Reader<X> xr,
|
||||
final RW.Reader<Y> yr,
|
||||
final CollectionConstructor<Y> cc) {
|
||||
final TransientMultiMaplet<X, Y> result = new TransientMultiMaplet<X, Y>(cc);
|
||||
|
||||
final int size = RW.readInt(r);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
final X key = xr.read(r);
|
||||
result.put(key, (Set<Y>)RW.readMany(r, yr, cc.create()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public interface CollectionConstructor<X> {
|
||||
Collection<X> create();
|
||||
}
|
||||
|
||||
private final Map<K, Collection<V>> myMap = new HashMap<K, Collection<V>>();
|
||||
|
||||
private final CollectionConstructor<V> constr;
|
||||
|
||||
public TransientMultiMaplet(final CollectionConstructor<V> c) {
|
||||
constr = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final K key) {
|
||||
return myMap.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> get(final K key) {
|
||||
return myMap.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(final MultiMaplet<K, V> m) {
|
||||
for (Map.Entry<K, Collection<V>> e : m.entrySet()) {
|
||||
put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final K key, final Collection<V> value) {
|
||||
final Collection<V> x = myMap.get(key);
|
||||
if (x == null) {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
else {
|
||||
x.addAll(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(K key, Collection<V> value) {
|
||||
if (value == null) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
else {
|
||||
myMap.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final K key, final V value) {
|
||||
final Collection<V> x = constr.create();
|
||||
x.add(value);
|
||||
put(key, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFrom(final K key, final V value) {
|
||||
final Collection<V> collection = myMap.get(key);
|
||||
if (collection != null) {
|
||||
if (collection.remove(value)) {
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(K key, Collection<V> values) {
|
||||
final Collection<V> collection = myMap.get(key);
|
||||
if (collection != null) {
|
||||
if (collection.removeAll(values)) {
|
||||
if (collection.isEmpty()) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final K key) {
|
||||
myMap.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(MultiMaplet<K, V> m) {
|
||||
for (Map.Entry<K, Collection<V>> e : m.entrySet()) {
|
||||
replace(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<K> keyCollection() {
|
||||
return myMap.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<K, Collection<V>>> entrySet() {
|
||||
return myMap.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
myMap.clear(); // free memory
|
||||
}
|
||||
|
||||
public void flush(boolean memoryCachesOnly) {
|
||||
}
|
||||
}
|
||||
@@ -28,21 +28,21 @@ class TypeRepr {
|
||||
}
|
||||
|
||||
interface AbstractType extends RW.Savable {
|
||||
void updateClassUsages(DependencyContext context, DependencyContext.S owner, UsageRepr.Cluster s);
|
||||
void updateClassUsages(DependencyContext context, int owner, UsageRepr.Cluster s);
|
||||
String getDescr(DependencyContext context);
|
||||
void save(DataOutput out);
|
||||
}
|
||||
|
||||
public static class PrimitiveType implements AbstractType {
|
||||
public final DependencyContext.S type;
|
||||
public final int myType;
|
||||
|
||||
@Override
|
||||
public String getDescr(final DependencyContext context) {
|
||||
return context.getValue(type);
|
||||
return context.getValue(myType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClassUsages(final DependencyContext context, final DependencyContext.S owner, final UsageRepr.Cluster s) {
|
||||
public void updateClassUsages(final DependencyContext context, final int owner, final UsageRepr.Cluster s) {
|
||||
|
||||
}
|
||||
|
||||
@@ -50,19 +50,24 @@ class TypeRepr {
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(PRIMITIVE_TYPE);
|
||||
type.save(out);
|
||||
out.writeInt(myType);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
PrimitiveType(final DependencyContext.S type) {
|
||||
this.type = type;
|
||||
PrimitiveType(final int type) {
|
||||
this.myType = type;
|
||||
}
|
||||
|
||||
PrimitiveType(final DataInput in) {
|
||||
type = new DependencyContext.S(in);
|
||||
try {
|
||||
myType = in.readInt();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,12 +77,12 @@ class TypeRepr {
|
||||
|
||||
final PrimitiveType that = (PrimitiveType)o;
|
||||
|
||||
return type.equals(that.type);
|
||||
return myType == that.myType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return type.hashCode();
|
||||
return myType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +105,7 @@ class TypeRepr {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClassUsages(final DependencyContext context, final DependencyContext.S owner, final UsageRepr.Cluster s) {
|
||||
public void updateClassUsages(final DependencyContext context, final int owner, final UsageRepr.Cluster s) {
|
||||
elementType.updateClassUsages(context, owner, s);
|
||||
}
|
||||
|
||||
@@ -136,7 +141,7 @@ class TypeRepr {
|
||||
}
|
||||
|
||||
public static class ClassType implements AbstractType {
|
||||
public final DependencyContext.S className;
|
||||
public final int className;
|
||||
public final AbstractType[] typeArgs;
|
||||
|
||||
@Override
|
||||
@@ -145,18 +150,18 @@ class TypeRepr {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClassUsages(final DependencyContext context, final DependencyContext.S owner, final UsageRepr.Cluster s) {
|
||||
public void updateClassUsages(final DependencyContext context, final int owner, final UsageRepr.Cluster s) {
|
||||
s.addUsage(owner, UsageRepr.createClassUsage(context, className));
|
||||
}
|
||||
|
||||
ClassType(final DependencyContext.S className) {
|
||||
ClassType(final int className) {
|
||||
this.className = className;
|
||||
typeArgs = new AbstractType[0];
|
||||
}
|
||||
|
||||
ClassType(final DependencyContext context, final DataInput in) {
|
||||
try {
|
||||
className = new DependencyContext.S(in);
|
||||
className = in.readInt();
|
||||
final int size = in.readInt();
|
||||
typeArgs = new AbstractType[size];
|
||||
|
||||
@@ -178,7 +183,7 @@ class TypeRepr {
|
||||
|
||||
final ClassType classType = (ClassType)o;
|
||||
|
||||
if (className != null ? !className.equals(classType.className) : classType.className != null) return false;
|
||||
if (className != classType.className) return false;
|
||||
if (!Arrays.equals(typeArgs, classType.typeArgs)) return false;
|
||||
|
||||
return true;
|
||||
@@ -186,7 +191,7 @@ class TypeRepr {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = className != null ? className.hashCode() : 0;
|
||||
int result = className;
|
||||
result = 31 * result + (typeArgs != null ? Arrays.hashCode(typeArgs) : 0);
|
||||
return result;
|
||||
}
|
||||
@@ -195,7 +200,7 @@ class TypeRepr {
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(CLASS_TYPE);
|
||||
className.save(out);
|
||||
out.writeInt(className);
|
||||
out.writeInt(typeArgs.length);
|
||||
for (AbstractType t : typeArgs) {
|
||||
t.save(out);
|
||||
@@ -231,11 +236,11 @@ class TypeRepr {
|
||||
return acc;
|
||||
}
|
||||
|
||||
public static ClassType createClassType(final DependencyContext context, final DependencyContext.S s) {
|
||||
public static ClassType createClassType(final DependencyContext context, final int s) {
|
||||
return (ClassType)context.getType(new ClassType(s));
|
||||
}
|
||||
|
||||
public static AbstractType getType(final DependencyContext context, final DependencyContext.S descr) {
|
||||
public static AbstractType getType(final DependencyContext context, final int descr) {
|
||||
final Type t = Type.getType(context.getValue(descr));
|
||||
|
||||
switch (t.getSort()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.ether.dependencyView;
|
||||
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.ether.RW;
|
||||
|
||||
@@ -26,13 +27,15 @@ class UsageRepr {
|
||||
private final static int CLASS_NEW_USAGE = 5;
|
||||
private final static int ANNOTATION_USAGE = 6;
|
||||
private final static int METAMETHOD_USAGE = 7;
|
||||
private static final int DEFAULT_SET_CAPACITY = 32;
|
||||
private static final float DEFAULT_SET_LOAD_FACTOR = 0.98f;
|
||||
|
||||
private UsageRepr() {
|
||||
|
||||
}
|
||||
|
||||
public static class Cluster implements RW.Savable {
|
||||
private final Map<Usage, Set<DependencyContext.S>> myUsageToDependenciesMap = new HashMap<Usage, Set<DependencyContext.S>>();
|
||||
private final Map<Usage, TIntHashSet> myUsageToDependenciesMap = new HashMap<Usage, TIntHashSet>(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR);
|
||||
|
||||
public Cluster() {
|
||||
}
|
||||
@@ -43,7 +46,7 @@ class UsageRepr {
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
final Usage u = externalizer(context).read(in);
|
||||
final Set<DependencyContext.S> s = (Set<DependencyContext.S>)RW.read(DependencyContext.descriptorS, new HashSet<DependencyContext.S>(), in);
|
||||
final TIntHashSet s = RW.read(new TIntHashSet(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR), in);
|
||||
myUsageToDependenciesMap.put(u, s);
|
||||
}
|
||||
}
|
||||
@@ -56,11 +59,11 @@ class UsageRepr {
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(myUsageToDependenciesMap.size());
|
||||
for (Map.Entry<Usage, Set<DependencyContext.S>> entry : myUsageToDependenciesMap.entrySet()) {
|
||||
for (Map.Entry<Usage, TIntHashSet> entry : myUsageToDependenciesMap.entrySet()) {
|
||||
final Usage u = entry.getKey();
|
||||
u.save(out);
|
||||
final Set<DependencyContext.S> deps = entry.getValue();
|
||||
RW.save(deps, DependencyContext.descriptorS, out);
|
||||
final TIntHashSet deps = entry.getValue();
|
||||
RW.save(deps, out);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -68,11 +71,11 @@ class UsageRepr {
|
||||
}
|
||||
}
|
||||
|
||||
public void addUsage(final DependencyContext.S residence, final Usage usage) {
|
||||
Set<DependencyContext.S> s = myUsageToDependenciesMap.get(usage);
|
||||
public void addUsage(final int residence, final Usage usage) {
|
||||
TIntHashSet s = myUsageToDependenciesMap.get(usage);
|
||||
|
||||
if (s == null) {
|
||||
s = new HashSet<DependencyContext.S>();
|
||||
s = new TIntHashSet(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR);
|
||||
myUsageToDependenciesMap.put(usage, s);
|
||||
}
|
||||
|
||||
@@ -83,7 +86,7 @@ class UsageRepr {
|
||||
return Collections.unmodifiableSet(myUsageToDependenciesMap.keySet());
|
||||
}
|
||||
|
||||
public Set<DependencyContext.S> getResidence(final Usage usage) {
|
||||
public TIntHashSet getResidence(final Usage usage) {
|
||||
return myUsageToDependenciesMap.get(usage);
|
||||
}
|
||||
|
||||
@@ -124,33 +127,38 @@ class UsageRepr {
|
||||
}
|
||||
|
||||
public static abstract class Usage implements RW.Savable {
|
||||
public abstract DependencyContext.S getOwner();
|
||||
public abstract int getOwner();
|
||||
}
|
||||
|
||||
public static abstract class FMUsage extends Usage {
|
||||
public final DependencyContext.S name;
|
||||
public final DependencyContext.S owner;
|
||||
public final int name;
|
||||
public final int owner;
|
||||
|
||||
@Override
|
||||
public DependencyContext.S getOwner() {
|
||||
public int getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
private FMUsage(final DependencyContext.S n, final DependencyContext.S o) {
|
||||
private FMUsage(final int n, final int o) {
|
||||
name = n;
|
||||
owner = o;
|
||||
}
|
||||
|
||||
private FMUsage(final DataInput in) {
|
||||
name = new DependencyContext.S(in);
|
||||
owner = new DependencyContext.S(in);
|
||||
try {
|
||||
name = in.readInt();
|
||||
owner = in.readInt();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void save(final int tag, final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(tag);
|
||||
name.save(out);
|
||||
owner.save(out);
|
||||
out.writeInt(name);
|
||||
out.writeInt(owner);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -164,27 +172,22 @@ class UsageRepr {
|
||||
|
||||
FMUsage fmUsage = (FMUsage)o;
|
||||
|
||||
if (!name.equals(fmUsage.name)) return false;
|
||||
if (!owner.equals(fmUsage.owner)) return false;
|
||||
if (name != fmUsage.name) return false;
|
||||
if (owner != fmUsage.owner) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result + owner.hashCode();
|
||||
return result;
|
||||
return 31 * name + owner;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FieldUsage extends FMUsage {
|
||||
public final TypeRepr.AbstractType type;
|
||||
|
||||
private FieldUsage(final DependencyContext context,
|
||||
final DependencyContext.S n,
|
||||
final DependencyContext.S o,
|
||||
final DependencyContext.S d) {
|
||||
private FieldUsage(final DependencyContext context, final int n, final int o, final int d) {
|
||||
super(n, o);
|
||||
type = TypeRepr.getType(context, d);
|
||||
}
|
||||
@@ -212,20 +215,17 @@ class UsageRepr {
|
||||
|
||||
final FieldUsage that = (FieldUsage)o;
|
||||
|
||||
return type.equals(that.type) && name.equals(that.name) && owner.equals(that.owner);
|
||||
return type.equals(that.type) && name == that.name && owner == that.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (31 * type.hashCode() + (name.hashCode())) + owner.hashCode();
|
||||
return 31 * (31 * type.hashCode() + name) + owner;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FieldAssignUsage extends FieldUsage {
|
||||
private FieldAssignUsage(final DependencyContext context,
|
||||
final DependencyContext.S n,
|
||||
final DependencyContext.S o,
|
||||
final DependencyContext.S d) {
|
||||
private FieldAssignUsage(final DependencyContext context, final int n, final int o, final int d) {
|
||||
super(context, n, o, d);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ class UsageRepr {
|
||||
|
||||
final FieldAssignUsage that = (FieldAssignUsage)o;
|
||||
|
||||
return type.equals(that.type) && name.equals(that.name) && owner.equals(that.owner);
|
||||
return type.equals(that.type) && name == that.name && owner == that.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,7 +259,7 @@ class UsageRepr {
|
||||
public final TypeRepr.AbstractType[] argumentTypes;
|
||||
public final TypeRepr.AbstractType returnType;
|
||||
|
||||
private MethodUsage(final DependencyContext context, final DependencyContext.S n, final DependencyContext.S o, final String d) {
|
||||
private MethodUsage(final DependencyContext context, final int n, final int o, final String d) {
|
||||
super(n, o);
|
||||
argumentTypes = TypeRepr.getType(context, Type.getArgumentTypes(d));
|
||||
returnType = TypeRepr.getType(context, Type.getReturnType(d));
|
||||
@@ -293,25 +293,25 @@ class UsageRepr {
|
||||
|
||||
if (!Arrays.equals(argumentTypes, that.argumentTypes)) return false;
|
||||
if (returnType != null ? !returnType.equals(that.returnType) : that.returnType != null) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false;
|
||||
if (name != that.name) return false;
|
||||
if (owner != that.owner) return false;
|
||||
|
||||
return Arrays.equals(argumentTypes, that.argumentTypes) &&
|
||||
returnType.equals(that.returnType) &&
|
||||
name.equals(that.name) &&
|
||||
owner.equals(that.owner);
|
||||
name == that.name &&
|
||||
owner == that.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((31 * Arrays.hashCode(argumentTypes) + (returnType.hashCode())) * 31 + (name.hashCode())) * 31 + (owner.hashCode());
|
||||
return ((31 * Arrays.hashCode(argumentTypes) + (returnType.hashCode())) * 31 + (name)) * 31 + (owner);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MetaMethodUsage extends FMUsage {
|
||||
private int myArity;
|
||||
|
||||
public MetaMethodUsage(final DependencyContext context, final DependencyContext.S n, final DependencyContext.S o, final String descr) {
|
||||
public MetaMethodUsage(final DependencyContext context, final int n, final int o, final String descr) {
|
||||
super(n, o);
|
||||
myArity = TypeRepr.getType(context, Type.getArgumentTypes(descr)).length;
|
||||
}
|
||||
@@ -359,26 +359,31 @@ class UsageRepr {
|
||||
}
|
||||
|
||||
public static class ClassUsage extends Usage {
|
||||
final DependencyContext.S className;
|
||||
final int className;
|
||||
|
||||
@Override
|
||||
public DependencyContext.S getOwner() {
|
||||
public int getOwner() {
|
||||
return className;
|
||||
}
|
||||
|
||||
private ClassUsage(final DependencyContext.S n) {
|
||||
private ClassUsage(final int n) {
|
||||
className = n;
|
||||
}
|
||||
|
||||
private ClassUsage(final DataInput in) {
|
||||
className = new DependencyContext.S(in);
|
||||
try {
|
||||
className = in.readInt();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(CLASS_USAGE);
|
||||
className.save(out);
|
||||
out.writeInt(className);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -392,36 +397,41 @@ class UsageRepr {
|
||||
|
||||
final ClassUsage that = (ClassUsage)o;
|
||||
|
||||
return className.equals(that.className);
|
||||
return className == that.className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return className.hashCode();
|
||||
return className;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClassExtendsUsage extends Usage {
|
||||
protected final DependencyContext.S className;
|
||||
protected final int className;
|
||||
|
||||
@Override
|
||||
public DependencyContext.S getOwner() {
|
||||
public int getOwner() {
|
||||
return className;
|
||||
}
|
||||
|
||||
private ClassExtendsUsage(final DependencyContext.S n) {
|
||||
private ClassExtendsUsage(final int n) {
|
||||
className = n;
|
||||
}
|
||||
|
||||
private ClassExtendsUsage(final DataInput in) {
|
||||
className = new DependencyContext.S(in);
|
||||
try {
|
||||
className = in.readInt();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(CLASS_EXTENDS_USAGE);
|
||||
className.save(out);
|
||||
out.writeInt(className);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -430,7 +440,7 @@ class UsageRepr {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return className.hashCode() + 1;
|
||||
return className + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,14 +450,14 @@ class UsageRepr {
|
||||
|
||||
ClassExtendsUsage that = (ClassExtendsUsage)o;
|
||||
|
||||
if (!className.equals(that.className)) return false;
|
||||
if (className != that.className) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClassNewUsage extends ClassExtendsUsage {
|
||||
public ClassNewUsage(DependencyContext.S n) {
|
||||
public ClassNewUsage(int n) {
|
||||
super(n);
|
||||
}
|
||||
|
||||
@@ -459,7 +469,7 @@ class UsageRepr {
|
||||
public void save(final DataOutput out) {
|
||||
try {
|
||||
out.writeInt(CLASS_NEW_USAGE);
|
||||
className.save(out);
|
||||
out.writeInt(className);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -468,7 +478,7 @@ class UsageRepr {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return className.hashCode() + 2;
|
||||
return className + 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,7 +497,7 @@ class UsageRepr {
|
||||
};
|
||||
|
||||
final TypeRepr.ClassType type;
|
||||
final Collection<DependencyContext.S> usedArguments;
|
||||
final TIntHashSet usedArguments;
|
||||
final Collection<ElementType> usedTargets;
|
||||
|
||||
public boolean satisfies(final Usage usage) {
|
||||
@@ -501,9 +511,9 @@ class UsageRepr {
|
||||
boolean argumentsSatisfy = false;
|
||||
|
||||
if (usedArguments != null) {
|
||||
final Collection<DependencyContext.S> arguments = new HashSet<DependencyContext.S>(usedArguments);
|
||||
final TIntHashSet arguments = new TIntHashSet(usedArguments.toArray());
|
||||
|
||||
arguments.removeAll(annotationUsage.usedArguments);
|
||||
arguments.removeAll(annotationUsage.usedArguments.toArray());
|
||||
|
||||
argumentsSatisfy = !arguments.isEmpty();
|
||||
}
|
||||
@@ -525,7 +535,7 @@ class UsageRepr {
|
||||
}
|
||||
|
||||
private AnnotationUsage(final TypeRepr.ClassType type,
|
||||
final Collection<DependencyContext.S> usedArguments,
|
||||
final TIntHashSet usedArguments,
|
||||
final Collection<ElementType> targets) {
|
||||
this.type = type;
|
||||
this.usedArguments = usedArguments;
|
||||
@@ -537,7 +547,7 @@ class UsageRepr {
|
||||
|
||||
try {
|
||||
type = (TypeRepr.ClassType)externalizer.read(in);
|
||||
usedArguments = RW.read(DependencyContext.descriptorS, new HashSet<DependencyContext.S>(), in);
|
||||
usedArguments = RW.read(new TIntHashSet(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR), in);
|
||||
usedTargets = RW.read(elementTypeExternalizer, new HashSet<ElementType>(), in);
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -550,7 +560,7 @@ class UsageRepr {
|
||||
try {
|
||||
out.writeInt(ANNOTATION_USAGE);
|
||||
type.save(out);
|
||||
RW.save(usedArguments, DependencyContext.descriptorS, out);
|
||||
RW.save(usedArguments, out);
|
||||
RW.save(usedTargets, elementTypeExternalizer, out);
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -559,7 +569,7 @@ class UsageRepr {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DependencyContext.S getOwner() {
|
||||
public int getOwner() {
|
||||
return type.className;
|
||||
}
|
||||
|
||||
@@ -587,50 +597,44 @@ class UsageRepr {
|
||||
}
|
||||
|
||||
public static Usage createFieldUsage(final DependencyContext context,
|
||||
final DependencyContext.S name,
|
||||
final DependencyContext.S owner,
|
||||
final DependencyContext.S descr) {
|
||||
final int name,
|
||||
final int owner,
|
||||
final int descr) {
|
||||
return context.getUsage(new FieldUsage(context, name, owner, descr));
|
||||
}
|
||||
|
||||
public static Usage createFieldAssignUsage(final DependencyContext context,
|
||||
final DependencyContext.S name,
|
||||
final DependencyContext.S owner,
|
||||
final DependencyContext.S descr) {
|
||||
final int name,
|
||||
final int owner,
|
||||
final int descr) {
|
||||
return context.getUsage(new FieldAssignUsage(context, name, owner, descr));
|
||||
}
|
||||
|
||||
public static Usage createMethodUsage(final DependencyContext context,
|
||||
final DependencyContext.S name,
|
||||
final DependencyContext.S owner,
|
||||
final int name,
|
||||
final int owner,
|
||||
final String descr) {
|
||||
return context.getUsage(new MethodUsage(context, name, owner, descr));
|
||||
}
|
||||
|
||||
public static Usage createMetaMethodUsage(final DependencyContext context,
|
||||
final DependencyContext.S name,
|
||||
final DependencyContext.S owner,
|
||||
final String descr) {
|
||||
public static Usage createMetaMethodUsage(final DependencyContext context, final int name, final int owner, final String descr) {
|
||||
return context.getUsage(new MetaMethodUsage(context, name, owner, descr));
|
||||
}
|
||||
|
||||
public static Usage createClassUsage(final DependencyContext context, final DependencyContext.S name) {
|
||||
public static Usage createClassUsage(final DependencyContext context, final int name) {
|
||||
return context.getUsage(new ClassUsage(name));
|
||||
}
|
||||
|
||||
|
||||
public static Usage createClassExtendsUsage(final DependencyContext context, final DependencyContext.S name) {
|
||||
public static Usage createClassExtendsUsage(final DependencyContext context, final int name) {
|
||||
return context.getUsage(new ClassExtendsUsage(name));
|
||||
}
|
||||
|
||||
public static Usage createClassNewUsage(final DependencyContext context, final DependencyContext.S name) {
|
||||
public static Usage createClassNewUsage(final DependencyContext context, final int name) {
|
||||
return context.getUsage(new ClassNewUsage(name));
|
||||
}
|
||||
|
||||
public static Usage createAnnotationUsage(final DependencyContext context,
|
||||
final TypeRepr.ClassType type,
|
||||
final Collection<DependencyContext.S> usedArguments,
|
||||
final Collection<ElementType> targets) {
|
||||
public static Usage createAnnotationUsage(final DependencyContext context, final TypeRepr.ClassType type, final TIntHashSet usedArguments, final Collection<ElementType> targets) {
|
||||
return context.getUsage(new AnnotationUsage(type, usedArguments, targets));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user