Search in sources :

Example 86 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project intellij-community by JetBrains.

the class CodeFragmentCodeStyleSettingsPanel method reformatSelectedTextWithNewSettings.

private void reformatSelectedTextWithNewSettings() {
    try {
        apply(getSettings());
    } catch (ConfigurationException e) {
        LOG.debug("Cannot apply code style settings", e);
    }
    CodeStyleSettings clonedSettings = getSettings().clone();
    mySelectedTextFormatter.reformatSelectedText(clonedSettings);
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 87 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project kotlin by JetBrains.

the class MoveKotlinNestedClassesToUpperLevelDialog method getTargetContainerWithValidation.

@Nullable
private PsiElement getTargetContainerWithValidation() throws ConfigurationException {
    String className = getClassName();
    String parameterName = getParameterName();
    if (className != null && className.isEmpty())
        throw new ConfigurationException(RefactoringBundle.message("no.class.name.specified"));
    if (!KotlinNameSuggester.INSTANCE.isIdentifier(className))
        throw new ConfigurationException(RefactoringMessageUtil.getIncorrectIdentifierMessage(className));
    if (passOuterClassCheckBox.isSelected()) {
        if (parameterName != null && parameterName.isEmpty())
            throw new ConfigurationException(RefactoringBundle.message("no.parameter.name.specified"));
        if (!KotlinNameSuggester.INSTANCE.isIdentifier(parameterName))
            throw new ConfigurationException(RefactoringMessageUtil.getIncorrectIdentifierMessage(parameterName));
    }
    PsiElement targetContainer = getTargetContainer();
    if (targetContainer instanceof KtClassOrObject) {
        KtClassOrObject targetClass = (KtClassOrObject) targetContainer;
        for (KtDeclaration member : targetClass.getDeclarations()) {
            if (member instanceof KtClassOrObject && className != null && className.equals(member.getName())) {
                throw new ConfigurationException(RefactoringBundle.message("inner.class.exists", className, targetClass.getName()));
            }
        }
    }
    if (targetContainer instanceof PsiDirectory || targetContainer instanceof KtFile) {
        FqName targetPackageFqName = getTargetPackageFqName();
        if (targetPackageFqName == null)
            throw new ConfigurationException("No package corresponds to this directory");
        //noinspection ConstantConditions
        ClassifierDescriptor existingClass = DescriptorUtils.getContainingModule(innerClassDescriptor).getPackage(targetPackageFqName).getMemberScope().getContributedClassifier(Name.identifier(className), NoLookupLocation.FROM_IDE);
        if (existingClass != null)
            throw new ConfigurationException("Class " + className + " already exists in package " + targetPackageFqName);
        PsiDirectory targetDir = targetContainer instanceof PsiDirectory ? (PsiDirectory) targetContainer : targetContainer.getContainingFile().getContainingDirectory();
        String message = RefactoringMessageUtil.checkCanCreateFile(targetDir, className + ".kt");
        if (message != null)
            throw new ConfigurationException(message);
    }
    return targetContainer;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FqName(org.jetbrains.kotlin.name.FqName) ClassifierDescriptor(org.jetbrains.kotlin.descriptors.ClassifierDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project kotlin by JetBrains.

the class MoveKotlinNestedClassesToUpperLevelDialog method doAction.

@Override
protected void doAction() {
    PsiElement target;
    try {
        target = getTargetContainerWithValidation();
        if (target == null)
            return;
    } catch (ConfigurationException e) {
        CommonRefactoringUtil.showErrorMessage(MoveInnerImpl.REFACTORING_NAME, e.getMessage(), HelpID.MOVE_INNER_UPPER, project);
        return;
    }
    KotlinRefactoringSettings settings = KotlinRefactoringSettings.getInstance();
    settings.MOVE_TO_UPPER_LEVEL_SEARCH_FOR_TEXT = searchForTextOccurrencesCheckBox.isSelected();
    settings.MOVE_TO_UPPER_LEVEL_SEARCH_IN_COMMENTS = searchInCommentsCheckBox.isSelected();
    KotlinMoveTarget moveTarget;
    if (target instanceof PsiDirectory) {
        final PsiDirectory targetDir = (PsiDirectory) target;
        final FqName targetPackageFqName = getTargetPackageFqName();
        if (targetPackageFqName == null)
            return;
        String innerClassName = innerClass.getName();
        if (innerClassName == null)
            return;
        final String targetFileName = KotlinNameSuggester.INSTANCE.suggestNameByName(innerClassName, new Function1<String, Boolean>() {

            @Override
            public Boolean invoke(String s) {
                return targetDir.findFile(s + "." + KotlinFileType.EXTENSION) == null;
            }
        }) + "." + KotlinFileType.EXTENSION;
        moveTarget = new KotlinMoveTargetForDeferredFile(targetPackageFqName, targetDir, null, new Function1<KtFile, KtFile>() {

            @Override
            public KtFile invoke(@NotNull KtFile originalFile) {
                return KotlinRefactoringUtilKt.createKotlinFile(targetFileName, targetDir, targetPackageFqName.asString());
            }
        });
    } else {
        //noinspection ConstantConditions
        moveTarget = new KotlinMoveTargetForExistingElement((KtElement) target);
    }
    String outerInstanceParameterName = passOuterClassCheckBox.isSelected() ? getParameterName() : null;
    String newClassName = getClassName();
    MoveDeclarationsDelegate delegate = new MoveDeclarationsDelegate.NestedClass(newClassName, outerInstanceParameterName);
    MoveDeclarationsDescriptor moveDescriptor = new MoveDeclarationsDescriptor(CollectionsKt.listOf(innerClass), moveTarget, delegate, isSearchInComments(), isSearchInNonJavaFiles(), true, false, null, isOpenInEditor());
    saveOpenInEditorOption();
    invokeRefactoring(new MoveKotlinDeclarationsProcessor(project, moveDescriptor, Mover.Default.INSTANCE));
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) Function1(kotlin.jvm.functions.Function1) NotNull(org.jetbrains.annotations.NotNull) ConfigurationException(com.intellij.openapi.options.ConfigurationException) KotlinRefactoringSettings(org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings)

Example 89 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project intellij-community by JetBrains.

the class PyStudyDirectoryProjectGenerator method createAndAddVirtualEnv.

public void createAndAddVirtualEnv(Project project, PyNewProjectSettings settings) {
    final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
    final String baseSdk = getBaseSdk(project);
    if (baseSdk != null) {
        final PyPackageManager packageManager = PyPackageManager.getInstance(new PyDetectedSdk(baseSdk));
        try {
            final String path = packageManager.createVirtualEnv(project.getBasePath() + "/.idea/VirtualEnvironment", false);
            AbstractCreateVirtualEnvDialog.setupVirtualEnvSdk(path, true, new AbstractCreateVirtualEnvDialog.VirtualEnvCallback() {

                @Override
                public void virtualEnvCreated(Sdk createdSdk, boolean associateWithProject) {
                    settings.setSdk(createdSdk);
                    model.addSdk(createdSdk);
                    try {
                        model.apply();
                    } catch (ConfigurationException exception) {
                        LOG.error("Error adding created virtual env " + exception.getMessage());
                    }
                    if (associateWithProject) {
                        SdkAdditionalData additionalData = createdSdk.getSdkAdditionalData();
                        if (additionalData == null) {
                            additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(createdSdk.getHomePath()));
                            ((ProjectJdkImpl) createdSdk).setSdkAdditionalData(additionalData);
                        }
                        ((PythonSdkAdditionalData) additionalData).associateWithNewProject();
                    }
                }
            });
        } catch (ExecutionException e) {
            LOG.warn("Failed to create virtual env " + e.getMessage());
        }
    }
}
Also used : ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) AbstractCreateVirtualEnvDialog(com.jetbrains.python.sdk.AbstractCreateVirtualEnvDialog) PyPackageManager(com.jetbrains.python.packaging.PyPackageManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 90 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project intellij-plugins by JetBrains.

the class OsmorcFacetJAREditorTab method apply.

@Override
public void apply() throws ConfigurationException {
    String jarFileName = myJarFileTextField.getText();
    if (StringUtil.isEmptyOrSpaces(jarFileName)) {
        throw new ConfigurationException(OsmorcBundle.message("facet.editor.jar.empty.jar.name"));
    }
    OsmorcFacetConfiguration configuration = (OsmorcFacetConfiguration) myEditorContext.getFacet().getConfiguration();
    OutputPathType pathType = getSelectedOutputPathType();
    if (pathType == SpecificOutputPath) {
        String location = myJarOutputPathChooser.getText();
        if (StringUtil.isEmptyOrSpaces(location)) {
            throw new ConfigurationException(OsmorcBundle.message("facet.editor.jar.empty.output.path"));
        }
        String completeOutputPath = new File(location, jarFileName).getPath();
        configuration.setJarFileLocation(completeOutputPath, pathType);
    } else {
        configuration.setJarFileLocation(jarFileName, pathType);
    }
    configuration.setIgnoreFilePattern(myIgnoreFilePatternTextField.getText());
    configuration.setAlwaysRebuildBundleJAR(myAlwaysRebuildBundleJARCheckBox.isSelected());
    configuration.setAdditionalJARContents(myAdditionalJARContentsTableModel.getAdditionalContents());
    myModified = false;
}
Also used : OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OutputPathType(org.jetbrains.osgi.jps.model.OutputPathType) ConfigurationException(com.intellij.openapi.options.ConfigurationException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Aggregations

ConfigurationException (com.intellij.openapi.options.ConfigurationException)102 File (java.io.File)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Project (com.intellij.openapi.project.Project)22 Module (com.intellij.openapi.module.Module)18 IOException (java.io.IOException)14 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)8 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)7 Sdk (com.intellij.openapi.projectRoots.Sdk)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)6 Disposable (com.intellij.openapi.Disposable)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 Pair (com.intellij.openapi.util.Pair)4 GradleProjectImporter (com.android.tools.idea.gradle.project.importing.GradleProjectImporter)3 ExecutionException (com.intellij.execution.ExecutionException)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)3 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)3 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)3