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);
}
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;
}
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));
}
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());
}
}
}
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;
}
Aggregations