use of com.intellij.refactoring.listeners.UndoRefactoringElementAdapter in project intellij-community by JetBrains.
the class JsonSchemaRefactoringListenerProvider method getListener.
@Nullable
@Override
public RefactoringElementListener getListener(PsiElement element) {
if (element == null) {
return null;
}
VirtualFile fileAtElement = PsiUtilBase.asVirtualFile(element);
if (fileAtElement == null || !(fileAtElement.getFileType() instanceof LanguageFileType) || !(((LanguageFileType) fileAtElement.getFileType()).getLanguage().isKindOf(JsonLanguage.INSTANCE))) {
return null;
}
Project project = element.getProject();
final JsonSchemaMappingsProjectConfiguration configuration = JsonSchemaMappingsProjectConfiguration.getInstance(project);
final JsonSchemaMappingsConfigurationBase.SchemaInfo schemaInfo = configuration.getSchemaBySchemaFile(fileAtElement);
if (schemaInfo != null && project.getBaseDir() != null) {
return new UndoRefactoringElementAdapter() {
@Override
protected void refactored(@NotNull PsiElement element, @Nullable String oldQualifiedName) {
VirtualFile newFile = PsiUtilBase.asVirtualFile(element);
if (newFile != null) {
final String relativePath = VfsUtil.getRelativePath(newFile, project.getBaseDir());
if (relativePath != null) {
configuration.removeSchema(schemaInfo);
final JsonSchemaMappingsConfigurationBase.SchemaInfo newSchema = new JsonSchemaMappingsConfigurationBase.SchemaInfo(schemaInfo.getName(), relativePath, schemaInfo.isApplicationLevel(), schemaInfo.getPatterns());
configuration.addSchema(newSchema);
}
}
}
};
}
return null;
}
Aggregations