@NotNull @Override @RequiredReadAction public Collection<PsiElement> doSelectElement(@NotNull CSharpResolveContext context, boolean deep) { if(myNameWithAt.isEmpty()) { return Collections.emptyList(); } UserDataHolderBase options = new UserDataHolderBase(); options.putUserData(BaseDotNetNamespaceAsElement.FILTER, DotNetNamespaceAsElement.ChildrenFilter.ONLY_ELEMENTS); if(myNameWithAt.charAt(0) == '@') { return context.findByName(myNameWithAt.substring(1, myNameWithAt.length()), deep, options); } else { Collection<PsiElement> withoutSuffix = context.findByName(myNameWithAt, deep, options); Collection<PsiElement> array = ContainerUtil2.concat(withoutSuffix, context.findByName(myNameWithAt + AttributeSuffix, deep, options)); return ContainerUtil.findAll(array, element -> element instanceof CSharpTypeDeclaration && DotNetInheritUtil.isAttribute((DotNetTypeDeclaration) element)); } }
@NotNull private static List<DiffRequest> collectRequests(@Nullable Project project, @NotNull final DiffRequestChain chain, @NotNull ProgressIndicator indicator) { List<DiffRequest> requests = new ArrayList<DiffRequest>(); UserDataHolderBase context = new UserDataHolderBase(); List<String> errorRequests = new ArrayList<String>(); // TODO: show all changes on explicit selection List<? extends DiffRequestProducer> producers = Collections.singletonList(chain.getRequests().get(chain.getIndex())); for (DiffRequestProducer producer : producers) { try { requests.add(producer.process(context, indicator)); } catch (DiffRequestProducerException e) { LOG.warn(e); errorRequests.add(producer.getName()); } } if (!errorRequests.isEmpty()) { new Notification("diff", "Can't load some changes", StringUtil.join(errorRequests, "<br>"), NotificationType.ERROR).notify(project); } return requests; }
/** * Checks if there is a memory leak if an object of type {@code suspectClass} is strongly accessible via references from the {@code root} object. */ @TestOnly public static <T> void checkLeak(@NotNull Collection<Object> roots, @NotNull Class<T> suspectClass, @Nullable final Processor<? super T> isReallyLeak) throws AssertionError { if (SwingUtilities.isEventDispatchThread()) { UIUtil.dispatchAllInvocationEvents(); } else { UIUtil.pump(); } PersistentEnumeratorBase.clearCacheForTests(); walkObjects(suspectClass, roots, new Processor<BackLink>() { @Override public boolean process(BackLink backLink) { UserDataHolder leaked = (UserDataHolder)backLink.value; if (((UserDataHolderBase)leaked).replace(REPORTED_LEAKED, null, Boolean.TRUE) && (isReallyLeak == null || isReallyLeak.process((T)leaked))) { String place = leaked instanceof Project ? PlatformTestCase.getCreationPlace((Project)leaked) : ""; System.out.println("Leaked object found:" + leaked + "; hash: " + System.identityHashCode(leaked) + "; place: " + place); while (backLink != null) { String valueStr; try { valueStr = backLink.value instanceof FList ? "FList" : backLink.value instanceof Collection ? "Collection" : String.valueOf(backLink.value); } catch (Throwable e) { valueStr = "(" + e.getMessage() + " while computing .toString())"; } System.out.println("-->" + backLink.field + "; Value: " + valueStr + "; " + backLink.value.getClass()); backLink = backLink.backLink; } System.out.println(";-----"); throw new AssertionError(); } return true; } }); }
private static void treeToBufferWithUserData(Appendable buffer, PsiElement root, int indent, boolean skipWhiteSpaces) { if (skipWhiteSpaces && root instanceof PsiWhiteSpace) return; StringUtil.repeatSymbol(buffer, ' ', indent); try { if (root instanceof CompositeElement) { buffer.append(root.toString()); } else { final String text = fixWhiteSpaces(root.getText()); buffer.append(root.toString()).append("('").append(text).append("')"); } buffer.append(((UserDataHolderBase)root).getUserDataString()); buffer.append("\n"); PsiElement[] children = root.getChildren(); for (PsiElement child : children) { treeToBufferWithUserData(buffer, child, indent + 2, skipWhiteSpaces); } if (children.length == 0) { StringUtil.repeatSymbol(buffer, ' ', indent + 2); buffer.append("<empty list>\n"); } } catch (IOException e) { LOG.error(e); } }
@Override public void computeChildren(@NotNull UserDataHolderBase dataHolder, @NotNull DotNetDebugContext debugContext, @NotNull DotNetAbstractVariableValueNode parentNode, @NotNull DotNetStackFrameProxy frameProxy, @Nullable DotNetValueProxy value, @NotNull XCompositeNode node) { XValueChildrenList childrenList = new XValueChildrenList(); computeChildrenImpl(debugContext, parentNode, frameProxy, value, childrenList); node.addChildren(childrenList, true); }
@Override @SuppressWarnings("unchecked") public void computeChildren(@NotNull UserDataHolderBase dataHolder, @NotNull DotNetDebugContext debugContext, @NotNull DotNetAbstractVariableValueNode parentNode, @NotNull DotNetStackFrameProxy frameProxy, @Nullable DotNetValueProxy oldValue, @NotNull XCompositeNode node) { if(oldValue == null || !isMyValue(oldValue)) { node.setErrorMessage("No value"); return; } T value = (T) oldValue; final int length = getSize(value); final int startIndex = ObjectUtil.notNull(dataHolder.getUserData(ourLastIndex), 0); XValueChildrenList childrenList = new XValueChildrenList(); int max = Math.min(startIndex + XCompositeNode.MAX_CHILDREN_TO_SHOW, length); for(int i = startIndex; i < max; i++) { childrenList.add(createChildValue(i, debugContext, frameProxy, value)); } dataHolder.putUserData(ourLastIndex, max); node.addChildren(childrenList, true); if(length > max) { node.tooManyChildren(length - max); } }
@Nonnull private static List<DiffRequest> collectRequests(@javax.annotation.Nullable Project project, @Nonnull final DiffRequestChain chain, @Nonnull ProgressIndicator indicator) { List<DiffRequest> requests = new ArrayList<DiffRequest>(); UserDataHolderBase context = new UserDataHolderBase(); List<String> errorRequests = new ArrayList<String>(); // TODO: show all changes on explicit selection List<? extends DiffRequestProducer> producers = Collections.singletonList(chain.getRequests().get(chain.getIndex())); for (DiffRequestProducer producer : producers) { try { requests.add(producer.process(context, indicator)); } catch (DiffRequestProducerException e) { LOG.warn(e); errorRequests.add(producer.getName()); } } if (!errorRequests.isEmpty()) { new Notification("diff", "Can't load some changes", StringUtil.join(errorRequests, "<br>"), NotificationType.ERROR).notify(project); } return requests; }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); myChildrenView = Collections.unmodifiableList(myChildren); myUserData = new UserDataHolderBase(); }
public DataContextWrapper(@NotNull DataContext delegate) { myDelegate = delegate; myDataHolder = delegate instanceof UserDataHolder ? (UserDataHolder) delegate : new UserDataHolderBase(); }
public void setVagrantConnectionType(VagrantBasedCredentialsHolder vagrantBasedCredentials) { myCredentialsTypeHolder = new UserDataHolderBase(); myCredentialsTypeHolder.putUserData(VAGRANT_BASED_CREDENTIALS, vagrantBasedCredentials); }
public void setPlainSshCredentials(RemoteCredentialsHolder credentials) { myCredentialsTypeHolder = new UserDataHolderBase(); myCredentialsTypeHolder.putUserData(PLAIN_SSH_CREDENTIALS, credentials); }
public void setWebDeploymentCredentials(WebDeploymentCredentialsHolder webDeploymentCredentials) { myCredentialsTypeHolder = new UserDataHolderBase(); myCredentialsTypeHolder.putUserData(WEB_DEPLOYMENT_BASED_CREDENTIALS, webDeploymentCredentials); }
public void setDockerDeploymentCredentials(DockerCredentialsHolder credentials) { myCredentialsTypeHolder = new UserDataHolderBase(); myCredentialsTypeHolder.putUserData(DOCKER_CREDENTIALS, credentials); }
private static CompileContext createContextWrapper(final CompileContext delegate) { final ClassLoader loader = delegate.getClass().getClassLoader(); final UserDataHolderBase localDataHolder = new UserDataHolderBase(); final Set<Object> deletedKeysSet = new ConcurrentHashSet<Object>(); final Class<UserDataHolder> dataHolderInterface = UserDataHolder.class; final Class<MessageHandler> messageHandlerInterface = MessageHandler.class; return (CompileContext)Proxy.newProxyInstance(loader, new Class[]{CompileContext.class}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final Class<?> declaringClass = method.getDeclaringClass(); if (dataHolderInterface.equals(declaringClass)) { final Object firstArgument = args[0]; if (!(firstArgument instanceof GlobalContextKey)) { final boolean isWriteOperation = args.length == 2 /*&& void.class.equals(method.getReturnType())*/; if (isWriteOperation) { if (args[1] == null) { deletedKeysSet.add(firstArgument); } else { deletedKeysSet.remove(firstArgument); } } else { if (deletedKeysSet.contains(firstArgument)) { return null; } } final Object result = method.invoke(localDataHolder, args); if (isWriteOperation || result != null) { return result; } } } else if (messageHandlerInterface.equals(declaringClass)) { final BuildMessage msg = (BuildMessage)args[0]; if (msg.getKind() == BuildMessage.Kind.ERROR) { Utils.ERRORS_DETECTED_KEY.set(localDataHolder, Boolean.TRUE); } } try { return method.invoke(delegate, args); } catch (InvocationTargetException e) { final Throwable targetEx = e.getTargetException(); if (targetEx instanceof ProjectBuildException) { throw targetEx; } throw e; } } }); }
@TestOnly public static <T> void checkLeak(@NotNull Object root, @NotNull Class<T> suspectClass, @Nullable final Processor<? super T> isReallyLeak) throws AssertionError { if (SwingUtilities.isEventDispatchThread()) { UIUtil.dispatchAllInvocationEvents(); } else { UIUtil.pump(); } PersistentEnumerator.clearCacheForTests(); toVisit.clear(); visited.clear(); toVisit.push(new BackLink(root.getClass(), root, null,null)); try { walkObjects(suspectClass, new Processor<BackLink>() { @Override public boolean process(BackLink backLink) { UserDataHolder leaked = (UserDataHolder)backLink.value; if (((UserDataHolderBase)leaked).replace(REPORTED_LEAKED,null,Boolean.TRUE) && (isReallyLeak == null || isReallyLeak.process((T)leaked))) { String place = leaked instanceof Project ? PlatformTestCase.getCreationPlace((Project)leaked) : ""; System.out.println("Leaked object found:" + leaked + "; hash: "+System.identityHashCode(leaked) + "; place: "+ place); while (backLink != null) { String valueStr; try { valueStr = String.valueOf(backLink.value); } catch (Throwable e) { valueStr = "("+e.getMessage()+" while computing .toString())"; } System.out.println("-->"+backLink.field+"; Value: "+ valueStr +"; "+backLink.aClass); backLink = backLink.backLink; } System.out.println(";-----"); throw new AssertionError(); } return true; } }); } finally { visited.clear(); ((THashSet)visited).compact(); toVisit.clear(); toVisit.trimToSize(); } }
void computeChildren(@NotNull UserDataHolderBase dataHolder, @NotNull DotNetDebugContext debugContext, @NotNull DotNetAbstractVariableValueNode parentNode, @NotNull DotNetStackFrameProxy frameProxy, @Nullable DotNetValueProxy value, @NotNull XCompositeNode node);
@TestOnly public static <T> void checkLeak(@Nonnull Object root, @Nonnull Class<T> suspectClass, @javax.annotation.Nullable final Processor<T> isReallyLeak) throws AssertionError { if (SwingUtilities.isEventDispatchThread()) { UIUtil.dispatchAllInvocationEvents(); } else { UIUtil.pump(); } PersistentEnumerator.clearCacheForTests(); toVisit.clear(); visited.clear(); toVisit.push(new BackLink(root.getClass(), root, null,null)); try { walkObjects(suspectClass, new Processor<BackLink>() { @Override public boolean process(BackLink backLink) { UserDataHolder leaked = (UserDataHolder)backLink.value; if (((UserDataHolderBase)leaked).replace(REPORTED_LEAKED,null,Boolean.TRUE) && (isReallyLeak == null || isReallyLeak.process((T)leaked))) { String place = leaked instanceof Project ? PlatformTestCase.getCreationPlace((Project)leaked) : ""; System.out.println("Leaked object found:" + leaked + "; hash: "+System.identityHashCode(leaked) + "; place: "+ place); while (backLink != null) { String valueStr; try { valueStr = String.valueOf(backLink.value); } catch (Throwable e) { valueStr = "("+e.getMessage()+" while computing .toString())"; } System.out.println("-->"+backLink.field+"; Value: "+ valueStr +"; "+backLink.aClass); backLink = backLink.backLink; } System.out.println(";-----"); throw new AssertionError(); } return true; } }); } finally { visited.clear(); ((THashSet)visited).compact(); toVisit.clear(); toVisit.trimToSize(); } }
public DataContextWrapper(@Nonnull DataContext delegate) { myDelegate = delegate; myDataHolder = delegate instanceof UserDataHolder ? (UserDataHolder) delegate : new UserDataHolderBase(); }
public T getCredentials(UserDataHolderBase dataHolder) { return dataHolder.getUserData(getCredentialsKey()); }
public void putCredentials(UserDataHolderBase dataHolder, T credentials) { dataHolder.putUserData(getCredentialsKey(), credentials); }
public <C> void setCredentials(Key<C> key, C credentials) { myCredentialsTypeHolder = new UserDataHolderBase(); myCredentialsTypeHolder.putUserData(key, credentials); }
public void copyTo(final RemoteConnectionCredentialsWrapper copy) { copy.myCredentialsTypeHolder = new UserDataHolderBase(); Pair<Object, CredentialsType> credentialsAndProvider = getCredentialsAndType(); credentialsAndProvider.getSecond().putCredentials(copy.myCredentialsTypeHolder, credentialsAndProvider.getFirst()); }