Merge branch 'master' of github.com:JetBrains/kotlin

This commit is contained in:
James Strachan
2012-04-19 14:53:12 +01:00
60 changed files with 891 additions and 140 deletions
@@ -62,11 +62,13 @@ public class CompilationException extends RuntimeException {
private String where() {
Throwable cause = getCause();
if (cause != null && cause.getStackTrace().length > 0) {
return cause.getStackTrace()[0].getFileName() + ":" + cause.getStackTrace()[0].getLineNumber();
Throwable throwable = cause != null ? cause : this;
StackTraceElement[] stackTrace = throwable.getStackTrace();
if (stackTrace != null && stackTrace.length > 0) {
return stackTrace[0].getFileName() + ":" + stackTrace[0].getLineNumber();
}
else {
return "far away in cyberspace";
return "unknown";
}
}
@@ -71,6 +71,8 @@ public class KotlinToJVMBytecodeCompiler {
return null;
}
exhaust.throwIfError();
return generate(environment, dependencies, messageCollector, exhaust, stubs);
}
@@ -96,7 +96,8 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
injector.getTopDownAnalyzer().analyzeFiles(files);
return new AnalyzeExhaust(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
}
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files,
@@ -76,6 +76,7 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.NamespaceFactory;
@@ -92,6 +93,7 @@ import org.jetbrains.jet.lang.resolve.constants.NullValue;
import org.jetbrains.jet.lang.resolve.constants.ShortValue;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -103,6 +105,7 @@ import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
import org.jetbrains.jet.rt.signature.JetSignatureReader;
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
import org.jetbrains.jet.util.lazy.LazyValue;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -330,7 +333,15 @@ public class JavaDescriptorResolver {
@Nullable
public ClassDescriptor resolveClass(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule) {
List<Runnable> tasks = Lists.newArrayList();
ClassDescriptor clazz = resolveClass(qualifiedName, searchRule, tasks);
for (Runnable task : tasks) {
task.run();
}
return clazz;
}
private ClassDescriptor resolveClass(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule, @NotNull List<Runnable> tasks) {
if (qualifiedName.getFqName().endsWith(JvmAbi.TRAIT_IMPL_SUFFIX)) {
// TODO: only if -$$TImpl class is created by Kotlin
return null;
@@ -365,12 +376,12 @@ public class JavaDescriptorResolver {
if (psiClass == null) {
return null;
}
classData = createJavaClassDescriptor(psiClass);
classData = createJavaClassDescriptor(psiClass, tasks);
}
return classData.getClassDescriptor();
}
private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass) {
private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass, List<Runnable> taskList) {
FqName fqName = new FqName(psiClass.getQualifiedName());
if (classDescriptorCache.containsKey(fqName)) {
throw new IllegalStateException(psiClass.getQualifiedName());
@@ -384,7 +395,7 @@ public class JavaDescriptorResolver {
ResolverBinaryClassData classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind));
classDescriptorCache.put(fqName, classData);
classData.classDescriptor.setName(name);
classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass));
classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass, taskList));
List<JetType> supertypes = new ArrayList<JetType>();
@@ -1596,11 +1607,11 @@ public class JavaDescriptorResolver {
return (FunctionDescriptorImpl) substitutedFunctionDescriptor;
}
private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner) {
private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner, @NotNull List<Runnable> tasks) {
PsiAnnotation[] psiAnnotations = owner.getModifierList().getAnnotations();
List<AnnotationDescriptor> r = Lists.newArrayListWithCapacity(psiAnnotations.length);
for (PsiAnnotation psiAnnotation : psiAnnotations) {
AnnotationDescriptor annotation = resolveAnnotation(psiAnnotation);
AnnotationDescriptor annotation = resolveAnnotation(psiAnnotation, tasks);
if (annotation != null) {
r.add(annotation);
}
@@ -1608,9 +1619,18 @@ public class JavaDescriptorResolver {
return r;
}
private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner) {
List<Runnable> tasks = Lists.newArrayList();
List<AnnotationDescriptor> annotations = resolveAnnotations(owner, tasks);
for (Runnable task : tasks) {
task.run();
}
return annotations;
}
@Nullable
private AnnotationDescriptor resolveAnnotation(PsiAnnotation psiAnnotation) {
AnnotationDescriptor annotation = new AnnotationDescriptor();
private AnnotationDescriptor resolveAnnotation(PsiAnnotation psiAnnotation, @NotNull List<Runnable> taskList) {
final AnnotationDescriptor annotation = new AnnotationDescriptor();
String qname = psiAnnotation.getQualifiedName();
if (qname.startsWith("java.lang.annotation.") || qname.startsWith("jet.runtime.typeinfo.") || qname.equals(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName())) {
@@ -1618,11 +1638,16 @@ public class JavaDescriptorResolver {
return null;
}
ClassDescriptor clazz = resolveClass(new FqName(psiAnnotation.getQualifiedName()), DescriptorSearchRule.INCLUDE_KOTLIN);
final ClassDescriptor clazz = resolveClass(new FqName(psiAnnotation.getQualifiedName()), DescriptorSearchRule.INCLUDE_KOTLIN, taskList);
if (clazz == null) {
return null;
}
annotation.setAnnotationType(clazz.getDefaultType());
taskList.add(new Runnable() {
@Override
public void run() {
annotation.setAnnotationType(clazz.getDefaultType());
}
});
ArrayList<CompileTimeConstant<?>> valueArguments = new ArrayList<CompileTimeConstant<?>>();
PsiAnnotationParameterList parameterList = psiAnnotation.getParameterList();
@@ -162,7 +162,9 @@ public class JavaTypeTransformer {
PsiType[] psiArguments = classType.getParameters();
if (parameters.size() != psiArguments.length) {
throw new IllegalStateException();
throw new IllegalStateException(
"parameters = " + parameters.size() + ", actual arguments = " + psiArguments.length
+ " in " + classType.getPresentableText());
}
for (int i = 0; i < parameters.size(); i++) {
@@ -87,7 +87,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
if (result != null) {
FqName actualQualifiedName = new FqName(result.getQualifiedName());
if (!actualQualifiedName.equals(qualifiedName)) {
// throw new IllegalStateException("requested " + qualifiedName + ", got " + actualQualifiedName);
throw new IllegalStateException("requested " + qualifiedName + ", got " + actualQualifiedName);
}
}
@@ -27,12 +27,22 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
public class AnalyzeExhaust {
@NotNull
private final BindingContext bindingContext;
@Nullable
private final JetStandardLibrary standardLibrary;
private final Throwable error;
public AnalyzeExhaust(@NotNull BindingContext bindingContext, @Nullable JetStandardLibrary standardLibrary) {
private AnalyzeExhaust(@NotNull BindingContext bindingContext,
@Nullable JetStandardLibrary standardLibrary, @Nullable Throwable error) {
this.bindingContext = bindingContext;
this.standardLibrary = standardLibrary;
this.error = error;
}
public static AnalyzeExhaust success(@NotNull BindingContext bindingContext, @NotNull JetStandardLibrary standardLibrary) {
return new AnalyzeExhaust(bindingContext, standardLibrary, null);
}
public static AnalyzeExhaust error(@NotNull BindingContext bindingContext, @NotNull Throwable error) {
return new AnalyzeExhaust(bindingContext, null, error);
}
@NotNull
@@ -40,8 +50,23 @@ public class AnalyzeExhaust {
return bindingContext;
}
@Nullable
@NotNull
public JetStandardLibrary getStandardLibrary() {
return standardLibrary;
}
@NotNull
public Throwable getError() {
return error;
}
public boolean isError() {
return error != null;
}
public void throwIfError() {
if (isError()) {
throw new IllegalStateException("failed to analyze: " + error, error);
}
}
}
@@ -42,7 +42,7 @@ public class AnnotationDescriptor {
}
public void setAnnotationType(@NotNull JetType annotationType) {
if (!(annotationType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
if (false && !(annotationType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
throw new IllegalStateException();
}
this.annotationType = annotationType;
@@ -156,11 +156,12 @@ public interface Errors {
DiagnosticFactory<JetDelegatorByExpressionSpecifier> BY_IN_SECONDARY_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
DiagnosticFactory<JetDelegatorToSuperClass> INITIALIZER_WITH_NO_ARGUMENTS = DiagnosticFactory.create(ERROR, "Constructor arguments required");
DiagnosticFactory<JetDelegationSpecifier> MANY_CALLS_TO_THIS = DiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
DiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = DiagnosticFactory1.create(ERROR, "{0} overrides nothing", PositioningStrategies.positionModifier(JetTokens.OVERRIDE_KEYWORD), DescriptorRenderer.TEXT);
DiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = DiagnosticFactory1.create(ERROR, "{0} overrides nothing", PositioningStrategies.POSITION_OVERRIDE_MODIFIER, DescriptorRenderer.TEXT);
DiagnosticFactory3<PsiNameIdentifierOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN =
DiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", PositioningStrategies.POSITION_NAME_IDENTIFIER, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
DiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableDescriptor, DeclarationDescriptor> CANNOT_OVERRIDE_INVISIBLE_MEMBER =
DiagnosticFactory3.create(ERROR, "''{0}'' cannot has no access to ''{1}'' in class {2}, so it cannot override it", PositioningStrategies.positionModifier(JetTokens.OVERRIDE_KEYWORD), DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
DiagnosticFactory3.create(ERROR, "''{0}'' cannot has no access to ''{1}'' in class {2}, so it cannot override it", PositioningStrategies.POSITION_OVERRIDE_MODIFIER, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
DiagnosticFactory<JetModifierListOwner> CANNOT_INFER_VISIBILITY = DiagnosticFactory.create(ERROR, "Cannot infer visibility. Please specify it explicitly", PositioningStrategies.POSITION_OVERRIDE_MODIFIER);
DiagnosticFactory1<JetClass, ClassDescriptor> ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, "Missing delegation specifier ''{0}''", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
DiagnosticFactory1<JetTypeReference, ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR, "The type constructor of enum entry should be ''{0}''", NAME);
@@ -380,6 +381,8 @@ public interface Errors {
}
}, TO_STRING, TO_STRING);
DiagnosticFactory2<JetBinaryExpression, JetBinaryExpression, Boolean> SENSELESS_COMPARISON = DiagnosticFactory2.create(WARNING, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING);
DiagnosticFactory2<PsiElement, CallableMemberDescriptor, DeclarationDescriptor> OVERRIDING_FINAL_MEMBER = DiagnosticFactory2.create(ERROR, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME);
DiagnosticFactory3<JetModifierListOwner, Visibility, CallableMemberDescriptor, DeclarationDescriptor> CANNOT_WEAKEN_ACCESS_PRIVILEGE = DiagnosticFactory3.create(ERROR, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", PositioningStrategies.POSITION_VISIBILITY_MODIFIER, TO_STRING, NAME, NAME);
DiagnosticFactory3<JetModifierListOwner, Visibility, CallableMemberDescriptor, DeclarationDescriptor> CANNOT_CHANGE_ACCESS_PRIVILEGE = DiagnosticFactory3.create(ERROR, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", PositioningStrategies.POSITION_VISIBILITY_MODIFIER, TO_STRING, NAME, NAME);
@@ -88,6 +88,8 @@ public class PositioningStrategies {
public static final PositioningStrategy<JetModifierListOwner> POSITION_ABSTRACT_MODIFIER = positionModifier(JetTokens.ABSTRACT_KEYWORD);
public static final PositioningStrategy<JetModifierListOwner> POSITION_OVERRIDE_MODIFIER = positionModifier(JetTokens.OVERRIDE_KEYWORD);
public static PositioningStrategy<JetModifierListOwner> positionModifier(final JetKeywordToken token) {
return new PositioningStrategy<JetModifierListOwner>() {
@NotNull
@@ -1128,27 +1128,20 @@ public class JetExpressionParsing extends AbstractJetParsing {
// {(a, b) -> ...}
{
PsiBuilder.Marker rollbackMarker = mark();
boolean preferParamsToExpressions = isConfirmedParametersByComma();
PsiBuilder.Marker rollbackMarker = mark();
parseFunctionLiteralParametersAndType();
paramsFound = rollbackOrDropAt(rollbackMarker, ARROW);
paramsFound = preferParamsToExpressions ?
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
rollbackOrDropAt(rollbackMarker, ARROW);
}
if (!paramsFound) {
// If not found, try a typeRef DOT and then LPAR .. RPAR ARROW
// {((A) -> B).(x) -> ... }
PsiBuilder.Marker rollbackMarker = mark();
int lastDot = matchTokenStreamPredicate(new LastBefore(new At(DOT), new AtSet(ARROW, RPAR)));
if (lastDot >= 0) {
createTruncatedBuilder(lastDot).parseTypeRef();
if (at(DOT)) {
advance(); // DOT
parseFunctionLiteralParametersAndType();
}
}
paramsFound = rollbackOrDropAt(rollbackMarker, ARROW);
paramsFound = parseFunctionTypeDotParametersAndType();
}
}
else {
@@ -1157,69 +1150,21 @@ public class JetExpressionParsing extends AbstractJetParsing {
// {a -> ...}
// {a, b -> ...}
PsiBuilder.Marker rollbackMarker = mark();
boolean preferParamsToExpressions = (lookahead(1) == COMMA);
parseFunctionLiteralShorthandParameterList();
parseOptionalFunctionLiteralType();
paramsFound = rollbackOrDropAt(rollbackMarker, ARROW);
paramsFound = preferParamsToExpressions ?
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
rollbackOrDropAt(rollbackMarker, ARROW);
}
if (!paramsFound && atSet(JetParsing.TYPE_REF_FIRST)) {
// Try to parse a type DOT valueParameterList ARROW
// {A.(b) -> ...}
PsiBuilder.Marker rollbackMarker = mark();
int lastDot = matchTokenStreamPredicate(new LastBefore(new At(DOT), new AtSet(ARROW, RBRACE)));
if (lastDot >= 0) { // There is a receiver type
createTruncatedBuilder(lastDot).parseTypeRef();
}
if (at(DOT)) {
advance(); // DOT
parseFunctionLiteralParametersAndType();
paramsFound = rollbackOrDropAt(rollbackMarker, ARROW);
}
else {
rollbackMarker.rollbackTo();
}
paramsFound = parseFunctionTypeDotParametersAndType();
}
// int doubleArrowPos = matchTokenStreamPredicate(new FirstBefore(new At(ARROW), new At(RBRACE)) {
// @Override
// public boolean isTopLevel(int openAngleBrackets, int openBrackets, int openBraces, int openParentheses) {
// return openBraces == 0;
// }
// });
//
// boolean doubleArrowPresent = doubleArrowPos >= 0;
// if (doubleArrowPresent) {
// boolean dontExpectParameters = false;
//
// int lastDot = matchTokenStreamPredicate(new LastBefore(new At(DOT), new AtOffset(doubleArrowPos)));
// if (lastDot >= 0) { // There is a receiver type
// createTruncatedBuilder(lastDot).parseTypeRef();
//
// expect(DOT, "Expecting '.'");
//
// if (!at(LPAR)) {
// int firstLParPos = matchTokenStreamPredicate(new FirstBefore(new At(LPAR), new AtOffset(doubleArrowPos)));
//
// if (firstLParPos >= 0) {
// errorUntilOffset("Expecting '('", firstLParPos);
// } else {
// errorUntilOffset("To specify a receiver type, use the full notation: {ReceiverType.(parameters) [: ReturnType] -> ...}",
// doubleArrowPos);
// dontExpectParameters = true;
// }
// }
//
// }
//
// if (at(LPAR)) {
// parseFunctionLiteralParametersAndType();
// }
// else if (!dontExpectParameters) {
// parseFunctionLiteralShorthandParameterList();
// }
//
// expectNoAdvance(ARROW, "Expecting '->'");
// }
}
if (!paramsFound) {
if (preferBlock) {
literal.drop();
@@ -1231,6 +1176,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
return;
}
}
PsiBuilder.Marker body = mark();
parseStatements();
body.done(BLOCK);
@@ -1252,6 +1198,25 @@ public class JetExpressionParsing extends AbstractJetParsing {
return false;
}
private boolean rollbackOrDrop(PsiBuilder.Marker rollbackMarker,
JetToken expected, String expectMessage,
IElementType validForDrop) {
if (at(expected)) {
advance(); // dropAt
rollbackMarker.drop();
return true;
}
else if (at(validForDrop)) {
rollbackMarker.drop();
expect(expected, expectMessage);
return true;
}
rollbackMarker.rollbackTo();
return false;
}
/*
* SimpleName{,}
*/
@@ -1289,9 +1254,45 @@ public class JetExpressionParsing extends AbstractJetParsing {
parameterList.done(VALUE_PARAMETER_LIST);
}
// Check that position is followed by top level comma. It can't be expression and we want it be
// parsed as parameters in function literal
private boolean isConfirmedParametersByComma() {
assert _at(LPAR);
PsiBuilder.Marker lparMarker = mark();
advance(); // LPAR
int comma = matchTokenStreamPredicate(new FirstBefore(new At(COMMA), new AtSet(ARROW, RPAR)));
lparMarker.rollbackTo();
return comma > 0;
}
private boolean parseFunctionTypeDotParametersAndType() {
PsiBuilder.Marker rollbackMarker = mark();
// True when it's confirmed that body of literal can't be simple expressions and we prefer to parse
// it to function params if possible.
boolean preferParamsToExpressions = false;
int lastDot = matchTokenStreamPredicate(new LastBefore(new At(DOT), new AtSet(ARROW, RPAR)));
if (lastDot >= 0) {
createTruncatedBuilder(lastDot).parseTypeRef();
if (at(DOT)) {
advance(); // DOT
if (at(LPAR)) {
preferParamsToExpressions = isConfirmedParametersByComma();
}
parseFunctionLiteralParametersAndType();
}
}
return preferParamsToExpressions ?
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
rollbackOrDropAt(rollbackMarker, ARROW);
}
private void parseFunctionLiteralParametersAndType() {
parseFunctionLiteralParameterList();
parseOptionalFunctionLiteralType();
}
@@ -230,8 +230,7 @@ public class FqNameUnsafe {
if (isRoot()) {
return false;
}
List<String> pathSegments = pathSegments();
return pathSegments.get(pathSegments.size() - 1).equals(segment);
return shortName().equals(segment);
}
@@ -36,6 +36,7 @@ import javax.inject.Inject;
import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.DECLARATION_TO_DESCRIPTOR;
import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
/**
@@ -418,10 +419,10 @@ public class OverrideResolver {
private void resolveUnknownVisibilityForMembers(@NotNull Set<CallableMemberDescriptor> fakeOverrides) {
for (CallableMemberDescriptor override : fakeOverrides) {
resolveUnknownVisibilityForMember(override);
resolveUnknownVisibilityForMember(null, override);
}
for (CallableMemberDescriptor memberDescriptor : context.getMembers().values()) {
resolveUnknownVisibilityForMember(memberDescriptor);
for (Map.Entry<JetDeclaration, CallableMemberDescriptor> entry : context.getMembers().entrySet()) {
resolveUnknownVisibilityForMember(entry.getKey(), entry.getValue());
}
for (PropertyDescriptor propertyDescriptor : context.getProperties().values()) {
for (PropertyAccessorDescriptor accessor : propertyDescriptor.getAccessors()) {
@@ -432,13 +433,19 @@ public class OverrideResolver {
}
}
private void resolveUnknownVisibilityForMember(@NotNull CallableMemberDescriptor memberDescriptor) {
private void resolveUnknownVisibilityForMember(@Nullable JetDeclaration member, @NotNull CallableMemberDescriptor memberDescriptor) {
resolveUnknownVisibilityForOverriddenDescriptors(memberDescriptor.getOverriddenDescriptors());
if (memberDescriptor.getVisibility() != Visibilities.INHERITED) {
return;
}
Visibility visibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
if (visibility == null) {
if (member != null) {
trace.report(CANNOT_INFER_VISIBILITY.on(member));
}
visibility = Visibilities.PUBLIC;
}
if (memberDescriptor instanceof PropertyDescriptor) {
((PropertyDescriptor)memberDescriptor).setVisibility(visibility);
@@ -465,12 +472,14 @@ public class OverrideResolver {
private void resolveUnknownVisibilityForOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
for (CallableMemberDescriptor descriptor : descriptors) {
if (descriptor.getVisibility() == Visibilities.INHERITED) {
resolveUnknownVisibilityForMember(descriptor);
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
JetDeclaration declaration = (element instanceof JetDeclaration) ? (JetDeclaration) element : null;
resolveUnknownVisibilityForMember(declaration, descriptor);
}
}
}
@NotNull
@Nullable
private Visibility findMaxVisibility(@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
if (descriptors.isEmpty()) {
return Visibilities.INTERNAL;
@@ -483,16 +492,23 @@ public class OverrideResolver {
maxVisibility = visibility;
continue;
}
Integer compare = Visibilities.compare(visibility, maxVisibility);
if (compare == null) {
maxVisibility = Visibilities.PUBLIC; //todo error or warning when inference only from incomparable visibilities
continue;
Integer compareResult = Visibilities.compare(visibility, maxVisibility);
if (compareResult == null) {
maxVisibility = null;
}
if (compare > 0) {
else if (compareResult > 0) {
maxVisibility = visibility;
}
}
assert maxVisibility != null;
if (maxVisibility == null) {
return null;
}
for (CallableMemberDescriptor descriptor : descriptors) {
Integer compareResult = Visibilities.compare(maxVisibility, descriptor.getVisibility());
if (compareResult == null || compareResult < 0) {
return null;
}
}
return maxVisibility;
}
@@ -950,9 +950,16 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(EQUALITY_NOT_APPLICABLE.on(expression, operationSign, leftType, rightType));
}
}
if (isSenselessComparisonWithNull(leftType, right) || isSenselessComparisonWithNull(rightType, left)) {
context.trace.report(SENSELESS_COMPARISON.on(expression, expression, operationSign.getReferencedNameElementType() == JetTokens.EXCLEQ));
}
}
}
private boolean isSenselessComparisonWithNull(JetType firstType, JetExpression secondExpression) {
return !firstType.isNullable() && secondExpression instanceof JetConstantExpression && secondExpression.getNode().getElementType() == JetNodeTypes.NULL;
}
protected JetType visitAssignmentOperation(JetBinaryExpression expression, ExpressionTypingContext context) {
return assignmentIsNotAnExpressionError(expression, context);
}
@@ -165,6 +165,10 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
// TODO: wrong environment // stepan.koltsov@ 2012-04-09
CompilerSpecialMode.REGULAR, CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR));
if (context.isError()) {
throw new IllegalStateException("failed to analyze: " + context.getError(), context.getError());
}
final GenerationState state = new GenerationState(project, builderFactory, context, Collections.singletonList(file)) {
@Override
protected void generateNamespace(JetFile namespace) {
@@ -0,0 +1,14 @@
//KT-1680 Warn if non-null variable is compared to null
package kt1680
fun foo() {
val x = 1
if (<!SENSELESS_COMPARISON!>x != null<!>) {} // <-- need a warning here!
if (<!SENSELESS_COMPARISON!>x == null<!>) {}
if (<!SENSELESS_COMPARISON!>null != x<!>) {}
if (<!SENSELESS_COMPARISON!>null == x<!>) {}
val y : Int? = 1
if (y != null) {}
if (y == null) {}
}
@@ -36,5 +36,5 @@ class F : C(), T {
}
class G : C(), T {
override fun foo() {}
public override fun foo() {}
}
@@ -0,0 +1,30 @@
//KT-1822 Error 'cannot infer visibility' required
package kt1822
open class C {
internal open fun foo() {}
}
trait T {
protected fun foo() {}
}
class G : C(), T {
<!CANNOT_INFER_VISIBILITY!>override<!> fun foo() {} //should be an error "cannot infer visibility"; for now 'public' is inferred in such cases
}
open class A {
internal open fun foo() {}
}
trait B {
protected fun foo() {}
}
trait D {
public fun foo() {}
}
class E : A(), B, D {
override fun foo() {}
}
@@ -15,4 +15,8 @@ fun foo() {
{a : b -> f}
{T.a : b -> f}
{(a, b) }
{T.(a, b) }
{a, }
}
+63 -4
View File
@@ -326,7 +326,66 @@ JetFile: FunctionLiterals_ERR.jet
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('f')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiErrorElement:Expecting '}'
<empty list>
PsiWhiteSpace('\n\n ')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('b')
PsiElement(RPAR)(')')
PsiErrorElement:An -> is expected
<empty list>
PsiWhiteSpace(' ')
BLOCK
<empty list>
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('b')
PsiElement(RPAR)(')')
PsiErrorElement:An -> is expected
<empty list>
PsiWhiteSpace(' ')
BLOCK
<empty list>
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiErrorElement:Expecting parameter name
PsiElement(RBRACE)('}')
PsiErrorElement:Expecting '->' or ','
<empty list>
PsiWhiteSpace('\n')
BLOCK
<empty list>
PsiElement(RBRACE)('}')
PsiErrorElement:Expecting '}'
<empty list>
@@ -0,0 +1,12 @@
package test;
interface Trait<P> {
}
class Outer<P, Q> {
class Inner {
}
class Inner2 extends Inner implements Trait<P> {
}
}
@@ -0,0 +1,11 @@
package test
trait Trait<erased P>
open class Outer<erased P, erased Q>() {
open class Inner() {
}
open class Inner2() : Inner(), Trait<P> {
}
}
@@ -0,0 +1,13 @@
namespace test
open class test.Outer</*0*/ P : jet.Any?, /*1*/ Q : jet.Any?> : jet.Any {
final /*constructor*/ fun </*0*/ P : jet.Any?, /*1*/ Q : jet.Any?><init>(): test.Outer<P, Q>
open class test.Outer.Inner : jet.Any {
final /*constructor*/ fun <init>(): test.Outer.Inner
}
open class test.Outer.Inner2 : test.Outer.Inner, test.Trait<P> {
final /*constructor*/ fun <init>(): test.Outer.Inner2
}
}
abstract trait test.Trait</*0*/ P : jet.Any?> : jet.Any {
}
@@ -0,0 +1,6 @@
package test;
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)
@AnnotatedAnnotation
@interface AnnotatedAnnotation {
}
@@ -0,0 +1,4 @@
package test
[AnnotatedAnnotation]
annotation class AnnotatedAnnotation
@@ -0,0 +1,5 @@
namespace test
test.AnnotatedAnnotation() final annotation class test.AnnotatedAnnotation : jet.Any {
final /*constructor*/ fun <init>(): test.AnnotatedAnnotation
}
@@ -0,0 +1,7 @@
package test
class Outer() {
open class Inner1()
class Inner2() : Inner1()
}
@@ -0,0 +1,11 @@
namespace test
final class test.Outer : jet.Any {
final /*constructor*/ fun <init>(): test.Outer
open class test.Outer.Inner1 : jet.Any {
final /*constructor*/ fun <init>(): test.Outer.Inner1
}
final class test.Outer.Inner2 : test.Outer.Inner1 {
final /*constructor*/ fun <init>(): test.Outer.Inner2
}
}
@@ -163,9 +163,12 @@ public class JetTestUtils {
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR));
}
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
JetCoreEnvironment environment = new JetCoreEnvironment(disposable, CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR));
return createEnvironmentWithMockJdk(disposable, CompilerSpecialMode.REGULAR);
}
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable, @NotNull CompilerSpecialMode compilerSpecialMode) {
JetCoreEnvironment environment = new JetCoreEnvironment(disposable, CompileCompilerDependenciesTest.compilerDependenciesForTests(compilerSpecialMode));
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
environment.addToClasspath(rtJar);
environment.addToClasspath(getAnnotationsJar());
@@ -0,0 +1,27 @@
/*
* 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;
/**
* @author Stepan Koltsov
*/
public class TimeUtils {
public static String millisecondsToSecondsString(long millis) {
return millis / 1000 + "." + String.format("%03d", millis % 1000);
}
}
@@ -128,6 +128,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
myFile, JetControlFlowDataTraceFactory.EMPTY,
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR));
analyzeExhaust.throwIfError();
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state;
@@ -31,14 +31,15 @@ import java.util.Collections;
*/
public class GenerationUtils {
public static ClassFileFactory compileFileGetClassFileFactoryForTest(@NotNull JetFile psiFile) {
return compileFileGetGenerationStateForTest(psiFile).getFactory();
public static ClassFileFactory compileFileGetClassFileFactoryForTest(@NotNull JetFile psiFile, @NotNull CompilerSpecialMode compilerSpecialMode) {
return compileFileGetGenerationStateForTest(psiFile, compilerSpecialMode).getFactory();
}
public static GenerationState compileFileGetGenerationStateForTest(JetFile psiFile) {
public static GenerationState compileFileGetGenerationStateForTest(JetFile psiFile, @NotNull CompilerSpecialMode compilerSpecialMode) {
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
psiFile, JetControlFlowDataTraceFactory.EMPTY,
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR));
CompileCompilerDependenciesTest.compilerDependenciesForTests(compilerSpecialMode));
analyzeExhaust.throwIfError();
GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust, Collections.singletonList(psiFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state;
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TimeUtils;
import java.io.File;
import java.io.FileOutputStream;
@@ -40,6 +41,8 @@ abstract class ForTestCompileSomething {
private File jarFile;
ForTestCompileSomething(@NotNull String jarName) {
System.out.println("Compiling " + jarName + "...");
long start = System.currentTimeMillis();
this.jarName = jarName;
try {
File tmpDir = JetTestUtils.tmpDir("runtimejar");
@@ -67,6 +70,8 @@ abstract class ForTestCompileSomething {
}
FileUtil.delete(classesDir);
long end = System.currentTimeMillis();
System.out.println("Compiling " + jarName + " done in " + TimeUtils.millisecondsToSecondsString(end - start) + "s");
} catch (Throwable e) {
error = e;
}
@@ -28,6 +28,7 @@ import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.plugin.JetLanguage;
import org.junit.Assert;
@@ -75,7 +76,7 @@ public class CompileJavaAgainstKotlinTest extends TestCaseWithTmpdir {
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, CompilerSpecialMode.REGULAR);
CompileEnvironmentUtil.writeToOutputDirectory(classFileFactory, tmpdir.getPath());
@@ -29,6 +29,7 @@ import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.plugin.JetLanguage;
import java.io.File;
@@ -89,7 +90,7 @@ public class CompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, CompilerSpecialMode.REGULAR);
CompileEnvironmentUtil.writeToOutputDirectory(classFileFactory, aDir.getPath());
@@ -107,7 +108,7 @@ public class CompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, CompilerSpecialMode.REGULAR);
CompileEnvironmentUtil.writeToOutputDirectory(classFileFactory, bDir.getPath());
@@ -76,7 +76,7 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
}
private NamespaceDescriptor compileKotlin() throws Exception {
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable, CompilerSpecialMode.JDK_HEADERS);
String text = FileUtil.loadFile(ktFile);
@@ -86,7 +86,7 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
psiFile, JetControlFlowDataTraceFactory.EMPTY,
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR))
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS))
.getBindingContext();
return bindingContext.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, FqName.topLevel("test"));
}
@@ -108,13 +108,13 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
fileManager.close();
}
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable, CompilerSpecialMode.JDK_HEADERS);
jetCoreEnvironment.addToClasspath(tmpdir);
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR), jetCoreEnvironment.getProject());
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS), jetCoreEnvironment.getProject());
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
return javaDescriptorResolver.resolveNamespace(FqName.topLevel("test"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
}
@@ -63,7 +63,7 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
@Override
public void runTest() throws Exception {
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable, CompilerSpecialMode.JDK_HEADERS);
String text = FileUtil.loadFile(testFile);
@@ -71,7 +71,7 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
GenerationState state = GenerationUtils.compileFileGetGenerationStateForTest(psiFile);
GenerationState state = GenerationUtils.compileFileGetGenerationStateForTest(psiFile, CompilerSpecialMode.JDK_HEADERS);
ClassFileFactory classFileFactory = state.getFactory();
@@ -84,13 +84,13 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
Disposer.dispose(myTestRootDisposable);
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable, CompilerSpecialMode.JDK_HEADERS);
jetCoreEnvironment.addToClasspath(tmpdir);
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR), jetCoreEnvironment.getProject());
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS), jetCoreEnvironment.getProject());
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace(FqName.topLevel("test"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
@@ -31,6 +31,7 @@ import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.plugin.JetLanguage;
import org.junit.Assert;
@@ -80,7 +81,7 @@ public class WriteSignatureTest extends TestCaseWithTmpdir {
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
ClassFileFactory classFileFactory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, CompilerSpecialMode.REGULAR);
CompileEnvironmentUtil.writeToOutputDirectory(classFileFactory, tmpdir.getPath());
@@ -0,0 +1,57 @@
/*
* 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.compiler.longTest;
import org.jetbrains.annotations.NotNull;
/**
* @author Stepan Koltsov
*/
public class LibFromMaven {
@NotNull
private final String org;
@NotNull
private final String module;
@NotNull
private final String rev;
public LibFromMaven(@NotNull String org, @NotNull String module, @NotNull String rev) {
this.org = org;
this.module = module;
this.rev = rev;
}
@NotNull
public String getOrg() {
return org;
}
@NotNull
public String getModule() {
return module;
}
@NotNull
public String getRev() {
return rev;
}
@Override
public String toString() {
return org + "/" + module + "/" + rev;
}
}
@@ -0,0 +1,199 @@
/*
* 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.compiler.longTest;
import com.google.common.io.ByteStreams;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.CompileCompilerDependenciesTest;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TimeUtils;
import org.jetbrains.jet.compiler.JetCoreEnvironment;
import org.jetbrains.jet.di.InjectorForJavaSemanticServices;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @author Stepan Koltsov
*/
public class ResolveDescriptorsFromExternalLibraries {
@NotNull
private final CompilerDependencies compilerDependencies;
public static void main(String[] args) throws Exception {
new ResolveDescriptorsFromExternalLibraries().run();
System.out.println("$");
}
public ResolveDescriptorsFromExternalLibraries() {
System.out.println("Getting compiler dependencies");
compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR);
}
private void run() throws Exception {
testLibrary("com.google.guava", "guava", "12.0-rc2");
testLibrary("org.springframework", "spring-core", "3.1.1.RELEASE");
}
private void testLibrary(@NotNull String org, @NotNull String module, @NotNull String rev) throws Exception {
LibFromMaven lib = new LibFromMaven(org, module, rev);
File jar = getLibrary(lib);
System.out.println("Testing library " + lib + "...");
System.out.println("Using file " + jar);
long start = System.currentTimeMillis();
Disposable junk = new Disposable() {
@Override
public void dispose() { }
};
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(junk);
jetCoreEnvironment.addToClasspath(jar);
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(compilerDependencies, jetCoreEnvironment.getProject());
FileInputStream is = new FileInputStream(jar);
try {
ZipInputStream zip = new ZipInputStream(is);
for (;;) {
ZipEntry entry = zip.getNextEntry();
if (entry == null) {
break;
}
String entryName = entry.getName();
if (!entryName.endsWith(".class")) {
continue;
}
if (entryName.matches("(.*/|)package-info\\.class")) {
continue;
}
if (entryName.contains("$")) {
continue;
}
String className = entryName.substring(0, entryName.length() - ".class".length()).replace("/", ".");
ClassDescriptor clazz = injector.getJavaDescriptorResolver().resolveClass(new FqName(className), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
if (clazz == null) {
throw new IllegalStateException("class not found by name " + className + " in " + lib);
}
clazz.getDefaultType().getMemberScope().getAllDescriptors();
}
} finally {
try {
is.close();
}
catch (Throwable e) {}
Disposer.dispose(junk);
}
System.out.println("Testing library " + lib + " done in " + TimeUtils.millisecondsToSecondsString(System.currentTimeMillis() - start) + "s");
}
@NotNull
private File getLibrary(@NotNull LibFromMaven lib) throws Exception {
File userHome = new File(System.getProperty("user.home"));
String fileName = lib.getModule() + "-" + lib.getRev() + ".jar";
File dir = new File(userHome, ".kotlin-project/resolve-libraries/" + lib.getOrg() + "/" + lib.getModule());
File file = new File(dir, fileName);
if (file.exists()) {
return file;
}
JetTestUtils.mkdirs(dir);
File tmp = new File(dir, fileName + "~");
String uri = url(lib);
GetMethod method = new GetMethod(uri);
FileOutputStream os = null;
System.out.println("Downloading library " + lib + " to " + file);
MultiThreadedHttpConnectionManager connectionManager = null;
try {
connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);
os = new FileOutputStream(tmp);
String userAgent = ResolveDescriptorsFromExternalLibraries.class.getName() + "/commons-httpclient";
method.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
int code = httpClient.executeMethod(method);
if (code != 200) {
throw new RuntimeException("failed to execute GET " + uri + ", code is " + code);
}
InputStream responseBodyAsStream = method.getResponseBodyAsStream();
if (responseBodyAsStream == null) {
throw new RuntimeException("method is executed fine, but response is null");
}
ByteStreams.copy(responseBodyAsStream, os);
os.close();
if (!tmp.renameTo(file)) {
throw new RuntimeException("failed to rename file: " + tmp + " to " + file);
}
return file;
}
finally {
if (method != null) {
try {
method.releaseConnection();
}
catch (Throwable e) {}
}
if (connectionManager != null) {
try {
connectionManager.shutdown();
}
catch (Throwable e) {}
}
if (os != null) {
try {
os.close();
}
catch (Throwable e) {}
}
tmp.delete();
}
}
private static String url(LibFromMaven lib) {
return "http://repo1.maven.org/maven2/" + lib.getOrg().replace(".", "/") + "/" + lib.getModule() + "/" + lib.getRev()
+ "/" + lib.getModule() + "-" + lib.getRev() + ".jar";
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

+3 -2
View File
@@ -56,7 +56,7 @@
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
<errorHandler implementation="org.jetbrains.jet.plugin.reporter.KotlinReportSubmitter"/>
<internalFileTemplate name="Kotlin File"/>
<internalFileTemplate name="Kotlin Class"/>
@@ -109,6 +109,7 @@
<completion.contributor language="jet" implementationClass="org.jetbrains.jet.plugin.liveTemplates.JetLiveTemplateCompletionContributor" id="liveTemplates" order="first"/>
<completion.confidence language="jet" implementationClass="com.intellij.codeInsight.completion.UnfocusedNameIdentifier"/>
<completion.confidence language="jet" implementationClass="org.jetbrains.jet.plugin.completion.confidence.UnfocusedPossibleFunctionParameter"/>
<completion.confidence language="jet" implementationClass="com.intellij.codeInsight.completion.AlwaysFocusLookup" order="last"/>
<completion.skip implementation="org.jetbrains.jet.plugin.liveTemplates.JetLiveTemplateCompletionContributor$Skipper" id="skipLiveTemplate"/>
@@ -170,7 +171,7 @@
<toolWindow id="Kotlin"
factoryClass="org.jetbrains.jet.plugin.internal.KotlinInternalToolWindowFactory"
anchor="right"
icon="/org/jetbrains/jet/plugin/icons/kotlin16x16.png"
icon="/org/jetbrains/jet/plugin/icons/kotlin13x13.png"
/>
@@ -76,7 +76,8 @@ public final class JetDescriptorIconProvider {
return PlatformIcons.PACKAGE_OPEN_ICON;
}
if (descriptor instanceof FunctionDescriptor) {
return JetIcons.FUNCTION;
return descriptor.getContainingDeclaration() instanceof ClassDescriptor ?
PlatformIcons.METHOD_ICON : JetIcons.FUNCTION;
}
if (descriptor instanceof ClassDescriptor) {
switch (((ClassDescriptor)descriptor).getKind()) {
@@ -97,9 +98,20 @@ public final class JetDescriptorIconProvider {
return null;
}
}
if (descriptor instanceof ValueParameterDescriptor) {
return JetIcons.PARAMETER;
}
if (descriptor instanceof LocalVariableDescriptor) {
return ((LocalVariableDescriptor)descriptor).isVar() ? JetIcons.VAR : JetIcons.VAL;
}
if (descriptor instanceof PropertyDescriptor) {
return ((PropertyDescriptor)descriptor).isVar() ? JetIcons.VAR : JetIcons.VAL;
return ((PropertyDescriptor)descriptor).isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
}
if (descriptor instanceof TypeParameterDescriptor) {
return PlatformIcons.CLASS_ICON;
}
LOG.warn("No icon for descriptor: " + descriptor);
@@ -64,7 +64,7 @@ public class JetIconProvider extends IconProvider {
}
if (psiElement instanceof JetNamedFunction) {
return PsiTreeUtil.getParentOfType(psiElement, JetNamedDeclaration.class) instanceof JetClass
? JetIcons.LAMBDA
? PlatformIcons.METHOD_ICON
: JetIcons.FUNCTION;
}
if (psiElement instanceof JetClass) {
@@ -90,14 +90,14 @@ public class JetIconProvider extends IconProvider {
if (parameter.getValOrVarNode() != null) {
JetParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, JetParameterList.class);
if (parameterList != null && parameterList.getParent() instanceof JetClass) {
return parameter.isVarArg() ? JetIcons.VAR : JetIcons.VAL;
return parameter.isMutable() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
}
}
return JetIcons.PARAMETER;
}
if (psiElement instanceof JetProperty) {
JetProperty property = (JetProperty)psiElement;
return property.isVar() ? JetIcons.VAR : JetIcons.VAL;
return property.isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
}
return null;
}
@@ -34,4 +34,6 @@ public interface JetIcons {
Icon VAR = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/variable.png");
Icon VAL = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/value.png");
Icon PARAMETER = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/parameter.png");
Icon FIELD_VAL = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/field_value.png");
Icon FIELD_VAR = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/field_variable.png");
}
@@ -0,0 +1,76 @@
/*
* 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.plugin.completion.confidence;
import com.intellij.codeInsight.completion.CompletionConfidence;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
/**
* @author Nikolay Krasko
*/
public class UnfocusedPossibleFunctionParameter extends CompletionConfidence {
@NotNull
@Override
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
// 1. Do not automatically insert completion for first reference expression in block inside
// function literal if it has no parameters yet.
// 2. The same but for the case when first expression is additionally surrounded with brackets
PsiElement position = parameters.getPosition();
JetFunctionLiteralExpression functionLiteral = PsiTreeUtil.getParentOfType(
position, JetFunctionLiteralExpression.class);
if (functionLiteral != null) {
PsiElement expectedReference = position.getParent();
if (expectedReference instanceof JetSimpleNameExpression) {
if (PsiTreeUtil.findChildOfType(functionLiteral, JetParameterList.class) == null) {
{
// 1.
PsiElement expectedBlock = expectedReference.getParent();
if (expectedBlock instanceof JetBlockExpression) {
if (expectedReference.getPrevSibling() == null) {
return ThreeState.NO;
}
}
}
{
// 2.
PsiElement expectedParenthesized = expectedReference.getParent();
if (expectedParenthesized instanceof JetParenthesizedExpression) {
PsiElement expectedBlock = expectedParenthesized.getParent();
if (expectedBlock instanceof JetBlockExpression) {
if (expectedParenthesized.getPrevSibling() == null) {
return ThreeState.NO;
}
}
}
}
}
}
}
return ThreeState.UNSURE;
}
}
@@ -155,6 +155,7 @@ public class JetPositionManager implements PositionManager {
return mapper;
}
final AnalyzeExhaust analyzeExhaust = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
analyzeExhaust.throwIfError();
JetTypeMapper typeMapper = new InjectorForJetTypeMapper(
analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), Collections.singletonList(file)).getJetTypeMapper();
myTypeMappers.put(file, typeMapper);
@@ -206,13 +206,14 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
try {
AnalyzeExhaust binding = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
// AnalyzingUtils.throwExceptionOnErrors(binding);
if (binding.isError()) {
return printStackTraceToString(binding.getError());
}
state = new GenerationState(myProject, ClassBuilderFactories.TEXT, binding, Collections.singletonList(file));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
}
catch (Exception e) {
StringWriter out = new StringWriter(1024);
e.printStackTrace(new PrintWriter(out));
return out.toString().replaceAll("\r", "");
return printStackTraceToString(e);
}
@@ -229,6 +230,11 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
return answer.toString();
}
private static String printStackTraceToString(Throwable e) {StringWriter out = new StringWriter(1024);
e.printStackTrace(new PrintWriter(out));
return out.toString().replace("\r", "");
}
@Override
public void dispose() {
EditorFactory.getInstance().releaseEditor(myEditor);
@@ -96,7 +96,7 @@ public final class AnalyzerFacadeWithCache {
private Result<AnalyzeExhaust> emptyExhaustWithDiagnosticOnFile(Throwable e) {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e));
AnalyzeExhaust analyzeExhaust = new AnalyzeExhaust(bindingTraceContext.getBindingContext(), null);
AnalyzeExhaust analyzeExhaust = AnalyzeExhaust.error(bindingTraceContext.getBindingContext(), e);
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
}
}, false);
@@ -47,6 +47,6 @@ public enum JSAnalyzerFacadeForIDEA implements AnalyzerFacade {
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
BindingContext context = AnalyzerFacadeForJS.analyzeFiles(files, new IDEAConfig(project));
return new AnalyzeExhaust(context, JetStandardLibrary.getInstance());
return AnalyzeExhaust.success(context, JetStandardLibrary.getInstance());
}
}
}
@@ -0,0 +1,49 @@
/*
* 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.plugin.reporter;
import com.intellij.diagnostic.ITNReporter;
import com.intellij.openapi.diagnostic.ErrorReportSubmitter;
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
import com.intellij.openapi.diagnostic.SubmittedReportInfo;
import java.awt.*;
/**
* We need to wrap ITNReporter into this delegating class to work around the following problem:
*
* Kotlin's lifecycle does not align with the one of IDEA, so every now and then we are in the situation when users
* install an unstable build of Kotlin on a released build of IDEA. Since IDEA does not show exceptions from ITNReporter
* in release build, the user doesn't see exceptions from Kotlin in such a situations. Wrapping solves this problem:
* even release builds of IDEA will report Kotlin exceptions to the user (and allow to submit them to Exception Analyzer).
*
* @author abreslav
*/
public class KotlinReportSubmitter extends ErrorReportSubmitter {
private final ErrorReportSubmitter delegate = new ITNReporter();
@Override
public String getReportActionText() {
return delegate.getReportActionText();
}
@Override
public SubmittedReportInfo submit(IdeaLoggingEvent[] events, Component parentComponent) {
return delegate.submit(events, parentComponent);
}
}
@@ -0,0 +1,4 @@
fun main(args : Array<String>) {
val mmm = 12
val t = { <caret>}
}
@@ -0,0 +1,4 @@
fun main(args : Array<String>) {
val mmm = 12
val t = { mm }
}
@@ -0,0 +1,4 @@
fun main(args : Array<String>) {
val mmm = 12
val t = { (<caret>) }
}
@@ -0,0 +1,4 @@
fun main(args : Array<String>) {
val mmm = 12
val t = { (mm ) }
}
@@ -0,0 +1,4 @@
fun main(args : Array<String>) {
val mmm = 12
val t = { i -> <caret>}
}
@@ -0,0 +1,4 @@
fun main(args : Array<String>) {
val mmm = 12
val t = { i -> mmm }
}
@@ -16,6 +16,8 @@
package org.jetbrains.jet.completion.confidence;
import com.intellij.codeInsight.completion.CodeCompletionHandlerBase;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.LightCompletionTestCase;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.Sdk;
@@ -37,6 +39,18 @@ public class JetConfidenceTest extends LightCompletionTestCase {
doTest("pub");
}
public void testInBeginningOfFunctionLiteral() {
doTest("mm");
}
public void testInBeginningOfFunctionLiteralInBrackets() {
doTest("mm");
}
public void testInBlockOfFunctionLiteral() {
doTest("mm");
}
protected void doTest(String completionActivateType) {
configureByFile(getBeforeFileName());
type(completionActivateType + " ");
@@ -60,4 +74,9 @@ public class JetConfidenceTest extends LightCompletionTestCase {
protected Sdk getProjectJDK() {
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
}
@Override
protected void complete() {
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true, true).invokeCompletion(getProject(), getEditor(), 0, false);
}
}