Compare commits

...

36 Commits

Author SHA1 Message Date
Pavel V. Talanov
804a251e5f ~ 2014-11-07 18:59:04 +03:00
Pavel V. Talanov
f4a4bd203d ~ tests 2014-11-07 18:58:40 +03:00
Pavel V. Talanov
1d5836f60a ~ 2014-11-07 18:08:26 +03:00
Pavel V. Talanov
69303d638f ~ test 2014-11-07 18:08:03 +03:00
Pavel V. Talanov
a445e8b289 Convert to Kotlin: KotlinParameterStubImpl 2014-11-07 18:07:51 +03:00
Pavel V. Talanov
2c5b11ed97 ~ 2014-11-07 17:44:21 +03:00
Pavel V. Talanov
6166afb911 Convert to Kotlin: KotlinUserTypeStubImpl 2014-11-07 17:44:01 +03:00
Pavel V. Talanov
8d7b2a83f7 Determine stub interface more accurately 2014-11-06 20:17:50 +03:00
Pavel V. Talanov
1806b09809 ++ KotlinModifierListStubImpl + ModifierMaskUtils.kt 2014-11-06 20:16:27 +03:00
Pavel V. Talanov
7ba16f8a4e ++ KotlinClassStubImpl.kt 2014-11-06 20:15:48 +03:00
Pavel V. Talanov
d6d642be52 tests ++ 2014-11-06 19:57:51 +03:00
Pavel V. Talanov
c3b232cb2f ++ 2014-11-06 19:43:41 +03:00
Pavel V. Talanov
a49a44dee3 ++ 2014-11-06 19:39:26 +03:00
Pavel V. Talanov
17451c13f0 Convert to Kotlin: KotlinFunctionStubImpl and KotlinPropertyStubImpl 2014-11-06 19:39:07 +03:00
Pavel V. Talanov
d886066102 ++ 2014-11-06 19:17:21 +03:00
Pavel V. Talanov
a4dc6946b8 ++ 2014-11-06 19:13:24 +03:00
Pavel V. Talanov
b7ae06f1f5 ++ 2014-11-06 19:12:57 +03:00
Pavel V. Talanov
a37144612f ++ 2014-11-06 19:11:40 +03:00
Pavel V. Talanov
cbbacd0043 ++ 2014-11-06 19:11:16 +03:00
Pavel V. Talanov
7d77005567 ++ 2014-11-06 19:08:50 +03:00
Pavel V. Talanov
eea79c6fca Convert to Kotlin: Stub interfaces and place them in one file 2014-11-06 18:19:21 +03:00
Pavel V. Talanov
7b1fd591c2 Convert to Kotlin: KotlinObjectStubImpl 2014-11-06 18:18:57 +03:00
Pavel V. Talanov
7f8b7fb35c ++ 2014-11-06 17:42:11 +03:00
Pavel V. Talanov
a52f6a849b Convert to Kotlin: KotlinObjectStubImpl 2014-11-06 17:38:59 +03:00
Pavel V. Talanov
3bd3c69bc1 ++ 2014-11-06 17:31:07 +03:00
Pavel V. Talanov
483de4d1db NAME 2014-11-06 14:39:55 +03:00
Pavel V. Talanov
0c0f400604 Move logic dealing with mask from KotlinModifierListStubImpl
To a separate kotlin file
2014-11-06 14:37:32 +03:00
Pavel V. Talanov
1abae94a03 Minor 2014-11-06 14:22:41 +03:00
Pavel V. Talanov
06c3494aa5 ++ draft 2014-11-06 14:21:13 +03:00
Pavel V. Talanov
81c7d82804 revert converting KotlinModifierListStubImpl 2014-11-06 14:21:02 +03:00
Pavel Talanov
630ac58520 -- draft 2014-11-04 19:48:36 +04:00
Pavel Talanov
1f08fef0a2 REVIEW: Convert KotlinModifierListStubImpl to Kotlin 2014-11-04 19:32:13 +04:00
Pavel Talanov
3406d030e5 ++ 2014-11-02 17:07:40 +04:00
Pavel Talanov
aabe67869b DRAFT: ClsStubBuilderTest 2014-11-02 17:04:31 +04:00
Pavel Talanov
6328700ee8 ++ 2014-11-01 20:27:10 +04:00
Pavel V. Talanov
009a0d3418 DRAFT: building stubs for kotlin cls 2014-10-31 20:24:54 +03:00
48 changed files with 1091 additions and 1073 deletions

View File

