Search in sources :

Example 1 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class IdeStubIndexService method indexObject.

@Override
public void indexObject(KotlinObjectStub stub, IndexSink sink) {
    String name = stub.getName();
    if (name != null) {
        sink.occurrence(KotlinClassShortNameIndex.getInstance().getKey(), name);
    }
    FqName fqName = stub.getFqName();
    if (fqName != null) {
        sink.occurrence(KotlinFullClassNameIndex.getInstance().getKey(), fqName.asString());
        if (stub.isTopLevel()) {
            sink.occurrence(KotlinTopLevelClassByPackageIndex.getInstance().getKey(), fqName.parent().asString());
        }
    }
    indexSuperNames(stub, sink);
}
Also used : FqName(org.jetbrains.kotlin.name.FqName)

Example 2 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class IdeStubIndexService method indexProperty.

@Override
public void indexProperty(KotlinPropertyStub stub, IndexSink sink) {
    String name = stub.getName();
    if (name != null) {
        sink.occurrence(KotlinPropertyShortNameIndex.getInstance().getKey(), name);
        if (TypeIndexUtilKt.isProbablyNothing(stub.getPsi().getTypeReference())) {
            sink.occurrence(KotlinProbablyNothingPropertyShortNameIndex.getInstance().getKey(), name);
        }
    }
    if (stub.isTopLevel()) {
        FqName fqName = stub.getFqName();
        // can have special fq name in case of syntactically incorrect property with no name
        if (fqName != null) {
            sink.occurrence(KotlinTopLevelPropertyFqnNameIndex.getInstance().getKey(), fqName.asString());
            sink.occurrence(KotlinTopLevelPropertyByPackageIndex.getInstance().getKey(), fqName.parent().asString());
            IndexUtilsKt.indexTopLevelExtension(stub, sink);
        }
    }
}
Also used : FqName(org.jetbrains.kotlin.name.FqName)

Example 3 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class IdeStubIndexService method indexTypeAlias.

@Override
public void indexTypeAlias(KotlinTypeAliasStub stub, IndexSink sink) {
    String name = stub.getName();
    if (name != null) {
        sink.occurrence(KotlinTypeAliasShortNameIndex.getInstance().getKey(), name);
    }
    IndexUtilsKt.indexTypeAliasExpansion(stub, sink);
    if (stub.isTopLevel()) {
        FqName fqName = stub.getFqName();
        if (fqName != null) {
            sink.occurrence(KotlinTopLevelTypeAliasFqNameIndex.getInstance().getKey(), fqName.asString());
            sink.occurrence(KotlinTopLevelTypeAliasByPackageIndex.getInstance().getKey(), fqName.parent().asString());
        }
    }
}
Also used : FqName(org.jetbrains.kotlin.name.FqName)

Example 4 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class MoveKotlinNestedClassesToUpperLevelDialog method init.

