mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
anonym -> lambda
This commit is contained in:
@@ -38,78 +38,74 @@ public class PythonFacet extends Facet<PythonFacetConfiguration> implements Libr
|
||||
}
|
||||
|
||||
public void updateLibrary() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final Module module = getModule();
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
boolean modelChanged = false;
|
||||
try {
|
||||
// Just remove all old facet libraries except one, that is necessary
|
||||
final Sdk sdk = getConfiguration().getSdk();
|
||||
final String name = (sdk != null) ? getFacetLibraryName(sdk.getName()) : null;
|
||||
boolean librarySeen = false;
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final String libraryName = ((LibraryOrderEntry)entry).getLibraryName();
|
||||
if (name != null && name.equals(libraryName)) {
|
||||
librarySeen = true;
|
||||
continue;
|
||||
}
|
||||
if (libraryName != null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
modelChanged = true;
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final Module module = getModule();
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
boolean modelChanged = false;
|
||||
try {
|
||||
// Just remove all old facet libraries except one, that is necessary
|
||||
final Sdk sdk = getConfiguration().getSdk();
|
||||
final String name = (sdk != null) ? getFacetLibraryName(sdk.getName()) : null;
|
||||
boolean librarySeen = false;
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final String libraryName = ((LibraryOrderEntry)entry).getLibraryName();
|
||||
if (name != null && name.equals(libraryName)) {
|
||||
librarySeen = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (name != null) {
|
||||
final ModifiableModelsProvider provider = ModifiableModelsProvider.SERVICE.getInstance();
|
||||
final LibraryTable.ModifiableModel libraryTableModifiableModel = provider.getLibraryTableModifiableModel();
|
||||
Library library = libraryTableModifiableModel.getLibraryByName(name);
|
||||
provider.disposeLibraryTableModifiableModel(libraryTableModifiableModel);
|
||||
if (library == null) {
|
||||
// we just create new project library
|
||||
library = PythonSdkTableListener.addLibrary(sdk);
|
||||
}
|
||||
if (!librarySeen) {
|
||||
model.addLibraryEntry(library);
|
||||
if (libraryName != null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
modelChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (modelChanged){
|
||||
model.commit();
|
||||
if (name != null) {
|
||||
final ModifiableModelsProvider provider = ModifiableModelsProvider.SERVICE.getInstance();
|
||||
final LibraryTable.ModifiableModel libraryTableModifiableModel = provider.getLibraryTableModifiableModel();
|
||||
Library library = libraryTableModifiableModel.getLibraryByName(name);
|
||||
provider.disposeLibraryTableModifiableModel(libraryTableModifiableModel);
|
||||
if (library == null) {
|
||||
// we just create new project library
|
||||
library = PythonSdkTableListener.addLibrary(sdk);
|
||||
}
|
||||
else {
|
||||
model.dispose();
|
||||
if (!librarySeen) {
|
||||
model.addLibraryEntry(library);
|
||||
modelChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (modelChanged){
|
||||
model.commit();
|
||||
}
|
||||
else {
|
||||
model.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void removeLibrary() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final Module module = getModule();
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
// Just remove all old facet libraries
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||
if (library != null) {
|
||||
final String libraryName = library.getName();
|
||||
if (libraryName!=null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
//PyBuiltinCache.clearInstanceCache();
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final Module module = getModule();
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
// Just remove all old facet libraries
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||
if (library != null) {
|
||||
final String libraryName = library.getName();
|
||||
if (libraryName!=null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
//PyBuiltinCache.clearInstanceCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
model.commit();
|
||||
}
|
||||
model.commit();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,9 @@ public class PythonSdkTableListener implements ApplicationComponent {
|
||||
ProjectJdkTable.Listener jdkTableListener = new ProjectJdkTable.Listener() {
|
||||
public void jdkAdded(final Sdk sdk) {
|
||||
if (sdk.getSdkType() instanceof PythonSdkType) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
addLibrary(sdk);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
addLibrary(sdk);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,40 +71,32 @@ public class PythonSdkTableListener implements ApplicationComponent {
|
||||
}
|
||||
|
||||
private static void removeLibrary(final Sdk sdk) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final LibraryTable.ModifiableModel libraryTableModel =
|
||||
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(sdk.getName()));
|
||||
if (library != null) {
|
||||
libraryTableModel.removeLibrary(library);
|
||||
}
|
||||
libraryTableModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final LibraryTable.ModifiableModel libraryTableModel =
|
||||
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(sdk.getName()));
|
||||
if (library != null) {
|
||||
libraryTableModel.removeLibrary(library);
|
||||
}
|
||||
libraryTableModel.commit();
|
||||
});
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
private static void renameLibrary(final Sdk sdk, final String previousName) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final LibraryTable.ModifiableModel libraryTableModel =
|
||||
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(previousName));
|
||||
if (library != null) {
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
model.setName(PythonFacet.getFacetLibraryName(sdk.getName()));
|
||||
model.commit();
|
||||
}
|
||||
libraryTableModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final LibraryTable.ModifiableModel libraryTableModel =
|
||||
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(previousName));
|
||||
if (library != null) {
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
model.setName(PythonFacet.getFacetLibraryName(sdk.getName()));
|
||||
model.commit();
|
||||
}
|
||||
libraryTableModel.commit();
|
||||
});
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,24 +74,22 @@ public class PyJavaTypeProvider extends PyTypeProviderBase {
|
||||
final int index = params.indexOf(param);
|
||||
if (index < 0) return null;
|
||||
final List<PyType> superMethodParameterTypes = new ArrayList<PyType>();
|
||||
PySuperMethodsSearch.search(func, context).forEach(new Processor<PsiElement>() {
|
||||
public boolean process(final PsiElement psiElement) {
|
||||
if (psiElement instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)psiElement;
|
||||
final PsiParameter[] psiParameters = method.getParameterList().getParameters();
|
||||
int javaIndex = method.hasModifierProperty(PsiModifier.STATIC) ? index : index-1; // adjust for 'self' parameter
|
||||
if (javaIndex < psiParameters.length) {
|
||||
PsiType paramType = psiParameters [javaIndex].getType();
|
||||
if (paramType instanceof PsiClassType) {
|
||||
final PsiClass psiClass = ((PsiClassType)paramType).resolve();
|
||||
if (psiClass != null) {
|
||||
superMethodParameterTypes.add(new PyJavaClassType(psiClass, false));
|
||||
}
|
||||
PySuperMethodsSearch.search(func, context).forEach(psiElement -> {
|
||||
if (psiElement instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)psiElement;
|
||||
final PsiParameter[] psiParameters = method.getParameterList().getParameters();
|
||||
int javaIndex = method.hasModifierProperty(PsiModifier.STATIC) ? index : index-1; // adjust for 'self' parameter
|
||||
if (javaIndex < psiParameters.length) {
|
||||
PsiType paramType = psiParameters [javaIndex].getType();
|
||||
if (paramType instanceof PsiClassType) {
|
||||
final PsiClass psiClass = ((PsiClassType)paramType).resolve();
|
||||
if (psiClass != null) {
|
||||
superMethodParameterTypes.add(new PyJavaClassType(psiClass, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (superMethodParameterTypes.size() > 0) {
|
||||
final PyType type = superMethodParameterTypes.get(0);
|
||||
|
||||
Reference in New Issue
Block a user