@@ -1,28 +0,0 @@
/*
* 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
public interface KotlinAnnotationEntryStub extends StubElement<JetAnnotationEntry> {
@NotNull
String getShortName();
boolean hasValueArguments();
}

View File

@@ -1,31 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import java.util.List;
public interface KotlinClassOrObjectStub<T extends JetClassOrObject> extends KotlinStubWithFqName<T> {
boolean isLocal();
@NotNull
List<String> getSuperNames();
boolean isTopLevel();
}

View File

@@ -1,25 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.jet.lang.psi.JetClass;
public interface KotlinClassStub extends KotlinClassOrObjectStub<JetClass> {
boolean isTrait();
boolean isEnumEntry();
}

View File

@@ -1,28 +0,0 @@
/*
* 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.psi.stubs;
import com.intellij.psi.stubs.PsiFileStub;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.name.FqName;
public interface KotlinFileStub extends PsiFileStub<JetFile> {
@NotNull
FqName getPackageFqName();
boolean isScript();
}

View File

@@ -1,31 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
public interface KotlinFunctionStub extends KotlinStubWithFqName<JetNamedFunction> {
boolean isTopLevel();
boolean isExtension();
boolean hasBlockBody();
boolean hasBody();
boolean hasTypeParameterListBeforeFunctionName();
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lexer.JetModifierKeywordToken;
public interface KotlinModifierListStub extends StubElement<JetModifierList> {
boolean hasModifier(@NotNull JetModifierKeywordToken modifierToken);
}

View File

@@ -1,27 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetNameReferenceExpression;
import org.jetbrains.jet.lang.resolve.name.Name;
public interface KotlinNameReferenceExpressionStub extends StubElement<JetNameReferenceExpression> {
@NotNull
String getReferencedName();
}

View File

@@ -1,24 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
public interface KotlinObjectStub extends KotlinClassOrObjectStub<JetObjectDeclaration> {
boolean isClassObject();
boolean isObjectLiteral();
}

View File

@@ -1,25 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.jet.lang.psi.JetParameter;
public interface KotlinParameterStub extends KotlinStubWithFqName<JetParameter> {
boolean isMutable();
boolean hasValOrValNode();
boolean hasDefaultValue();
}

View File

@@ -1,23 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.JetElement;
public interface KotlinPlaceHolderStub<T extends JetElement> extends StubElement<T> {
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
public interface KotlinPropertyAccessorStub extends StubElement<JetPropertyAccessor> {
boolean isGetter();
boolean hasBody();
boolean hasBlockBody();
}

View File

@@ -1,29 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.jet.lang.psi.JetProperty;
public interface KotlinPropertyStub extends KotlinStubWithFqName<JetProperty> {
boolean isVar();
boolean isTopLevel();
boolean hasDelegate();
boolean hasDelegateExpression();
boolean hasInitializer();
boolean hasReceiverTypeRef();
boolean hasReturnTypeRef();
}

View File

@@ -1,27 +0,0 @@
/*
* 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.psi.stubs;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.stubs.NamedStub;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.FqName;
public interface KotlinStubWithFqName<T extends PsiNamedElement> extends NamedStub<T> {
@Nullable
FqName getFqName();
}

View File

@@ -1,24 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.JetTypeConstraint;
public interface KotlinTypeConstraintStub extends StubElement<JetTypeConstraint> {
boolean isClassObjectConstraint();
}

View File

@@ -1,24 +0,0 @@
/*
* 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.psi.stubs;
import org.jetbrains.jet.lang.psi.JetTypeParameter;
public interface KotlinTypeParameterStub extends KotlinStubWithFqName<JetTypeParameter> {
boolean isInVariance();
boolean isOutVariance();
}

View File

@@ -1,25 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.JetProjectionKind;
import org.jetbrains.jet.lang.psi.JetTypeProjection;
public interface KotlinTypeProjectionStub extends StubElement<JetTypeProjection> {
JetProjectionKind getProjectionKind();
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetUserType;
import org.jetbrains.jet.lang.resolve.name.Name;
public interface KotlinUserTypeStub extends StubElement<JetUserType> {
boolean isAbsoluteInRootPackage();
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright 2010-2014 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.psi.stubs
import com.intellij.psi.PsiNamedElement
import com.intellij.psi.stubs.NamedStub
import org.jetbrains.jet.lang.resolve.name.FqName
import com.intellij.psi.stubs.StubElement
import com.intellij.psi.stubs.PsiFileStub
import org.jetbrains.jet.lexer.JetModifierKeywordToken
import org.jetbrains.jet.lang.psi.*
public trait KotlinFileStub : PsiFileStub<JetFile> {
public fun getPackageFqName(): FqName
public fun isScript(): Boolean
}
public trait KotlinPlaceHolderStub<T : JetElement> : StubElement<T>
public trait KotlinStubWithFqName<T : PsiNamedElement> : NamedStub<T> {
public fun getFqName(): FqName?
}
public trait KotlinClassOrObjectStub<T : JetClassOrObject> : KotlinStubWithFqName<T> {
public fun isLocal(): Boolean
public fun getSuperNames(): List<String>
public fun isTopLevel(): Boolean
}
public trait KotlinClassStub : KotlinClassOrObjectStub<JetClass> {
public fun isTrait(): Boolean
public fun isEnumEntry(): Boolean
}
public trait KotlinObjectStub : KotlinClassOrObjectStub<JetObjectDeclaration> {
public fun isClassObject(): Boolean
public fun isObjectLiteral(): Boolean
}
public trait KotlinAnnotationEntryStub : StubElement<JetAnnotationEntry> {
public fun getShortName(): String
public fun hasValueArguments(): Boolean
}
public trait KotlinFunctionStub : KotlinStubWithFqName<JetNamedFunction> {
public fun isTopLevel(): Boolean
public fun isExtension(): Boolean
public fun hasBlockBody(): Boolean
public fun hasBody(): Boolean
public fun hasTypeParameterListBeforeFunctionName(): Boolean
}
public trait KotlinImportDirectiveStub : StubElement<JetImportDirective> {
public fun isAbsoluteInRootPackage(): Boolean
public fun isAllUnder(): Boolean
public fun getAliasName(): String?
public fun isValid(): Boolean
}
public trait KotlinModifierListStub : StubElement<JetModifierList> {
public fun hasModifier(modifierToken: JetModifierKeywordToken): Boolean
}
public trait KotlinNameReferenceExpressionStub : StubElement<JetNameReferenceExpression> {
public fun getReferencedName(): String
}
public trait KotlinParameterStub : KotlinStubWithFqName<JetParameter> {
public fun isMutable(): Boolean
public fun hasValOrValNode(): Boolean
public fun hasDefaultValue(): Boolean
}
public trait KotlinPropertyAccessorStub : StubElement<JetPropertyAccessor> {
public fun isGetter(): Boolean
public fun hasBody(): Boolean
public fun hasBlockBody(): Boolean
}
public trait KotlinPropertyStub : KotlinStubWithFqName<JetProperty> {
public fun isVar(): Boolean
public fun isTopLevel(): Boolean
public fun hasDelegate(): Boolean
public fun hasDelegateExpression(): Boolean
public fun hasInitializer(): Boolean
public fun hasReceiverTypeRef(): Boolean
public fun hasReturnTypeRef(): Boolean
}
public trait KotlinTypeConstraintStub : StubElement<JetTypeConstraint> {
public fun isClassObjectConstraint(): Boolean
}
public trait KotlinTypeParameterStub : KotlinStubWithFqName<JetTypeParameter> {
public fun isInVariance(): Boolean
public fun isOutVariance(): Boolean
}
public trait KotlinTypeProjectionStub : StubElement<JetTypeProjection> {
public fun getProjectionKind(): JetProjectionKind
}
public trait KotlinUserTypeStub : StubElement<JetUserType> {
public fun isAbsoluteInRootPackage(): Boolean
}

View File

@@ -106,7 +106,7 @@ public class JetClassElementType extends JetStubElementType<KotlinClassStub, Jet
StubIndexServiceFactory.getInstance().indexClass(stub, sink);
}
private static JetClassElementType getStubType(boolean isEnumEntry) {
public static JetClassElementType getStubType(boolean isEnumEntry) {
return isEnumEntry ? JetStubElementTypes.ENUM_ENTRY : JetStubElementTypes.CLASS;
}
}

View File

@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.psi.stubs.impl.KotlinModifierListStubImpl;
import java.io.IOException;
import static org.jetbrains.jet.lang.psi.stubs.impl.KotlinModifierListStubImpl.computeMaskFromPsi;
import static org.jetbrains.jet.lang.psi.stubs.impl.ModifierMaskUtils.computeMaskFromModifierList;
public class JetModifierListElementType<T extends JetModifierList> extends JetStubElementType<KotlinModifierListStub, T> {
public JetModifierListElementType(@NotNull @NonNls String debugName, @NotNull Class<T> psiClass) {
@@ -36,7 +36,7 @@ public class JetModifierListElementType<T extends JetModifierList> extends JetSt
@Override
public KotlinModifierListStub createStub(@NotNull T psi, StubElement parentStub) {
return new KotlinModifierListStubImpl(parentStub, computeMaskFromPsi(psi), this);
return new KotlinModifierListStubImpl(parentStub, computeMaskFromModifierList(psi), this);
}
@Override

View File

@@ -1,103 +0,0 @@
/*
* 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.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.stubs.KotlinClassStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.ArrayList;
import java.util.List;
public class KotlinClassStubImpl extends KotlinStubBaseImpl<JetClass> implements KotlinClassStub {
private final StringRef qualifiedName;
private final StringRef name;
private final StringRef[] superNames;
private final boolean isTrait;
private final boolean isEnumEntry;
private final boolean isLocal;
private final boolean isTopLevel;
public KotlinClassStubImpl(
JetClassElementType type,
StubElement parent,
StringRef qualifiedName,
StringRef name,
StringRef[] superNames,
boolean isTrait,
boolean isEnumEntry,
boolean isLocal,
boolean isTopLevel
) {
super(parent, type);
this.qualifiedName = qualifiedName;
this.name = name;
this.superNames = superNames;
this.isTrait = isTrait;
this.isEnumEntry = isEnumEntry;
this.isLocal = isLocal;
this.isTopLevel = isTopLevel;
}
@Override
public FqName getFqName() {
String stringRef = StringRef.toString(qualifiedName);
if (stringRef == null) {
return null;
}
return new FqName(stringRef);
}
@Override
public boolean isTrait() {
return isTrait;
}
@Override
public boolean isEnumEntry() {
return isEnumEntry;
}
@Override
public boolean isLocal() {
return isLocal;
}
@Override
public String getName() {
return StringRef.toString(name);
}
@NotNull
@Override
public List<String> getSuperNames() {
List<String> result = new ArrayList<String>();
for (StringRef ref : superNames) {
result.add(ref.toString());
}
return result;
}
@Override
public boolean isTopLevel() {
return isTopLevel;
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
import org.jetbrains.jet.lang.psi.JetClass
import org.jetbrains.jet.lang.psi.stubs.KotlinClassStub
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType
import org.jetbrains.jet.lang.resolve.name.FqName
import java.util.ArrayList
import com.intellij.psi.PsiElement
public class KotlinClassStubImpl(
type: JetClassElementType,
parent: StubElement<out PsiElement>,
private val qualifiedName: StringRef?,
private val name: StringRef,
private val superNames: Array<StringRef>,
private val isTrait: Boolean,
private val isEnumEntry: Boolean,
private val isLocal: Boolean,
private val isTopLevel: Boolean
) : KotlinStubBaseImpl<JetClass>(parent, `type`), KotlinClassStub {
override fun getFqName(): FqName? {
val stringRef = StringRef.toString(qualifiedName)
if (stringRef == null) {
return null
}
return FqName(stringRef)
}
override fun isTrait(): Boolean {
return isTrait
}
override fun isEnumEntry(): Boolean {
return isEnumEntry
}
override fun isLocal(): Boolean {
return isLocal
}
override fun getName(): String? {
return StringRef.toString(name)
}
override fun getSuperNames(): List<String> {
val result = ArrayList<String>()
for (ref in superNames) {
result.add(ref.toString())
}
return result
}
override fun isTopLevel(): Boolean {
return isTopLevel
}
}

View File

@@ -1,98 +0,0 @@
/*
* 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.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.stubs.KotlinFunctionStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.lang.resolve.name.FqName;
public class KotlinFunctionStubImpl extends KotlinStubBaseImpl<JetNamedFunction> implements KotlinFunctionStub {
private final StringRef nameRef;
private final boolean isTopLevel;
private final boolean isExtension;
private final FqName fqName;
private final boolean hasBlockBody;
private final boolean hasBody;
private final boolean hasTypeParameterListBeforeFunctionName;
public KotlinFunctionStubImpl(
@NotNull StubElement parent,
@Nullable StringRef nameRef,
boolean isTopLevel,
@Nullable FqName fqName,
boolean isExtension,
boolean hasBlockBody,
boolean hasBody,
boolean hasTypeParameterListBeforeFunctionName
) {
super(parent, JetStubElementTypes.FUNCTION);
if (isTopLevel && fqName == null) {
throw new IllegalArgumentException("fqName shouldn't be null for top level functions");
}
this.nameRef = nameRef;
this.fqName = fqName;
this.isTopLevel = isTopLevel;
this.isExtension = isExtension;
this.hasBlockBody = hasBlockBody;
this.hasBody = hasBody;
this.hasTypeParameterListBeforeFunctionName = hasTypeParameterListBeforeFunctionName;
}
@Override
public String getName() {
return StringRef.toString(nameRef);
}
@Override
public boolean isTopLevel() {
return isTopLevel;
}
@Override
public boolean isExtension() {
return isExtension;
}
@Override
public boolean hasBlockBody() {
return hasBlockBody;
}
@Override
public boolean hasBody() {
return hasBody;
}
@Override
public boolean hasTypeParameterListBeforeFunctionName() {
return hasTypeParameterListBeforeFunctionName;
}
@Nullable
@Override
public FqName getFqName() {
return fqName;
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
import org.jetbrains.jet.lang.psi.JetNamedFunction
import org.jetbrains.jet.lang.psi.stubs.KotlinFunctionStub
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.jet.lang.resolve.name.FqName
import com.intellij.psi.PsiElement
public class KotlinFunctionStubImpl(
parent: StubElement<out PsiElement>,
private val nameRef: StringRef?,
private val isTopLevel: Boolean,
private val fqName: FqName?,
private val isExtension: Boolean,
private val hasBlockBody: Boolean,
private val hasBody: Boolean,
private val hasTypeParameterListBeforeFunctionName: Boolean
) : KotlinStubBaseImpl<JetNamedFunction>(parent, JetStubElementTypes.FUNCTION), KotlinFunctionStub {
{
if (isTopLevel && fqName == null) {
throw IllegalArgumentException("fqName shouldn't be null for top level functions")
}
}
override fun getFqName() = fqName
override fun getName() = StringRef.toString(nameRef)
override fun isTopLevel() = isTopLevel
override fun isExtension() = isExtension
override fun hasBlockBody() = hasBlockBody
override fun hasBody() = hasBody
override fun hasTypeParameterListBeforeFunctionName() = hasTypeParameterListBeforeFunctionName
}

View File

@@ -17,33 +17,14 @@
package org.jetbrains.jet.lang.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lang.psi.stubs.KotlinModifierListStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetModifierListElementType;
import org.jetbrains.jet.lexer.JetModifierKeywordToken;
import static org.jetbrains.jet.lexer.JetTokens.MODIFIER_KEYWORDS_ARRAY;
public class KotlinModifierListStubImpl extends KotlinStubBaseImpl<JetModifierList> implements KotlinModifierListStub {
static {
assert MODIFIER_KEYWORDS_ARRAY.length <= 32 : "Current implementation depends on the ability to represent modifier list as bit mask";
}
public static int computeMaskFromPsi(@NotNull JetModifierList modifierList) {
int mask = 0;
JetModifierKeywordToken[] orderedKeywords = MODIFIER_KEYWORDS_ARRAY;
for (int i = 0; i < orderedKeywords.length; i++) {
JetModifierKeywordToken modifierKeywordToken = orderedKeywords[i];
if (modifierList.hasModifier(modifierKeywordToken)) {
mask |= 1 << i;
}
}
return mask;
}
private final int mask;
public KotlinModifierListStubImpl(StubElement parent, int mask, @NotNull JetModifierListElementType<?> elementType) {
@@ -51,33 +32,18 @@ public class KotlinModifierListStubImpl extends KotlinStubBaseImpl<JetModifierLi
this.mask = mask;
}
@Override
public boolean hasModifier(@NotNull JetModifierKeywordToken modifierToken) {
int index = ArrayUtil.indexOf(MODIFIER_KEYWORDS_ARRAY, modifierToken);
assert index >= 0 : "All JetModifierKeywordTokens should present in MODIFIER_KEYWORDS_ARRAY";
return (mask & (1 << index)) != 0;
}
public int getMask() {
return mask;
}
@Override
public boolean hasModifier(@NotNull JetModifierKeywordToken modifierToken) {
return ModifierMaskUtils.maskHasModifier(mask, modifierToken);
}
@NotNull
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString());
sb.append("[");
boolean first = true;
for (JetModifierKeywordToken modifierKeyword : MODIFIER_KEYWORDS_ARRAY) {
if (hasModifier(modifierKeyword)) {
if (!first) {
sb.append(" ");
}
sb.append(modifierKeyword.getValue());
first = false;
}
}
sb.append("]");
return sb.toString();
return super.toString() + ModifierMaskUtils.maskToString(mask);
}
}

View File

@@ -1,100 +0,0 @@
/*
* 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.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
import org.jetbrains.jet.lang.psi.stubs.KotlinObjectStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.ArrayList;
import java.util.List;
public class KotlinObjectStubImpl extends KotlinStubBaseImpl<JetObjectDeclaration> implements KotlinObjectStub {
private final StringRef name;
private final FqName fqName;
private final StringRef[] superNames;
private final boolean isTopLevel;
private final boolean isClassObject;
private final boolean isLocal;
private final boolean isObjectLiteral;
public KotlinObjectStubImpl(
@NotNull StubElement parent,
@Nullable StringRef name,
@Nullable FqName fqName,
@NotNull StringRef[] superNames,
boolean isTopLevel,
boolean isClassObject,
boolean isLocal,
boolean isObjectLiteral
) {
super(parent, JetStubElementTypes.OBJECT_DECLARATION);
this.name = name;
this.fqName = fqName;
this.superNames = superNames;
this.isTopLevel = isTopLevel;
this.isClassObject = isClassObject;
this.isLocal = isLocal;
this.isObjectLiteral = isObjectLiteral;
}
@Override
public String getName() {
return StringRef.toString(name);
}
@Nullable
@Override
public FqName getFqName() {
return fqName;
}
@NotNull
@Override
public List<String> getSuperNames() {
List<String> result = new ArrayList<String>();
for (StringRef ref : superNames) {
result.add(ref.toString());
}
return result;
}
@Override
public boolean isTopLevel() {
return isTopLevel;
}
@Override
public boolean isClassObject() {
return isClassObject;
}
@Override
public boolean isObjectLiteral() {
return isObjectLiteral;
}
@Override
public boolean isLocal() {
return isLocal;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
import org.jetbrains.jet.lang.psi.JetObjectDeclaration
import org.jetbrains.jet.lang.psi.stubs.KotlinObjectStub
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.jet.lang.resolve.name.FqName
import com.intellij.psi.PsiElement
public class KotlinObjectStubImpl(
parent: StubElement<out PsiElement>,
private val name: StringRef?,
private val fqName: FqName?,
private val superNames: Array<StringRef>,
private val isTopLevel: Boolean,
private val isClassObject: Boolean,
private val isLocal: Boolean,
private val isObjectLiteral: Boolean
) : KotlinStubBaseImpl<JetObjectDeclaration>(parent, JetStubElementTypes.OBJECT_DECLARATION), KotlinObjectStub {
override fun getFqName() = fqName
override fun getName() = StringRef.toString(name)
override fun getSuperNames() = superNames map { it.toString() }
override fun isTopLevel() = isTopLevel
override fun isClassObject() = isClassObject
override fun isObjectLiteral() = isObjectLiteral
override fun isLocal() = isLocal
}

View File

@@ -1,74 +0,0 @@
/*
* 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.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.psi.stubs.KotlinParameterStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.lang.resolve.name.FqName;
public class KotlinParameterStubImpl extends KotlinStubBaseImpl<JetParameter> implements KotlinParameterStub {
private final StringRef name;
private final boolean isMutable;
private final StringRef fqName;
private final boolean hasValOrValNode;
private final boolean hasDefaultValue;
public KotlinParameterStubImpl(
StubElement parent,
StringRef fqName, StringRef name,
boolean isMutable,
boolean hasValOrValNode,
boolean hasDefaultValue
) {
super(parent, JetStubElementTypes.VALUE_PARAMETER);
this.name = name;
this.isMutable = isMutable;
this.fqName = fqName;
this.hasValOrValNode = hasValOrValNode;
this.hasDefaultValue = hasDefaultValue;
}
@Override
public String getName() {
return StringRef.toString(name);
}
@Override
public boolean isMutable() {
return isMutable;
}
@Override
public boolean hasValOrValNode() {
return hasValOrValNode;
}
@Override
public boolean hasDefaultValue() {
return hasDefaultValue;
}
@Nullable
@Override
public FqName getFqName() {
return fqName != null ? new FqName(fqName.getString()) : null;
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
import org.jetbrains.jet.lang.psi.JetParameter
import org.jetbrains.jet.lang.psi.stubs.KotlinParameterStub
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.jet.lang.resolve.name.FqName
import com.intellij.psi.PsiElement
public class KotlinParameterStubImpl(
parent: StubElement<out PsiElement>,
private val fqName: StringRef?,
private val name: StringRef?,
private val isMutable: Boolean,
private val hasValOrValNode: Boolean,
private val hasDefaultValue: Boolean
) : KotlinStubBaseImpl<JetParameter>(parent, JetStubElementTypes.VALUE_PARAMETER), KotlinParameterStub {
override fun getName(): String? {
return StringRef.toString(name)
}
override fun getFqName(): FqName? {
return if (fqName != null) FqName(fqName.getString()) else null
}
override fun isMutable() = isMutable
override fun hasValOrValNode() = hasValOrValNode
override fun hasDefaultValue() = hasDefaultValue
}

View File

@@ -1,115 +0,0 @@
/*
* 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.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.stubs.KotlinPropertyStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.lang.resolve.name.FqName;
public class KotlinPropertyStubImpl extends KotlinStubBaseImpl<JetProperty> implements KotlinPropertyStub {
private final StringRef name;
private final boolean isVar;
private final boolean isTopLevel;
private final boolean hasDelegate;
private final boolean hasDelegateExpression;
private final boolean hasInitializer;
private final boolean hasReceiverTypeRef;
private final boolean hasReturnTypeRef;
private final FqName fqName;
public KotlinPropertyStubImpl(
StubElement parent,
StringRef name,
boolean isVar,
boolean isTopLevel,
boolean hasDelegate,
boolean hasDelegateExpression,
boolean hasInitializer,
boolean hasReceiverTypeRef,
boolean hasReturnTypeRef,
@Nullable FqName fqName
) {
super(parent, JetStubElementTypes.PROPERTY);
if (isTopLevel && fqName == null) {
throw new IllegalArgumentException("fqName shouldn't be null for top level properties");
}
if (hasDelegateExpression && !hasDelegate) {
throw new IllegalArgumentException("Can't have delegate expression without delegate");
}
this.name = name;
this.isVar = isVar;
this.isTopLevel = isTopLevel;
this.hasDelegate = hasDelegate;
this.hasDelegateExpression = hasDelegateExpression;
this.hasInitializer = hasInitializer;
this.hasReceiverTypeRef = hasReceiverTypeRef;
this.hasReturnTypeRef = hasReturnTypeRef;
this.fqName = fqName;
}
@Override
public boolean isVar() {
return isVar;
}
@Override
public boolean isTopLevel() {
return isTopLevel;
}
@Override
public boolean hasDelegate() {
return hasDelegate;
}
@Override
public boolean hasDelegateExpression() {
return hasDelegateExpression;
}
@Override
public boolean hasInitializer() {
return hasInitializer;
}
@Override
public boolean hasReceiverTypeRef() {
return hasReceiverTypeRef;
}
@Override
public boolean hasReturnTypeRef() {
return hasReturnTypeRef;
}
@Nullable
@Override
public FqName getFqName() {
return fqName;
}
@Override
public String getName() {
return StringRef.toString(name);
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
import org.jetbrains.jet.lang.psi.JetProperty
import org.jetbrains.jet.lang.psi.stubs.KotlinPropertyStub
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.jet.lang.resolve.name.FqName
import com.intellij.psi.PsiElement
public class KotlinPropertyStubImpl(
parent: StubElement<out PsiElement>,
private val name: StringRef,
private val isVar: Boolean,
private val isTopLevel: Boolean,
private val hasDelegate: Boolean,
private val hasDelegateExpression: Boolean,
private val hasInitializer: Boolean,
private val hasReceiverTypeRef: Boolean,
private val hasReturnTypeRef: Boolean,
private val fqName: FqName?
) : KotlinStubBaseImpl<JetProperty>(parent, JetStubElementTypes.PROPERTY), KotlinPropertyStub {
{
if (isTopLevel && fqName == null) {
throw IllegalArgumentException("fqName shouldn't be null for top level properties")
}
if (hasDelegateExpression && !hasDelegate) {
throw IllegalArgumentException("Can't have delegate expression without delegate")
}
}
override fun getFqName() = fqName
override fun isVar() = isVar
override fun isTopLevel() = isTopLevel
override fun hasDelegate() = hasDelegate
override fun hasDelegateExpression() = hasDelegateExpression
override fun hasInitializer() = hasInitializer
override fun hasReceiverTypeRef() = hasReceiverTypeRef
override fun hasReturnTypeRef() = hasReturnTypeRef
override fun getName() = StringRef.toString(name)
}

View File

@@ -30,7 +30,7 @@ import java.util.ArrayList
public open class KotlinStubBaseImpl<T : JetElementImplStub<*>>(parent: StubElement<*>?, elementType: IStubElementType<*, *>) : StubBase<T>(parent, elementType) {
override fun toString(): String {
val stubInterface = this.javaClass.getInterfaces().first()
val stubInterface = this.javaClass.getInterfaces().filter { it.getName().endsWith("Stub") }.single()
val propertiesValues = renderPropertyValues(stubInterface)
if (propertiesValues.isEmpty()) {
return ""

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.JetUserType;
import org.jetbrains.jet.lang.psi.stubs.KotlinUserTypeStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
public class KotlinUserTypeStubImpl extends KotlinStubBaseImpl<JetUserType> implements KotlinUserTypeStub {
private final boolean isAbsoluteInRootPackage;
public KotlinUserTypeStubImpl(StubElement parent, boolean isAbsoluteInRootPackage) {
super(parent, JetStubElementTypes.USER_TYPE);
this.isAbsoluteInRootPackage = isAbsoluteInRootPackage;
}
@Override
public boolean isAbsoluteInRootPackage() {
return isAbsoluteInRootPackage;
}
}

View File

@@ -14,17 +14,17 @@
* limitations under the License.
*/
package org.jetbrains.jet.lang.psi.stubs;
package org.jetbrains.jet.lang.psi.stubs.impl
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetImportDirective;
import org.jetbrains.jet.lang.resolve.name.Name;
import com.intellij.psi.stubs.StubElement
import org.jetbrains.jet.lang.psi.JetUserType
import org.jetbrains.jet.lang.psi.stubs.KotlinUserTypeStub
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import com.intellij.psi.PsiElement
public interface KotlinImportDirectiveStub extends StubElement<JetImportDirective> {
boolean isAbsoluteInRootPackage();
boolean isAllUnder();
@Nullable
String getAliasName();
boolean isValid();
public class KotlinUserTypeStubImpl(
parent: StubElement<out PsiElement>,
private val isAbsoluteInRootPackage: Boolean
) : KotlinStubBaseImpl<JetUserType>(parent, JetStubElementTypes.USER_TYPE), KotlinUserTypeStub {
override fun isAbsoluteInRootPackage() = isAbsoluteInRootPackage
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2010-2014 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.psi.stubs.impl
import org.jetbrains.jet.lang.psi.JetModifierList
import org.jetbrains.jet.lexer.JetTokens.MODIFIER_KEYWORDS_ARRAY
import org.jetbrains.jet.lexer.JetModifierKeywordToken
import kotlin.platform.platformStatic
public object ModifierMaskUtils {
{
assert(MODIFIER_KEYWORDS_ARRAY.size <= 32, "Current implementation depends on the ability to represent modifier list as bit mask")
}
platformStatic public fun computeMaskFromModifierList(modifierList: JetModifierList): Int = computeMask { modifierList.hasModifier(it) }
platformStatic public fun computeMask(hasModifier: (JetModifierKeywordToken) -> Boolean): Int {
var mask = 0
val orderedKeywords = MODIFIER_KEYWORDS_ARRAY
for ((index, modifierKeywordToken) in orderedKeywords.withIndices()) {
if (hasModifier(modifierKeywordToken)) {
mask = mask or (1 shl index)
}
}
return mask
}
platformStatic public fun maskHasModifier(mask: Int, modifierToken: JetModifierKeywordToken): Boolean {
val index = MODIFIER_KEYWORDS_ARRAY.indexOf(modifierToken)
assert(index >= 0, "All JetModifierKeywordTokens should be present in MODIFIER_KEYWORDS_ARRAY")
return (mask and (1 shl index)) != 0
}
platformStatic public fun maskToString(mask: Int): String {
val sb = StringBuilder()
sb.append("[")
var first = true
for (modifierKeyword in MODIFIER_KEYWORDS_ARRAY) {
if (maskHasModifier(mask, modifierKeyword)) {
if (!first) {
sb.append(" ")
}
sb.append(modifierKeyword.getValue())
first = false
}
}
sb.append("]")
return sb.toString()
}
}

View File

@@ -20,6 +20,6 @@ import com.intellij.util.io.StringRef
object Utils {
fun wrapStrings(names : List<String>) : Array<StringRef> {
return Array<StringRef>(names.size()) { i -> StringRef.fromString(names.get(i))!! }
return Array(names.size()) { i -> StringRef.fromString(names.get(i))!! }
}
}

View File

@@ -129,6 +129,7 @@ import org.jetbrains.k2js.test.semantics.AbstractBridgeTest
import org.jetbrains.jet.j2k.test.AbstractJavaToKotlinConverterMultiFileTest
import org.jetbrains.jet.j2k.test.AbstractJavaToKotlinConverterForWebDemoTest
import org.jetbrains.jet.plugin.decompiler.textBuilder.AbstractDecompiledTextTest
import org.jetbrains.jet.plugin.decompiler.stubBuilder.AbstractClsStubBuilderTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -576,6 +577,10 @@ fun main(args: Array<String>) {
model("decompiler/decompiledText", pattern = """^([^\.]+)$""")
}
testClass(javaClass<AbstractClsStubBuilderTest>()) {
model("decompiler/stubBuilder", extension = null, recursive = false)
}
testClass(javaClass<AbstractOptimizeImportsTest>()) {
model("editor/optimizeImports", extension = null, recursive = false)
}

View File

@@ -22,6 +22,7 @@ import com.intellij.psi.PsiManager;
import com.intellij.psi.compiled.ClassFileDecompilers;
import com.intellij.psi.compiled.ClsStubBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.decompiler.stubBuilder.KotlinClsStubBuilder;
public class JetClassFileDecompiler extends ClassFileDecompilers.Full {
private final ClsStubBuilder stubBuilder = new KotlinClsStubBuilder();

View File

@@ -25,6 +25,8 @@ import com.intellij.psi.SingleRootFileViewProvider
import org.jetbrains.jet.plugin.JetLanguage
import kotlin.properties.Delegates
import org.jetbrains.jet.plugin.decompiler.textBuilder.buildDecompiledText
import org.jetbrains.jet.lang.psi.JetFile
import com.intellij.lang.Language
public class JetClassFileViewProvider(
manager: PsiManager,
@@ -44,7 +46,7 @@ public class JetClassFileViewProvider(
//TODO: check index that file is library file, as in ClassFileViewProvider
if (isInternal) return null
return JetClsFile(this)
return JetFile(this, true)
}
override fun createCopy(copy: VirtualFile): SingleRootFileViewProvider {

View File

@@ -1,40 +0,0 @@
/*
* Copyright 2010-2014 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.decompiler
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.compiled.ClsStubBuilder
import com.intellij.psi.impl.compiled.ClassFileStubBuilder
import com.intellij.psi.impl.compiled.ClsFileImpl
import com.intellij.psi.stubs.PsiFileStub
import com.intellij.util.cls.ClsFormatException
import com.intellij.util.indexing.FileContent
public class KotlinClsStubBuilder : ClsStubBuilder() {
override fun getStubVersion() = ClassFileStubBuilder.STUB_VERSION + 1
throws(javaClass<ClsFormatException>())
override fun buildFileStub(content: FileContent): PsiFileStub<*>? {
val file = content.getFile()
if (isKotlinInternalCompiledFile(file)) {
return null
}
return ClsFileImpl.buildFileStub(file, content.getContent())
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2010-2014 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.decompiler.stubBuilder
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.stubs.StubElement
import org.jetbrains.jet.descriptors.serialization.ClassData
import org.jetbrains.jet.descriptors.serialization.Flags
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
import org.jetbrains.jet.lang.psi.stubs.KotlinStubWithFqName
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinClassStubImpl
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinObjectStubImpl
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.name.Name
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.psi.JetClassBody
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinPlaceHolderStubImpl
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import com.intellij.util.io.StringRef
import org.jetbrains.jet.lexer.JetModifierKeywordToken
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Visibility
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Modality
import com.intellij.psi.PsiNamedElement
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinModifierListStubImpl
import org.jetbrains.jet.lang.psi.stubs.impl.ModifierMaskUtils
import org.jetbrains.jet.lang.psi.JetParameterList
import kotlin.properties.Delegates
public class CompiledClassStubBuilder(
classData: ClassData,
private val classFqName: FqName,
packageFqName: FqName,
private val parent: StubElement<out PsiElement>,
private val file: VirtualFile
) : CompiledStubBuilderBase(classData.getNameResolver(), packageFqName) {
private val classProto = classData.getClassProto()
private var rootStub: KotlinStubWithFqName<out PsiNamedElement> by Delegates.notNull()
override fun getInternalFqName(name: String) = null
public fun createStub() {
createRootStub()
createModifierListStub(rootStub, classProto.getFlags())
createConstructorStub()
createClassBodyAndMemberStubs()
}
private fun createClassBodyAndMemberStubs() {
val classBody = KotlinPlaceHolderStubImpl<JetClassBody>(rootStub, JetStubElementTypes.CLASS_BODY)
for (callableProto in classProto.getMemberList()) {
createCallableStub(classBody, callableProto)
}
}
private fun createRootStub() {
val kind = Flags.CLASS_KIND.get(classProto.getFlags())
val isEnumEntry = kind == ProtoBuf.Class.Kind.ENUM_ENTRY
val shortName = classFqName.shortName().asString().ref()
if (kind == ProtoBuf.Class.Kind.OBJECT) {
rootStub = KotlinObjectStubImpl(
parent, shortName, classFqName, getSuperTypeRefs(),
isTopLevel = true,
isClassObject = false,
isLocal = false,
isObjectLiteral = false
)
}
else {
rootStub = KotlinClassStubImpl(
JetClassElementType.getStubType(isEnumEntry), parent, classFqName.asString().ref(), shortName,
getSuperTypeRefs(),
isTrait = kind == ProtoBuf.Class.Kind.TRAIT,
isEnumEntry = kind == ProtoBuf.Class.Kind.ENUM_ENTRY,
isLocal = false,
isTopLevel = true
)
}
}
private fun getSuperTypeRefs(): Array<StringRef> {
val superTypeStrings = classProto.getSupertypeList().map {
type ->
assert(type.getConstructor().getKind() == ProtoBuf.Type.Constructor.Kind.CLASS)
val superFqName = nameResolver.getFqName(type.getConstructor().getId())
superFqName.asString()
}
return superTypeStrings.filter { it != "kotlin.Any" }.map { it.ref() }.copyToArray()
}
fun createConstructorStub() {
KotlinPlaceHolderStubImpl<JetParameterList>(rootStub, JetStubElementTypes.VALUE_PARAMETER_LIST)
}
}
//TODO: eliminate toString().ref
fun String.ref() = StringRef.fromString(this)

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2010-2014 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.decompiler.stubBuilder
import org.jetbrains.jet.descriptors.serialization.PackageData
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.name.Name
import org.jetbrains.jet.lang.psi.stubs.KotlinFileStub
public class CompiledPackageClassStubBuilder(
packageData: PackageData,
packageFqName: FqName
) : CompiledStubBuilderBase(packageData.getNameResolver(), packageFqName) {
private val packageProto = packageData.getPackageProto()
public fun createStub(): KotlinFileStub {
val fileStub = createFileStub(packageFqName)
for (callableProto in packageProto.getMemberList()) {
createCallableStub(fileStub, callableProto)
}
return fileStub
}
override fun getInternalFqName(name: String): FqName? {
return packageFqName.child(Name.identifier(name))
}
}

View File

@@ -0,0 +1,235 @@
/*
* Copyright 2010-2014 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.decompiler.stubBuilder
import com.intellij.psi.stubs.StubElement
import org.jetbrains.jet.descriptors.serialization.Flags
import org.jetbrains.jet.descriptors.serialization.NameResolver
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinFileStubImpl
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinFunctionStubImpl
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinPropertyStubImpl
import org.jetbrains.jet.lang.resolve.name.FqName
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinPlaceHolderStubImpl
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.jet.lang.psi.JetPackageDirective
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinNameReferenceExpressionStubImpl
import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinUserTypeStubImpl
import org.jetbrains.jet.lang.psi.JetTypeReference
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinModifierListStubImpl
import org.jetbrains.jet.lang.psi.stubs.impl.ModifierMaskUtils
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Modality
import org.jetbrains.jet.lexer.JetModifierKeywordToken
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Visibility
import org.jetbrains.jet.lang.psi.JetParameterList
import org.jetbrains.jet.lang.psi.stubs.impl.KotlinParameterStubImpl
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.CallableKind
public abstract class CompiledStubBuilderBase(
protected val nameResolver: NameResolver,
protected val packageFqName: FqName
) {
protected fun createCallableStub(parentStub: StubElement<out PsiElement>, callableProto: ProtoBuf.Callable) {
val callableStub = doCreateCallableStub(callableProto, parentStub)
createModifierListStub(callableStub, callableProto.getFlags(), ignoreModality = true)
createValueParametersStub(callableStub, callableProto)
createTypeReferenceStub(callableStub, callableProto.getReturnType())
}
private fun createTypeReferenceStub(parent: StubElement<out PsiElement>, typeProto: ProtoBuf.Type) {
val typeReference = KotlinPlaceHolderStubImpl<JetTypeReference>(parent, JetStubElementTypes.TYPE_REFERENCE)
createTypeStub(typeProto, typeReference)
}
private fun createValueParametersStub(callableStub: StubElement<out PsiElement>, callableProto: ProtoBuf.Callable) {
if (Flags.CALLABLE_KIND.get(callableProto.getFlags()) != CallableKind.FUN) {
return
}
val parameterListStub = KotlinPlaceHolderStubImpl<JetParameterList>(callableStub, JetStubElementTypes.VALUE_PARAMETER_LIST)
for (valueParameter in callableProto.getValueParameterList()) {
val name = nameResolver.getName(valueParameter.getName())
val parameterStub = KotlinParameterStubImpl(
parameterListStub,
name = name.asString().ref(),
fqName = null,
hasDefaultValue = false,
hasValOrValNode = false,
isMutable = false
)
createTypeReferenceStub(parameterStub, valueParameter.getType())
}
}
private fun doCreateCallableStub(callableProto: ProtoBuf.Callable, parentStub: StubElement<out PsiElement>): StubElement<out PsiElement> {
val callableKind = Flags.CALLABLE_KIND.get(callableProto.getFlags())
val callableName = nameResolver.getName(callableProto.getName()).asString()
val callableFqName = getInternalFqName(callableName)
val callableNameRef = callableName.ref()
return when (callableKind) {
ProtoBuf.Callable.CallableKind.FUN ->
KotlinFunctionStubImpl(
parentStub,
callableNameRef,
isTopLevel = callableFqName != null,
fqName = callableFqName,
isExtension = callableProto.hasReceiverType(),
hasBlockBody = true,
hasBody = true,
hasTypeParameterListBeforeFunctionName = false
)
//TODO: merge these two
ProtoBuf.Callable.CallableKind.VAL ->
KotlinPropertyStubImpl(
parentStub, callableNameRef,
isVar = false,
isTopLevel = callableFqName != null,
hasDelegate = false,
hasDelegateExpression = false,
hasInitializer = false,
hasReceiverTypeRef = false,
hasReturnTypeRef = true,
fqName = callableFqName
)
//TODO: merge these two
ProtoBuf.Callable.CallableKind.VAR ->
KotlinPropertyStubImpl(
parentStub,
callableNameRef,
isVar = true,
isTopLevel = callableFqName != null,
hasDelegate = false,
hasDelegateExpression = false,
hasInitializer = false,
hasReceiverTypeRef = false,
hasReturnTypeRef = true,
fqName = callableFqName
)
ProtoBuf.Callable.CallableKind.CONSTRUCTOR -> throw IllegalStateException("Stubs for constructors are not supported!")
else -> throw IllegalStateException("Unknown callable kind $callableKind")
}
}
protected abstract fun getInternalFqName(name: String): FqName?
private fun createTypeStub(type: ProtoBuf.Type, parent: StubElement<out PsiElement>) {
val id = type.getConstructor().getId()
when (type.getConstructor().getKind()) {
ProtoBuf.Type.Constructor.Kind.CLASS -> {
val fqName = nameResolver.getFqName(id)
createStubForType(fqName, parent)
}
ProtoBuf.Type.Constructor.Kind.TYPE_PARAMETER -> {
//TODO: rocket science goes here
throw IllegalStateException("Unexpected $type")
}
}
}
}
public fun createFileStub(packageFqName: FqName): KotlinFileStubImpl {
val fileStub = KotlinFileStubImpl(null, packageFqName.asString(), packageFqName.isRoot())
val packageDirectiveStub = KotlinPlaceHolderStubImpl<JetPackageDirective>(fileStub, JetStubElementTypes.PACKAGE_DIRECTIVE)
createStubForPackageName(packageDirectiveStub, packageFqName)
return fileStub
}
private fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<JetPackageDirective>, packageFqName: FqName) {
val segments = packageFqName.pathSegments().toArrayList()
var current: StubElement<out JetElement> = packageDirectiveStub
while (segments.notEmpty) {
val head = segments.popFirst()
if (segments.empty) {
current = KotlinNameReferenceExpressionStubImpl(current, head.asString().ref())
}
else {
current = KotlinPlaceHolderStubImpl<JetDotQualifiedExpression>(current, JetStubElementTypes.DOT_QUALIFIED_EXPRESSION)
KotlinNameReferenceExpressionStubImpl(current, head.asString().ref())
}
}
}
private fun createStubForType(typeFqName: FqName, parent: StubElement<out PsiElement>) {
val segments = typeFqName.pathSegments().toArrayList()
assert(segments.notEmpty)
var current: StubElement<out PsiElement> = parent
var next: StubElement<out PsiElement>? = null
while (true) {
val lastSegment = segments.popLast()
current = next ?: KotlinUserTypeStubImpl(current, isAbsoluteInRootPackage = false)
if (segments.notEmpty) {
next = KotlinUserTypeStubImpl(current, isAbsoluteInRootPackage = false)
}
KotlinNameReferenceExpressionStubImpl(current, lastSegment.asString().ref())
if (segments.isEmpty()) {
break
}
}
}
private fun <T> MutableList<T>.popLast(): T {
val last = this.last
this.remove(lastIndex)
return last!!
}
private fun <T> MutableList<T>.popFirst(): T {
val first = this.head
this.remove(0)
return first!!
}
fun createModifierListStub(
parent: StubElement<out PsiElement>,
flags: Int,
ignoreModality: Boolean = false
) {
val modifiers = arrayListOf(visibilityToModifier(Flags.VISIBILITY.get(flags)))
if (!ignoreModality) {
modifiers.add(modalityToModifier(Flags.MODALITY.get(flags)))
}
KotlinModifierListStubImpl(
parent,
ModifierMaskUtils.computeMask { it in modifiers },
JetStubElementTypes.MODIFIER_LIST
)
}
private fun modalityToModifier(modality: Modality): JetModifierKeywordToken {
return when (modality) {
ProtoBuf.Modality.ABSTRACT -> JetTokens.ABSTRACT_KEYWORD
ProtoBuf.Modality.FINAL -> JetTokens.FINAL_KEYWORD
ProtoBuf.Modality.OPEN -> JetTokens.OPEN_KEYWORD
else -> throw IllegalStateException("Unexpected modality: $modality")
}
}
private fun visibilityToModifier(visibility: Visibility): JetModifierKeywordToken {
return when (visibility) {
ProtoBuf.Visibility.PRIVATE -> JetTokens.PRIVATE_KEYWORD
ProtoBuf.Visibility.INTERNAL -> JetTokens.INTERNAL_KEYWORD
ProtoBuf.Visibility.PROTECTED -> JetTokens.PROTECTED_KEYWORD
ProtoBuf.Visibility.PUBLIC -> JetTokens.PUBLIC_KEYWORD
//TODO: support extra visibility
else -> throw IllegalStateException("Unexpected visibility: $visibility")
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2010-2014 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.decompiler.stubBuilder
import com.intellij.psi.compiled.ClsStubBuilder
import com.intellij.util.cls.ClsFormatException
import com.intellij.util.indexing.FileContent
import com.intellij.psi.stubs.PsiFileStub
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.impl.compiled.ClassFileStubBuilder
import org.jetbrains.jet.plugin.decompiler
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
import org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil
import org.jetbrains.jet.lang.psi.JetFile
public class KotlinClsStubBuilder : ClsStubBuilder() {
override fun getStubVersion() = ClassFileStubBuilder.STUB_VERSION + 1
override fun buildFileStub(content: FileContent): PsiFileStub<*>? {
val file = content.getFile()
if (decompiler.isKotlinInternalCompiledFile(file)) {
return null
}
return doBuildFileStub(file)
}
throws(javaClass<ClsFormatException>())
fun doBuildFileStub(file: VirtualFile): PsiFileStub<JetFile>? {
val kotlinBinaryClass = KotlinBinaryClassCache.getKotlinBinaryClass(file)
val classFqName = kotlinBinaryClass.getClassId().asSingleFqName().toSafe()
val header = kotlinBinaryClass.getClassHeader()
val packageFqName = classFqName.parent()
return when (header.kind) {
KotlinClassHeader.Kind.PACKAGE_FACADE -> CompiledPackageClassStubBuilder(
JavaProtoBufUtil.readPackageDataFrom(header.annotationData), packageFqName
).createStub()
KotlinClassHeader.Kind.CLASS -> {
val fileStub = createFileStub(packageFqName)
CompiledClassStubBuilder(
JavaProtoBufUtil.readClassDataFrom(header.annotationData),
classFqName, packageFqName, fileStub, file
).createStub()
fileStub
}
else -> throw IllegalStateException("Should have processed " + file.getPath() + " with ${header.kind}")
}
}
}

View File

@@ -0,0 +1,3 @@
package test
class ClassWithNoMembers

View File

@@ -0,0 +1,13 @@
package foo.TopLevelMembers
fun funWithBlockBody() {
}
private fun funWithExprBody() = 3
private fun funWithParams(c: Int) {
}
public val immutable: Double = 0.0
public var mutable: Float = 0.0f

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2010-2014 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.decompiler.stubBuilder
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.jet.lang.psi.stubs.elements.JetFileStubBuilder
import com.intellij.psi.impl.DebugUtil
import org.jetbrains.jet.lang.resolve.name.SpecialNames
import org.jetbrains.jet.JetTestUtils
import java.io.File
import org.jetbrains.jet.MockLibraryUtil
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.util.indexing.FileContentImpl
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement
import java.util.ArrayList
import com.google.common.io.Files
import com.intellij.openapi.vfs.VirtualFile
import org.junit.Assert
//TODO: not clear that code in file and decompiled code differ
public open class AbstractClsStubBuilderTest : LightCodeInsightFixtureTestCase() {
fun doTest(sourcePath: String) {
val classFile = getClassFileToDecompile(sourcePath)
val stubTreeFromCls = KotlinClsStubBuilder().buildFileStub(FileContentImpl.createByFile(classFile))!!
val psiFile = myFixture.configureByFile(classFile.getPath())
val stubTreeFromDecompiledText = JetFileStubBuilder().buildStubTree(psiFile)
Assert.assertEquals(stubTreeFromDecompiledText.serializeToString(), stubTreeFromCls.serializeToString())
//TODO: add comparison to file
}
//TODO: util
private fun StubElement<out PsiElement>.serializeToString(): String {
return DebugUtil.stubTreeToString(this).replace(SpecialNames.SAFE_IDENTIFIER_FOR_NO_NAME.asString(), "<no name>")
}
private fun getClassFileToDecompile(sourcePath: String): VirtualFile {
//TODO: Review
val outDir = JetTestUtils.tmpDir("libForStubTest-" + sourcePath)
MockLibraryUtil.compileKotlin(sourcePath, outDir)
//TODO: refactor
val classFileToDecompile = outDir.findTargetClassFile(Files.getNameWithoutExtension(sourcePath.split("/").last()))
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(classFileToDecompile)!!
}
private fun File.findTargetClassFile(classFileName: String): File {
val result = ArrayList<File>()
recurse {
if (it.name == "$classFileName.class") {
result.add(it)
}
}
return result.single()
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2010-2014 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.decompiler.stubBuilder;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/decompiler/stubBuilder")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest {
public void testAllFilesPresentInStubBuilder() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/stubBuilder"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("ClassWithNoMembers")
public void testClassWithNoMembers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/ClassWithNoMembers/");
doTest(fileName);
}
@TestMetadata("TopLevelMembersPackage")
public void testTopLevelMembersPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/TopLevelMembersPackage/");
doTest(fileName);
}
}