@Override
protected void init() {
    classNameField.setText(innerClass.getName());
    classNameField.selectAll();
    if (innerClass instanceof KtClass && ((KtClass) innerClass).isInner()) {
        passOuterClassCheckBox.setSelected(true);
        passOuterClassCheckBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                parameterField.setEnabled(passOuterClassCheckBox.isSelected());
            }
        });
    } else {
        passOuterClassCheckBox.setSelected(false);
        passOuterClassCheckBox.setEnabled(false);
        parameterField.setEnabled(false);
    }
    if (passOuterClassCheckBox.isEnabled()) {
        boolean thisNeeded = isThisNeeded();
        passOuterClassCheckBox.setSelected(thisNeeded);
        parameterField.setEnabled(thisNeeded);
    }
    passOuterClassCheckBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selected = passOuterClassCheckBox.isSelected();
            parameterField.getComponent().setEnabled(selected);
        }
    });
    if (!(targetContainer instanceof PsiDirectory)) {
        packageNameField.setVisible(false);
        packageNameLabel.setVisible(false);
    }
    if (innerClass instanceof KtClass && ((KtClass) innerClass).isInner()) {
        KtClassBody innerClassBody = innerClass.getBody();
        Function1<String, Boolean> validator = innerClassBody != null ? new NewDeclarationNameValidator(innerClassBody, (PsiElement) null, NewDeclarationNameValidator.Target.VARIABLES, Collections.<KtDeclaration>emptyList()) : new CollectingNameValidator();
        List<String> suggestions = KotlinNameSuggester.INSTANCE.suggestNamesByType(getOuterInstanceType(), validator, "outer");
        parameterField.setSuggestions(ArrayUtil.toStringArray(suggestions));
    } else {
        parameterField.getComponent().setEnabled(false);
    }
    FqName packageFqName = getTargetPackageFqName();
    if (packageFqName != null) {
        packageNameField.prependItem(packageFqName.asString());
    }
    KotlinRefactoringSettings settings = KotlinRefactoringSettings.getInstance();
    searchForTextOccurrencesCheckBox.setSelected(settings.MOVE_TO_UPPER_LEVEL_SEARCH_FOR_TEXT);
    searchInCommentsCheckBox.setSelected(settings.MOVE_TO_UPPER_LEVEL_SEARCH_IN_COMMENTS);
    super.init();
}
Also used : ItemEvent(java.awt.event.ItemEvent) FqName(org.jetbrains.kotlin.name.FqName) CollectingNameValidator(org.jetbrains.kotlin.idea.core.CollectingNameValidator) NewDeclarationNameValidator(org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator) KotlinRefactoringSettings(org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings) ItemListener(java.awt.event.ItemListener)

Example 5 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class AbstractScriptCodegenTest method doTest.

@Override
protected void doTest(@NotNull String filename) {
    loadFileByFullPath(filename);
    try {
        //noinspection ConstantConditions
        FqName fqName = myFiles.getPsiFile().getScript().getFqName();
        Class<?> scriptClass = generateClass(fqName.asString());
        Constructor constructor = getTheOnlyConstructor(scriptClass);
        Object scriptInstance = constructor.newInstance(myFiles.getScriptParameterValues().toArray());
        assertFalse("expecting at least one expectation", myFiles.getExpectedValues().isEmpty());
        for (Pair<String, String> nameValue : myFiles.getExpectedValues()) {
            String fieldName = nameValue.first;
            String expectedValue = nameValue.second;
            if (expectedValue.equals("<nofield>")) {
                try {
                    scriptClass.getDeclaredField(fieldName);
                    fail("must have no field " + fieldName);
                } catch (NoSuchFieldException e) {
                    continue;
                }
            }
            Field field = scriptClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            Object result = field.get(scriptInstance);
            String resultString = result != null ? result.toString() : "null";
            assertEquals("comparing field " + fieldName, expectedValue, resultString);
        }
    } catch (Throwable e) {
        System.out.println(generateToText());
        throw ExceptionUtilsKt.rethrow(e);
    }
}
Also used : Field(java.lang.reflect.Field) FqName(org.jetbrains.kotlin.name.FqName) Constructor(java.lang.reflect.Constructor)

Aggregations

FqName (org.jetbrains.kotlin.name.FqName)74 NotNull (org.jetbrains.annotations.NotNull)25 Nullable (org.jetbrains.annotations.Nullable)15 KtFile (org.jetbrains.kotlin.psi.KtFile)10 StringRef (com.intellij.util.io.StringRef)6 File (java.io.File)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)4 Name (org.jetbrains.kotlin.name.Name)4 PsiClass (com.intellij.psi.PsiClass)3 ClassId (org.jetbrains.kotlin.name.ClassId)3 Disposable (com.intellij.openapi.Disposable)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 SmartList (com.intellij.util.SmartList)2 Function1 (kotlin.jvm.functions.Function1)2 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)2 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)2 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)2 KtClassOrObject (org.jetbrains.kotlin.psi.KtClassOrObject)2