diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java index 5a25396bc63..8aba49d5f5e 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java @@ -92,7 +92,7 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer @NotNull @Override public List loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto) { - VirtualFile virtualFile = findVirtualFileByClass(descriptor); + VirtualFile virtualFile = findVirtualFileByDescriptor(descriptor); if (virtualFile == null) { // This means that the resource we're constructing the descriptor from is no longer present: VirtualFileFinder had found the // file earlier, but it can't now @@ -111,26 +111,16 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer @Nullable private VirtualFile findVirtualFileByDescriptor(@NotNull ClassOrNamespaceDescriptor descriptor) { if (descriptor instanceof ClassDescriptor) { - return findVirtualFileByClass((ClassDescriptor) descriptor); + return virtualFileFinder.find(kotlinFqNameToJavaFqName(naiveKotlinFqName((ClassDescriptor) descriptor))); } else if (descriptor instanceof NamespaceDescriptor) { - return findVirtualFileByPackage((NamespaceDescriptor) descriptor); + return virtualFileFinder.find(PackageClassUtils.getPackageClassFqName(DescriptorUtils.getFQName(descriptor).toSafe())); } else { throw new IllegalStateException("Unrecognized descriptor: " + descriptor); } } - @Nullable - private VirtualFile findVirtualFileByClass(@NotNull ClassDescriptor descriptor) { - return virtualFileFinder.find(kotlinFqNameToJavaFqName(naiveKotlinFqName(descriptor))); - } - - @Nullable - private VirtualFile findVirtualFileByPackage(@NotNull NamespaceDescriptor descriptor) { - return virtualFileFinder.find(PackageClassUtils.getPackageClassFqName(DescriptorUtils.getFQName(descriptor).toSafe())); - } - @NotNull private List loadClassAnnotationsFromFile(@NotNull VirtualFile virtualFile) throws IOException { final List result = new ArrayList(); @@ -250,15 +240,7 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer if (container instanceof NamespaceDescriptor) { Name name = loadSrcClassName(proto, nameResolver); if (name != null) { - // To locate a package$src class, we first find the facade virtual file (*Package.class) and then look up the $src file in - // the same directory. This hack is needed because FileManager doesn't find classfiles for $src classes - VirtualFile facadeFile = findVirtualFileByPackage((NamespaceDescriptor) container); - if (facadeFile != null) { - VirtualFile srcFile = facadeFile.getParent().findChild(name + ".class"); - if (srcFile != null) { - return srcFile; - } - } + return virtualFileFinder.find(getSrcClassFqName((NamespaceDescriptor) container, name)); } return null; } @@ -272,6 +254,11 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer return findVirtualFileByDescriptor(container); } + @NotNull + private static FqName getSrcClassFqName(@NotNull NamespaceDescriptor container, @NotNull Name name) { + return PackageClassUtils.getPackageClassFqName(DescriptorUtils.getFQName(container).toSafe()).parent().child(name); + } + @Nullable private static Name loadSrcClassName(@NotNull ProtoBuf.Callable proto, @NotNull NameResolver nameResolver) { return proto.hasExtension(JavaProtoBuf.srcClassName) ? nameResolver.getName(proto.getExtension(JavaProtoBuf.srcClassName)) : null; diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/PackageFragmentClassFileHeader.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/PackageFragmentClassFileHeader.java new file mode 100644 index 00000000000..3b5f477df7c --- /dev/null +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/PackageFragmentClassFileHeader.java @@ -0,0 +1,27 @@ +/* + * 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.lang.resolve.kotlin.header; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassFileHeader; +import org.jetbrains.jet.lang.resolve.name.FqName; + +public class PackageFragmentClassFileHeader extends KotlinClassFileHeader { + protected PackageFragmentClassFileHeader(int version, @NotNull FqName fqName) { + super(version, fqName); + } +} diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/ReadDataFromAnnotationVisitor.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/ReadDataFromAnnotationVisitor.java index b3705dcd0b3..131587df8cc 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/ReadDataFromAnnotationVisitor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/header/ReadDataFromAnnotationVisitor.java @@ -40,6 +40,7 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom private enum HeaderType { CLASS(JvmAnnotationNames.KOTLIN_CLASS), PACKAGE(JvmAnnotationNames.KOTLIN_PACKAGE), + PACKAGE_FRAGMENT(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT), OLD_CLASS(JvmAnnotationNames.OLD_JET_CLASS_ANNOTATION), OLD_PACKAGE(JvmAnnotationNames.OLD_JET_PACKAGE_CLASS_ANNOTATION); @@ -93,6 +94,8 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom return serializedDataHeader(SerializedDataHeader.Kind.CLASS, fqName); case PACKAGE: return serializedDataHeader(SerializedDataHeader.Kind.PACKAGE, fqName); + case PACKAGE_FRAGMENT: + return new PackageFragmentClassFileHeader(version, fqName); default: throw new UnsupportedOperationException("Unknown compatible HeaderType: " + foundType); } @@ -127,6 +130,9 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom if (newType == HeaderType.CLASS || newType == HeaderType.PACKAGE) { return kotlinClassOrPackageVisitor(desc); } + else if (newType == HeaderType.PACKAGE_FRAGMENT) { + return kotlinPackageFragmentVisitor(desc); + } return null; } @@ -136,12 +142,7 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom return new AnnotationVisitor(Opcodes.ASM4) { @Override public void visit(String name, Object value) { - if (name.equals(JvmAnnotationNames.ABI_VERSION_FIELD_NAME)) { - version = (Integer) value; - } - else if (isAbiVersionCompatible(version)) { - throw new IllegalStateException("Unexpected argument " + name + " for annotation " + desc); - } + visitIntValueForSupportedAnnotation(name, value, desc); } @Override @@ -177,4 +178,23 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom } }; } + + @NotNull + private AnnotationVisitor kotlinPackageFragmentVisitor(final String desc) { + return new AnnotationVisitor(Opcodes.ASM4) { + @Override + public void visit(String name, Object value) { + visitIntValueForSupportedAnnotation(name, value, desc); + } + }; + } + + private void visitIntValueForSupportedAnnotation(@NotNull String name, @NotNull Object value, @NotNull String desc) { + if (name.equals(JvmAnnotationNames.ABI_VERSION_FIELD_NAME)) { + version = (Integer) value; + } + else if (isAbiVersionCompatible(version)) { + throw new IllegalStateException("Unexpected argument " + name + " for annotation " + desc); + } + } } diff --git a/idea/src/org/jetbrains/jet/plugin/vfilefinder/KotlinClassFileIndex.java b/idea/src/org/jetbrains/jet/plugin/vfilefinder/KotlinClassFileIndex.java index 22d32af3c80..e8b285701f7 100644 --- a/idea/src/org/jetbrains/jet/plugin/vfilefinder/KotlinClassFileIndex.java +++ b/idea/src/org/jetbrains/jet/plugin/vfilefinder/KotlinClassFileIndex.java @@ -1,3 +1,19 @@ +/* + * 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.plugin.vfilefinder; import com.intellij.openapi.diagnostic.Logger; @@ -6,8 +22,8 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.indexing.*; import com.intellij.util.io.KeyDescriptor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.kotlin.header.IncompatibleAnnotationHeader; import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassFileHeader; -import org.jetbrains.jet.lang.resolve.kotlin.header.SerializedDataHeader; import org.jetbrains.jet.lang.resolve.name.FqName; import java.io.DataInput; @@ -19,7 +35,7 @@ import java.util.Map; public final class KotlinClassFileIndex extends ScalarIndexExtension { private static final Logger LOG = Logger.getInstance(KotlinClassFileIndex.class); - private static final int VERSION = 1; + private static final int VERSION = 2; public static final ID KEY = ID.create(KotlinClassFileIndex.class.getCanonicalName()); private static final KeyDescriptor KEY_DESCRIPTOR = new KeyDescriptor() { @@ -59,7 +75,7 @@ public final class KotlinClassFileIndex extends ScalarIndexExtension { public Map map(FileContent inputData) { try { KotlinClassFileHeader header = KotlinClassFileHeader.readKotlinHeaderFromClassFile(inputData.getFile()); - if (header instanceof SerializedDataHeader) { + if (header != null && !(header instanceof IncompatibleAnnotationHeader)) { return Collections.singletonMap(header.getFqName(), null); } }