printScopeStructure() introduced for debugging

This commit is contained in:
Andrey Breslav
2013-11-19 16:00:49 +04:00
parent af68739e69
commit d9444fea09
18 changed files with 237 additions and 4 deletions
@@ -18,11 +18,13 @@ package org.jetbrains.jet.lang.resolve.java.scope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaMemberResolver;
import org.jetbrains.jet.lang.resolve.java.resolver.ProgressChecker;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
import org.jetbrains.jet.utils.Printer;
import java.util.*;
@@ -170,4 +172,16 @@ public abstract class JavaBaseScope extends JetScopeImpl {
}
return result;
}
@TestOnly
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), " {");
p.pushIndent();
p.println("descriptor = ", descriptor);
p.popIndent();
p.println("}");
}
}
@@ -17,9 +17,11 @@
package org.jetbrains.jet.lang.resolve.scopes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.List;
@@ -98,4 +100,17 @@ public abstract class AbstractScopeAdapter implements JetScope {
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
return getWorkerScope().getOwnDeclaredDescriptors();
}
@TestOnly
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), " {");
p.pushIndent();
p.print("worker =");
getWorkerScope().printScopeStructure(p.withholdIndentOnce());
p.popIndent();
p.println("}");
}
}
@@ -19,9 +19,11 @@ package org.jetbrains.jet.lang.resolve.scopes;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.Collections;
@@ -170,4 +172,18 @@ public class ChainedScope implements JetScope {
public String toString() {
return debugName;
}
@TestOnly
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), ": ", debugName, " {");
p.pushIndent();
for (JetScope scope : scopeChain) {
scope.printScopeStructure(p);
}
p.popIndent();
p.println("}");
}
}
@@ -20,9 +20,11 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.List;
@@ -108,4 +110,17 @@ public class FilteringScope implements JetScope {
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
return Collections2.filter(workerScope.getOwnDeclaredDescriptors(), predicate);
}
@TestOnly
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), " {");
p.pushIndent();
p.print("workerScope = ");
workerScope.printScopeStructure(p.withholdIndentOnce());
p.popIndent();
p.println("}");
}
}
@@ -19,9 +19,11 @@ package org.jetbrains.jet.lang.resolve.scopes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ReadOnly;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.List;
@@ -38,6 +40,11 @@ public interface JetScope {
public String toString() {
return "EMPTY";
}
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println("EMPTY");
}
};
/**
@@ -93,4 +100,7 @@ public interface JetScope {
@NotNull
@ReadOnly
Collection<DeclarationDescriptor> getOwnDeclaredDescriptors();
@TestOnly
void printScopeStructure(@NotNull Printer p);
}
@@ -17,9 +17,11 @@
package org.jetbrains.jet.lang.resolve.scopes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.Collections;
@@ -88,4 +90,9 @@ public abstract class JetScopeImpl implements JetScope {
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
return Collections.emptyList();
}
}
// This method should not be implemented here by default: every scope class has its unique structure pattern
@TestOnly
@Override
public abstract void printScopeStructure(@NotNull Printer p);
}
@@ -20,10 +20,12 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.List;
@@ -150,4 +152,22 @@ public class SubstitutingScope implements JetScope {
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
return substitute(workerScope.getOwnDeclaredDescriptors());
}
@TestOnly
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), " {");
p.pushIndent();
p.println("substitutor = ");
p.pushIndent();
p.println(substitutor);
p.popIndent();
p.print("workerScope = ");
workerScope.printScopeStructure(p.withholdIndentOnce());
p.popIndent();
p.println("}");
}
}
@@ -19,11 +19,13 @@ package org.jetbrains.jet.lang.resolve.scopes;
import com.google.common.collect.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.utils.CommonSuppliers;
import org.jetbrains.jet.utils.Printer;
import java.util.*;
@@ -507,4 +509,10 @@ public class WritableScopeImpl extends WritableScopeWithImports {
throw new IllegalStateException("unknown classifier: " + classifier);
}
}
@TestOnly
@Override
protected void printAdditionalScopeStructure(@NotNull Printer p) {
p.println("allDescriptorsDone = ", allDescriptorsDone);
}
}
@@ -20,8 +20,10 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.*;
@@ -249,4 +251,36 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
return getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + " " + debugName + " for " + getContainingDeclaration();
}
@TestOnly
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), ": ", debugName, " for ", getContainingDeclaration(), " {");
p.pushIndent();
p.println("lockLevel = ", lockLevel);
printAdditionalScopeStructure(p);
p.print("worker = ");
getWorkerScope().printScopeStructure(p.withholdIndentOnce());
if (getImports().isEmpty()) {
p.println("imports = {}");
}
else {
p.println("imports = {");
p.pushIndent();
for (JetScope anImport : getImports()) {
anImport.printScopeStructure(p);
}
p.popIndent();
p.println("}");
}
p.popIndent();
p.println("}");
}
@TestOnly
protected abstract void printAdditionalScopeStructure(@NotNull Printer p);
}
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor;
import org.jetbrains.jet.lang.types.error.ErrorSimpleFunctionDescriptorImpl;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.Collections;
@@ -155,6 +156,11 @@ public class ErrorUtils {
public String toString() {
return "ErrorScope{" + debugMessage + '}';
}
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), ": ", debugMessage);
}
}
private static class ThrowingScope implements JetScope {
@@ -240,6 +246,11 @@ public class ErrorUtils {
public String toString() {
return "ThrowingScope{" + debugMessage + '}';
}
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println(getClass().getSimpleName(), ": ", debugMessage);
}
}
private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor("");
@@ -0,0 +1,145 @@
/*
* Copyright 2010-2013 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.jet.utils;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
public class Printer {
private static final String INDENTATION_UNIT = " ";
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final Appendable out;
private final int maxBlankLines;
private String indent = "";
private int blankLineCountIncludingCurrent = 0;
private boolean withholdIndentOnce = false;
public Printer(@NotNull Appendable out) {
this(out, Integer.MAX_VALUE);
}
public Printer(@NotNull Appendable out, int maxBlankLines) {
this.out = out;
this.maxBlankLines = maxBlankLines;
}
private void append(Object o) {
try {
out.append(o.toString());
}
catch (IOException e) {
// Do nothing
}
}
@NotNull
public Printer println(Object... objects) {
print(objects);
printLineSeparator();
return this;
}
private void printLineSeparator() {
if (blankLineCountIncludingCurrent <= maxBlankLines) {
blankLineCountIncludingCurrent++;
append(LINE_SEPARATOR);
}
}
@NotNull
public Printer print(Object... objects) {
if (withholdIndentOnce) {
withholdIndentOnce = false;
}
else {
append(indent);
}
printWithNoIndent(objects);
return this;
}
@NotNull
public Printer printWithNoIndent(Object... objects) {
for (Object object : objects) {
blankLineCountIncludingCurrent = 0;
append(object);
}
return this;
}
@NotNull
public Printer withholdIndentOnce() {
withholdIndentOnce = true;
return this;
}
@NotNull
public Printer printlnWithNoIndent(Object... objects) {
printWithNoIndent(objects);
printLineSeparator();
return this;
}
@NotNull
public Printer pushIndent() {
indent += INDENTATION_UNIT;
return this;
}
@NotNull
public Printer popIndent() {
if (indent.length() < INDENTATION_UNIT.length()) {
throw new IllegalStateException("No indentation to pop");
}
indent = indent.substring(INDENTATION_UNIT.length());
return this;
}
@NotNull
public Printer separated(Object separator, Object... items) {
for (int i = 0; i < items.length; i++) {
if (i > 0) {
printlnWithNoIndent(separator);
}
printlnWithNoIndent(items[i]);
}
return this;
}
@NotNull
public Printer separated(Object separator, Collection<?> items) {
for (Iterator<?> iterator = items.iterator(); iterator.hasNext(); ) {
printlnWithNoIndent(iterator.next());
if (iterator.hasNext()) {
printlnWithNoIndent(separator);
}
}
return this;
}
}