Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2011-12-12 14:32:52 +01:00
5 changed files with 111 additions and 46 deletions
@@ -766,7 +766,16 @@ public class PluginManager {
message.append("not loaded plugins");
}
message.append("</a>");
message.append("<br>").append("<a href=\"" + ENABLE + "\">Enable ").append(faultyDescriptors.size() == 1 ? disabledPluginNames.get(faultyDescriptors.iterator().next()) : " all necessary plugins").append("</a>");
boolean possibleToEnable = true;
for (String descriptor : faultyDescriptors) {
if (disabledPluginNames.get(descriptor) == null) {
possibleToEnable = false;
break;
}
}
if (possibleToEnable) {
message.append("<br>").append("<a href=\"" + ENABLE + "\">Enable ").append(faultyDescriptors.size() == 1 ? disabledPluginNames.get(faultyDescriptors.iterator().next()) : " all necessary plugins").append("</a>");
}
message.append("<br>").append("<a href=\"" + EDIT + "\">Open plugin manager</a>");
}
if (pluginsWithoutIdFound) {
@@ -27,26 +27,38 @@ import com.intellij.pom.Navigatable;
* @author cdr
*/
public class ChangeEncodingUpdateGroup extends DefaultActionGroup {
private boolean myUpdating;
@Override
public void update(final AnActionEvent e) {
if (myUpdating) {
return;
}
VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
if (files != null && files.length > 1) {
virtualFile = null;
}
if (virtualFile != null){
if (virtualFile != null) {
Navigatable navigatable = e.getData(PlatformDataKeys.NAVIGATABLE);
if (navigatable instanceof OpenFileDescriptor) {
// prefer source to the class file
virtualFile = ((OpenFileDescriptor)navigatable).getFile();
}
}
if(virtualFile != null && !virtualFile.isInLocalFileSystem()){
if (virtualFile != null && !virtualFile.isInLocalFileSystem()) {
virtualFile = null;
}
Pair<String, Boolean> result = ChooseFileEncodingAction.update(virtualFile);
e.getPresentation().setText(result.getFirst());
e.getPresentation().setEnabled(result.getSecond());
myUpdating = true;
try {
e.getPresentation().setText(result.getFirst());
// updating the enabled state of the action can trigger the menuSelected handler, which updates the action group again
e.getPresentation().setEnabled(result.getSecond());
}
finally {
myUpdating = false;
}
}
}
@@ -17,6 +17,7 @@ package com.intellij.util.pico;
import com.intellij.util.ReflectionCache;
import com.intellij.util.containers.ConcurrentHashMap;
import com.intellij.util.containers.FList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.picocontainer.*;
@@ -24,7 +25,6 @@ import org.picocontainer.defaults.*;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
public class DefaultPicoContainer implements MutablePicoContainer, Serializable {
@@ -34,11 +34,11 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
private final Set<PicoContainer> children = new HashSet<PicoContainer>();
private final Map<Object, ComponentAdapter> componentKeyToAdapterCache = new ConcurrentHashMap<Object, ComponentAdapter>();
private final AtomicReference<LinkedHashSet<ComponentAdapter>> componentAdapters = new AtomicReference<LinkedHashSet<ComponentAdapter>>(new LinkedHashSet<ComponentAdapter>());
private final LinkedHashSetWrapper<ComponentAdapter> componentAdapters = new LinkedHashSetWrapper<ComponentAdapter>();
// Keeps track of instantiation order.
private final AtomicReference<LinkedHashSet<ComponentAdapter>> orderedComponentAdapters = new AtomicReference<LinkedHashSet<ComponentAdapter>>(new LinkedHashSet<ComponentAdapter>());
private final LinkedHashSetWrapper<ComponentAdapter> orderedComponentAdapters = new LinkedHashSetWrapper<ComponentAdapter>();
private final Map<String, ComponentAdapter> classNameToAdapter = new ConcurrentHashMap<String, ComponentAdapter>();
private final CopyOnWriteArrayList<ComponentAdapter> nonAssignableComponentAdapters = new CopyOnWriteArrayList<ComponentAdapter>();
private final AtomicReference<FList<ComponentAdapter>> nonAssignableComponentAdapters = new AtomicReference<FList<ComponentAdapter>>(FList.<ComponentAdapter>emptyList());
public DefaultPicoContainer(@NotNull ComponentAdapterFactory componentAdapterFactory, PicoContainer parent) {
this.componentAdapterFactory = componentAdapterFactory;
@@ -50,7 +50,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
}
public Collection<ComponentAdapter> getComponentAdapters() {
return Collections.unmodifiableCollection(componentAdapters.get());
return componentAdapters.getImmutableSet();
}
public Map<String, ComponentAdapter> getAssignablesCache() {
@@ -59,7 +59,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
public Collection<ComponentAdapter> getNonAssignableAdapters() {
return nonAssignableComponentAdapters;
return nonAssignableComponentAdapters.get().getReversedList();
}
@Nullable
@@ -141,51 +141,34 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
classNameToAdapter.put(classKey, componentAdapter);
}
else {
nonAssignableComponentAdapters.add(componentAdapter);
do {
FList<ComponentAdapter> oldList = nonAssignableComponentAdapters.get();
FList<ComponentAdapter> newList = oldList.prepend(componentAdapter);
if (nonAssignableComponentAdapters.compareAndSet(oldList, newList)) {
break;
}
} while (true);
}
addElement(componentAdapters, componentAdapter);
componentAdapters.add(componentAdapter);
componentKeyToAdapterCache.put(componentKey, componentAdapter);
return componentAdapter;
}
private static <T> void addElement(AtomicReference<LinkedHashSet<T>> collectionHolder, T element) {
do {
LinkedHashSet<T> oldCollection = collectionHolder.get();
if (oldCollection.contains(element)) {
return;
}
LinkedHashSet<T> newCollection = new LinkedHashSet<T>(oldCollection);
newCollection.add(element);
if (collectionHolder.compareAndSet(oldCollection, newCollection)) break;
} while (true);
}
private static <T> void removeElement(AtomicReference<LinkedHashSet<T>> collectionHolder, T element) {
do {
LinkedHashSet<T> oldCollection = collectionHolder.get();
LinkedHashSet<T> newCollection = new LinkedHashSet<T>(oldCollection);
newCollection.remove(element);
if (collectionHolder.compareAndSet(oldCollection, newCollection)) break;
} while (true);
}
public ComponentAdapter unregisterComponent(Object componentKey) {
ComponentAdapter adapter = componentKeyToAdapterCache.remove(componentKey);
removeElement(componentAdapters, adapter);
removeElement(orderedComponentAdapters, adapter);
componentAdapters.remove(adapter);
orderedComponentAdapters.remove(adapter);
return adapter;
}
private void addOrderedComponentAdapter(ComponentAdapter componentAdapter) {
addElement(orderedComponentAdapters, componentAdapter);
if (!orderedComponentAdapters.contains(componentAdapter)) {
orderedComponentAdapters.add(componentAdapter);
}
}
public List getComponentInstances() throws PicoException {
@@ -198,7 +181,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
}
Map<ComponentAdapter, Object> adapterToInstanceMap = new HashMap<ComponentAdapter, Object>();
for (final ComponentAdapter componentAdapter : componentAdapters.get()) {
for (final ComponentAdapter componentAdapter : componentAdapters.getImmutableSet()) {
if (ReflectionCache.isAssignable(componentType, componentAdapter.getComponentImplementation())) {
Object componentInstance = getInstance(componentAdapter);
adapterToInstanceMap.put(componentAdapter, componentInstance);
@@ -210,7 +193,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
}
List<Object> result = new ArrayList<Object>();
for (ComponentAdapter componentAdapter : orderedComponentAdapters.get()) {
for (ComponentAdapter componentAdapter : orderedComponentAdapters.getImmutableSet()) {
final Object componentInstance = adapterToInstanceMap.get(componentAdapter);
if (componentInstance != null) {
// may be null in the case of the "implicit" adapter
@@ -240,7 +223,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
@Nullable
private Object getInstance(ComponentAdapter componentAdapter) {
final boolean isLocal = componentAdapters.get().contains(componentAdapter);
final boolean isLocal = componentAdapters.contains(componentAdapter);
if (isLocal) {
return getLocalInstance(componentAdapter);
@@ -359,4 +342,50 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
public PicoContainer getParent() {
return parent;
}
private static class LinkedHashSetWrapper<T> {
private volatile Set<T> immutableSet;
private final LinkedHashSet<T> synchronizedSet = new LinkedHashSet<T>();
private final ConcurrentHashMap<T, T> concurrentSet = new ConcurrentHashMap<T, T>();
public boolean contains(@Nullable T element) {
return element != null && concurrentSet.containsKey(element);
}
public void add(@NotNull T element) {
synchronized (synchronizedSet) {
immutableSet = null;
synchronizedSet.add(element);
concurrentSet.put(element, element);
}
}
public void remove(@Nullable T element) {
if (element == null) return;
synchronized (synchronizedSet) {
immutableSet = null;
synchronizedSet.remove(element);
concurrentSet.remove(element);
}
}
@NotNull
public Set<T> getImmutableSet() {
Set<T> res = immutableSet;
if (res == null) {
synchronized (synchronizedSet) {
res = immutableSet;
if (res == null) {
res = Collections.unmodifiableSet((Set<T>)synchronizedSet.clone());
immutableSet = res;
}
}
}
return res;
}
}
}
@@ -70,4 +70,9 @@ public class DateInfo
}
private final Calendar calendar;
@Override
public String toString() {
return new SimpleDateFormat().format(calendar.getTime());
}
}
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
*/
public class SpringLoadedPositionManager implements PositionManager {
private static final Pattern GENERATED_CLASS_NAME = Pattern.compile(".*\\$\\$[A-Za-z0-9]{8}");
private static final Pattern GENERATED_CLASS_NAME = Pattern.compile("\\$\\$[A-Za-z0-9]{8}");
private final DebugProcess myDebugProcess;
@@ -158,6 +158,16 @@ public class SpringLoadedPositionManager implements PositionManager {
return myDebugProcess.getRequestsManager().createClassPrepareRequest(requestor, className + "*");
}
private static boolean isSpringLoadedGeneratedClass(ReferenceType ownerClass, ReferenceType aClass) {
String name = aClass.name();
String ownerClassName = ownerClass.name();
// return name == ownerClassName + "$$" + /[A-Za-z0-9]{8}/
return name.length() == ownerClassName.length() + 2 + 8
&& name.startsWith(ownerClassName)
&& GENERATED_CLASS_NAME.matcher(name.substring(ownerClassName.length())).matches();
}
@Nullable
private static List<ReferenceType> findNested(ReferenceType fromClass, SourcePosition classPosition) {
if (!fromClass.isPrepared()) return null;
@@ -169,7 +179,7 @@ public class SpringLoadedPositionManager implements PositionManager {
for (ReferenceType nested : nestedTypes) {
if (!nested.isPrepared()) continue;
if (GENERATED_CLASS_NAME.matcher(nested.name()).matches()) {
if (isSpringLoadedGeneratedClass(fromClass, nested)) {
if (springLoadedGeneratedClasses.size() > 0 && !springLoadedGeneratedClasses.get(0).name().equals(nested.name())) {
springLoadedGeneratedClasses.clear(); // Only latest generated classes should be used.
}