ScriptCodeDescriptor

This commit is contained in:
Stepan Koltsov
2012-06-05 22:56:23 +04:00
parent 0a14d9d2a5
commit 52234e96fd
3 changed files with 60 additions and 0 deletions
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2012 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.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collections;
/**
* @author Stepan Koltsov
*/
public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
public ScriptCodeDescriptor(@NotNull ScriptDescriptor containingDeclaration) {
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), Name.special("<script-code>"), Kind.DECLARATION);
setVisibility(Visibilities.LOCAL);
}
@Override
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
throw new IllegalStateException("no need to copy script code descriptor");
}
@NotNull
@Override
public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, boolean makeInvisible, Kind kind, boolean copyOverrides) {
throw new IllegalStateException("no need to copy script code descriptor");
}
}
@@ -35,6 +35,8 @@ public class ScriptDescriptor extends DeclarationDescriptorImpl {
private JetType returnType;
private List<ValueParameterDescriptor> valueParameters;
private final ScriptCodeDescriptor scriptCodeDescriptor = new ScriptCodeDescriptor(this);
public ScriptDescriptor(@Nullable DeclarationDescriptor containingDeclaration) {
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), NAME);
}
@@ -54,6 +56,11 @@ public class ScriptDescriptor extends DeclarationDescriptorImpl {
return valueParameters;
}
@NotNull
public ScriptCodeDescriptor getScriptCodeDescriptor() {
return scriptCodeDescriptor;
}
@Override
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
throw new IllegalStateException("nothing to substitute in script");
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
@@ -193,6 +194,13 @@ public class ExpressionTypingServices {
}
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
if (containingDescriptor instanceof ScriptDescriptor) {
if (!(expression.getParent() instanceof JetScript)) {
// top level script declarations should have ScriptDescriptor parent
// and lower level script declarations should be ScriptCodeDescriptor parent
containingDescriptor = ((ScriptDescriptor) containingDescriptor).getScriptCodeDescriptor();
}
}
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);