Java Code Examples for com.intellij.openapi.util.UserDataHolderBase

The following are top voted examples for showing how to use com.intellij.openapi.util.UserDataHolderBase. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: consulo-csharp   File: AttributeByNameSelector.java   View source code 6 votes vote down vote up
@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));
	}
}
 
Example 2
Project: intellij-ce-playground   File: ExternalDiffTool.java   View source code 5 votes vote down vote up
@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;
}
 
Example 3
Project: intellij-ce-playground   File: LeakHunter.java   View source code 5 votes vote down vote up
/**
 * 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;
    }
  });
}
 
Example 4
Project: intellij-ce-playground   File: DebugUtil.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 5
Project: tools-idea   File: DebugUtil.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 6
Project: consulo-dotnet   File: BaseDotNetLogicView.java   View source code 5 votes vote down vote up
@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);
}
 
Example 7
Project: consulo-dotnet   File: LimitableDotNetLogicValueView.java   View source code 5 votes vote down vote up
@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);
	}
}
 
Example 8
Project: consulo   File: ExternalDiffTool.java   View source code 5 votes vote down vote up
@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;
}
 
Example 9
Project: consulo   File: DebugUtil.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 10
Project: intellij-ce-playground   File: DataNode.java   View source code 4 votes vote down vote up
private void readObject(ObjectInputStream in)
  throws IOException, ClassNotFoundException {
  in.defaultReadObject();
  myChildrenView = Collections.unmodifiableList(myChildren);
  myUserData = new UserDataHolderBase();
}
 
Example 11
Project: intellij-ce-playground   File: DataContextWrapper.java   View source code 4 votes vote down vote up
public DataContextWrapper(@NotNull DataContext delegate) {
  myDelegate = delegate;
  myDataHolder = delegate instanceof UserDataHolder ? (UserDataHolder) delegate : new UserDataHolderBase();
}
 
Example 12
Project: intellij-ce-playground   File: RemoteConnectionCredentialsWrapper.java   View source code 4 votes vote down vote up
public void setVagrantConnectionType(VagrantBasedCredentialsHolder vagrantBasedCredentials) {
  myCredentialsTypeHolder = new UserDataHolderBase();
  myCredentialsTypeHolder.putUserData(VAGRANT_BASED_CREDENTIALS, vagrantBasedCredentials);
}
 
Example 13
Project: intellij-ce-playground   File: RemoteConnectionCredentialsWrapper.java   View source code 4 votes vote down vote up
public void setPlainSshCredentials(RemoteCredentialsHolder credentials) {
  myCredentialsTypeHolder = new UserDataHolderBase();
  myCredentialsTypeHolder.putUserData(PLAIN_SSH_CREDENTIALS, credentials);
}
 
Example 14
Project: intellij-ce-playground   File: RemoteConnectionCredentialsWrapper.java   View source code 4 votes vote down vote up
public void setWebDeploymentCredentials(WebDeploymentCredentialsHolder webDeploymentCredentials) {
  myCredentialsTypeHolder = new UserDataHolderBase();
  myCredentialsTypeHolder.putUserData(WEB_DEPLOYMENT_BASED_CREDENTIALS, webDeploymentCredentials);
}
 
Example 15
Project: intellij-ce-playground   File: RemoteConnectionCredentialsWrapper.java   View source code 4 votes vote down vote up
public void setDockerDeploymentCredentials(DockerCredentialsHolder credentials) {
  myCredentialsTypeHolder = new UserDataHolderBase();
  myCredentialsTypeHolder.putUserData(DOCKER_CREDENTIALS, credentials);
}
 
Example 16
Project: tools-idea   File: IncProjectBuilder.java   View source code 4 votes vote down vote up
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;
      }
    }
  });
}
 
Example 17
Project: tools-idea   File: LeakHunter.java   View source code 4 votes vote down vote up
@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();
  }
}
 
Example 18
Project: consulo-dotnet   File: DotNetLogicValueView.java   View source code 4 votes vote down vote up
void computeChildren(@NotNull UserDataHolderBase dataHolder,
@NotNull DotNetDebugContext debugContext,
@NotNull DotNetAbstractVariableValueNode parentNode,
@NotNull DotNetStackFrameProxy frameProxy,
@Nullable DotNetValueProxy value,
@NotNull XCompositeNode node);
 
Example 19
Project: consulo   File: LeakHunter.java   View source code 4 votes vote down vote up
@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();
  }
}
 
Example 20
Project: consulo   File: DataContextWrapper.java   View source code 4 votes vote down vote up
public DataContextWrapper(@Nonnull DataContext delegate) {
  myDelegate = delegate;
  myDataHolder = delegate instanceof UserDataHolder ? (UserDataHolder) delegate : new UserDataHolderBase();
}
 
Example 21
Project: consulo   File: CredentialsType.java   View source code 4 votes vote down vote up
public T getCredentials(UserDataHolderBase dataHolder) {
  return dataHolder.getUserData(getCredentialsKey());
}
 
Example 22
Project: consulo   File: CredentialsType.java   View source code 4 votes vote down vote up
public void putCredentials(UserDataHolderBase dataHolder, T credentials) {
  dataHolder.putUserData(getCredentialsKey(), credentials);
}
 
Example 23
Project: consulo   File: RemoteConnectionCredentialsWrapper.java   View source code 4 votes vote down vote up
public <C> void setCredentials(Key<C> key, C credentials) {
  myCredentialsTypeHolder = new UserDataHolderBase();
  myCredentialsTypeHolder.putUserData(key, credentials);
}
 
Example 24
Project: consulo   File: RemoteConnectionCredentialsWrapper.java   View source code 3 votes vote down vote up
public void copyTo(final RemoteConnectionCredentialsWrapper copy) {
  copy.myCredentialsTypeHolder = new UserDataHolderBase();

  Pair<Object, CredentialsType> credentialsAndProvider = getCredentialsAndType();

  credentialsAndProvider.getSecond().putCredentials(copy.myCredentialsTypeHolder, credentialsAndProvider.getFirst());
}