ScriptCodeDescriptor
This commit is contained in:
@@ -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 JetType returnType;
|
||||||
private List<ValueParameterDescriptor> valueParameters;
|
private List<ValueParameterDescriptor> valueParameters;
|
||||||
|
|
||||||
|
private final ScriptCodeDescriptor scriptCodeDescriptor = new ScriptCodeDescriptor(this);
|
||||||
|
|
||||||
public ScriptDescriptor(@Nullable DeclarationDescriptor containingDeclaration) {
|
public ScriptDescriptor(@Nullable DeclarationDescriptor containingDeclaration) {
|
||||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), NAME);
|
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), NAME);
|
||||||
}
|
}
|
||||||
@@ -54,6 +56,11 @@ public class ScriptDescriptor extends DeclarationDescriptorImpl {
|
|||||||
return valueParameters;
|
return valueParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ScriptCodeDescriptor getScriptCodeDescriptor() {
|
||||||
|
return scriptCodeDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
|
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
|
||||||
throw new IllegalStateException("nothing to substitute in script");
|
throw new IllegalStateException("nothing to substitute in script");
|
||||||
|
|||||||
+8
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
|
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.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
@@ -193,6 +194,13 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
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");
|
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);
|
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);
|
||||||
|
|||||||
Reference in New Issue
Block a user