提交 652be4ed 编写于 作者: P Pavel V. Talanov

Revert misleading whitespace changes.

上级 62efa952
......@@ -54,18 +54,12 @@ public class GenerationState {
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files);
}
public GenerationState(Project project,
ClassBuilderFactory builderFactory,
Progress progress,
@NotNull AnalyzeExhaust exhaust,
@NotNull List<JetFile> files) {
public GenerationState(Project project, ClassBuilderFactory builderFactory, Progress progress, @NotNull AnalyzeExhaust exhaust, @NotNull List<JetFile> files) {
this.project = project;
this.progress = progress;
this.analyzeExhaust = exhaust;
this.files = files;
this.injector =
new InjectorForJvmCodegen(analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), this.files, project, this,
builderFactory);
this.injector = new InjectorForJvmCodegen(analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), this.files, project, this, builderFactory);
}
@NotNull
......@@ -90,13 +84,11 @@ public class GenerationState {
}
public ClassBuilder forClassImplementation(ClassDescriptor aClass) {
return getFactory().newVisitor(
getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName() + ".class");
return getFactory().newVisitor(getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName() + ".class");
}
public ClassBuilder forTraitImplementation(ClassDescriptor aClass) {
return getFactory().newVisitor(
getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.TRAIT_IMPL).getInternalName() + ".class");
return getFactory().newVisitor(getInjector().getJetTypeMapper().mapType(aClass.getDefaultType(), OwnerKind.TRAIT_IMPL).getInternalName() + ".class");
}
public Pair<String, ClassBuilder> forAnonymousSubclass(JetExpression expression) {
......@@ -142,17 +134,14 @@ public class GenerationState {
closure.cv = nameAndVisitor.getSecond();
closure.name = nameAndVisitor.getFirst();
final CodegenContext objectContext = closure.context.intoAnonymousClass(
closure, analyzeExhaust.getBindingContext().get(BindingContext.CLASS, objectDeclaration), OwnerKind.IMPLEMENTATION,
injector.getJetTypeMapper());
closure, analyzeExhaust.getBindingContext().get(BindingContext.CLASS, objectDeclaration), OwnerKind.IMPLEMENTATION, injector.getJetTypeMapper());
new ImplementationBodyCodegen(objectDeclaration, objectContext, nameAndVisitor.getSecond(), this).generate();
ConstructorDescriptor constructorDescriptor = analyzeExhaust.getBindingContext().get(BindingContext.CONSTRUCTOR, objectDeclaration);
CallableMethod callableMethod = injector.getJetTypeMapper().mapToCallableMethod(
constructorDescriptor, OwnerKind.IMPLEMENTATION,
injector.getJetTypeMapper().hasThis0(constructorDescriptor.getContainingDeclaration()));
return new GeneratedAnonymousClassDescriptor(nameAndVisitor.first, callableMethod.getSignature().getAsmMethod(),
objectContext.outerWasUsed, null);
constructorDescriptor, OwnerKind.IMPLEMENTATION, injector.getJetTypeMapper().hasThis0(constructorDescriptor.getContainingDeclaration()));
return new GeneratedAnonymousClassDescriptor(nameAndVisitor.first, callableMethod.getSignature().getAsmMethod(), objectContext.outerWasUsed, null);
}
public String createText() {
......@@ -162,8 +151,8 @@ public class GenerationState {
List<String> files = factory.files();
for (String file : files) {
// if (!file.startsWith("kotlin/")) {
answer.append("@").append(file).append('\n');
answer.append(factory.asText(file));
answer.append("@").append(file).append('\n');
answer.append(factory.asText(file));
// }
}
......
......@@ -34,11 +34,11 @@ public class GenerationUtils {
}
public static GenerationState compileFileGetGenerationState(JetFile psiFile) {
final AnalyzeExhaust analyzeExhaust =
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, JetControlFlowDataTraceFactory.EMPTY);
GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust,
Collections.singletonList(psiFile));
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, JetControlFlowDataTraceFactory.EMPTY);
GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false),
analyzeExhaust, Collections.singletonList(psiFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state;
}
}
......@@ -37,13 +37,12 @@ import java.util.Collections;
*/
public abstract class CodegenTestCase extends JetLiteFixture {
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args)
throws IllegalAccessException {
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args) throws IllegalAccessException {
boolean caught = false;
try {
foo.invoke(instance, args);
}
catch (InvocationTargetException ex) {
catch(InvocationTargetException ex) {
caught = exceptionClass.isInstance(ex.getTargetException());
}
assertTrue(caught);
......@@ -61,17 +60,16 @@ public abstract class CodegenTestCase extends JetLiteFixture {
}
protected void loadText(final String text) {
myFile = (JetFile)createFile("a.jet", text);
myFile = (JetFile) createFile("a.jet", text);
}
@Override
protected String loadFile(final String name) {
try {
final String content = doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
myFile = (JetFile)createFile(name, content);
myFile = (JetFile) createFile(name, content);
return content;
}
catch (IOException e) {
} catch (IOException e) {
throw new RuntimeException(e);
}
}
......@@ -89,12 +87,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String actual;
try {
actual = blackBox();
}
catch (NoClassDefFoundError e) {
} catch (NoClassDefFoundError e) {
System.out.println(generateToText());
throw e;
}
catch (Throwable e) {
} catch (Throwable e) {
System.out.println(generateToText());
throw new RuntimeException(e);
}
......@@ -112,10 +108,9 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
Class<?> namespaceClass = loader.loadClass(fqName);
Method method = namespaceClass.getMethod("box");
return (String)method.invoke(null);
}
finally {
loader.dispose();
return (String) method.invoke(null);
} finally {
loader.dispose();
}
}
......@@ -128,8 +123,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
}
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
final AnalyzeExhaust analyzeExhaust =
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY);
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY);
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state;
......@@ -149,11 +143,9 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
try {
return createClassLoader(state).loadClass(fqName);
}
catch (ClassNotFoundException e) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
......@@ -162,10 +154,8 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected Class loadClass(String fqName, @NotNull ClassFileFactory state) {
try {
return createClassLoader(state).loadClass(fqName);
}
catch (ClassNotFoundException e) {
}
catch (MalformedURLException e) {
} catch (ClassNotFoundException e) {
} catch (MalformedURLException e) {
}
fail("No classfile was generated for: " + fqName);
......@@ -178,8 +168,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
ClassBuilderFactory classBuilderFactory = ClassBuilderFactories.binaries(false);
return generateCommon(classBuilderFactory).getFactory();
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
System.out.println(generateToText());
throw e;
}
......@@ -200,12 +189,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
r = method;
}
if (r == null) {
if (r == null)
throw new AssertionError();
}
return r;
}
catch (Error e) {
} catch (Error e) {
System.out.println(generateToText());
throw e;
}
......@@ -233,11 +220,11 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected static void assertIsCurrentTime(long returnValue) {
long currentTime = System.currentTimeMillis();
long diff = Math.abs(returnValue - currentTime);
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)",
diff <= 1L);
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", diff <= 1L);
}
protected Class loadImplementationClass(@NotNull ClassFileFactory codegens, final String name) {
return loadClass(name, codegens);
}
}
......@@ -35,9 +35,9 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.List;
import java.util.Map;
......@@ -139,13 +139,11 @@ public abstract class ExpectedResolveData {
JetStandardLibrary lib = JetStandardLibrary.getInstance();
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files,
Predicates.<PsiFile>alwaysTrue(),
JetControlFlowDataTraceFactory.EMPTY,
CompilerSpecialMode.REGULAR);
Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
BindingContext bindingContext = analyzeExhaust.getBindingContext();
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic;
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
unresolvedReferences.add(unresolvedReferenceDiagnostic.getPsiElement());
}
}
......@@ -176,35 +174,35 @@ public abstract class ExpectedResolveData {
JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class);
if ("!".equals(name)) {
assertTrue(
"Must have been unresolved: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
unresolvedReferences.contains(referenceExpression));
"Must have been unresolved: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
unresolvedReferences.contains(referenceExpression));
continue;
}
if ("!!".equals(name)) {
assertTrue(
"Must have been resolved to multiple descriptors: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null);
"Must have been resolved to multiple descriptors: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null);
continue;
}
else if ("!null".equals(name)) {
assertTrue(
"Must have been resolved to null: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(REFERENCE_TARGET, referenceExpression) == null
"Must have been resolved to null: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(REFERENCE_TARGET, referenceExpression) == null
);
continue;
}
else if ("!error".equals(name)) {
assertTrue(
"Must have been resolved to error: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression))
"Must have been resolved to error: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression))
);
continue;
}
......@@ -252,30 +250,30 @@ public abstract class ExpectedResolveData {
if (expected instanceof JetParameter || actual instanceof JetParameter) {
DeclarationDescriptor expectedDescriptor;
if (name.startsWith("$")) {
expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter)expected);
expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter) expected);
}
else {
expectedDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expected);
if (expectedDescriptor == null) {
expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement)expected);
expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement) expected);
}
}
DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference);
if (actualDescriptor instanceof VariableAsFunctionDescriptor) {
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor)actualDescriptor;
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor;
actualDescriptor = descriptor.getVariableDescriptor();
}
assertEquals(
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expectedDescriptor, actualDescriptor);
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expectedDescriptor, actualDescriptor);
}
else {
assertEquals(
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expected, actual);
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expected, actual);
}
}
......@@ -307,8 +305,7 @@ public abstract class ExpectedResolveData {
expectedTypeConstructor = classDescriptor.getTypeConstructor();
}
else if (declaration instanceof JetTypeParameter) {
TypeParameterDescriptor typeParameterDescriptor =
bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter)declaration);
TypeParameterDescriptor typeParameterDescriptor = bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter) declaration);
expectedTypeConstructor = typeParameterDescriptor.getTypeConstructor();
}
else {
......@@ -328,13 +325,14 @@ public abstract class ExpectedResolveData {
PsiElement parent = statement.getParent();
if (!(parent instanceof JetExpression)) break;
if (parent instanceof JetBlockExpression) break;
statement = (JetExpression)parent;
statement = (JetExpression) parent;
}
JetDeclaration declaration = PsiTreeUtil.getParentOfType(referenceExpression, JetDeclaration.class);
return referenceExpression.getText() + " at " + DiagnosticUtils.atLocation(referenceExpression) +
" in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText());
" in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText());
}
private static <T> T getAncestorOfType(Class<T> type, PsiElement element) {
......@@ -342,7 +340,7 @@ public abstract class ExpectedResolveData {
element = element.getParent();
}
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
T result = (T)element;
T result = (T) element;
return result;
}
}
......@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.JetType;
......@@ -66,7 +67,7 @@ public class JetSourceNavigationHelper {
}
final List<JetFile> libraryFiles = findAllSourceFilesWhichContainIdentifier(declaration);
for (JetFile libraryFile : libraryFiles) {
BindingContext bindingContext = AnalyzeSingleFileUtil.analyzeSingleFileWithCache(libraryFile).getBindingContext();
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile(libraryFile);
D descriptor = bindingContext.get(slice, fqName);
if (descriptor != null) {
return new Tuple2<BindingContext, D>(bindingContext, descriptor);
......
......@@ -22,6 +22,7 @@ import com.intellij.util.ArrayUtil;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
......@@ -29,13 +30,12 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lexer.JetLexer;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* User: Alefas
* Date: 31.01.12
......@@ -68,7 +68,7 @@ public class JetNameSuggester {
public static String[] suggestNames(JetExpression expression, JetNameValidator validator) {
ArrayList<String> result = new ArrayList<String>();
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)expression.getContainingFile());
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
if (jetType != null) {
addNamesForType(result, jetType, validator);
......
......@@ -37,17 +37,17 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.NamespaceType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import org.jetbrains.jet.plugin.refactoring.*;
import java.util.*;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* User: Alefas
* Date: 25.01.12
......@@ -99,7 +99,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
return;
}
}
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)expression.getContainingFile());
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
if (expressionType instanceof NamespaceType) {
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression"));
......@@ -370,7 +370,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
final ArrayList<JetExpression> result = new ArrayList<JetExpression>();
final BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
final BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)expression.getContainingFile());
JetVisitorVoid visitor = new JetVisitorVoid() {
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册