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

The following examples show how to use com.intellij.openapi.util.RecursionManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo-csharp   Source File: CSharpTypeResolveContext.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
protected List<DotNetTypeRef> getExtendTypeRefs()
{
	DotNetTypeRef[] typeRefs = myElement.getExtendTypeRefs();
	List<DotNetTypeRef> extendTypeRefs = new ArrayList<>(typeRefs.length);

	for(DotNetTypeRef typeRef : typeRefs)
	{
		DotNetTypeRef ref = RecursionManager.doPreventingRecursion(this, false, () -> GenericUnwrapTool.exchangeTypeRef(typeRef, myExtractor, myElement));
		if(ref == null)
		{
			continue;
		}
		extendTypeRefs.add(ref);
	}
	return extendTypeRefs;
}
 
Example 2
public void testError526() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());

  PsiFile psiFile = loadToPsiFile(getTestName(false) + ".java");
  assertNotNull(psiFile);

  PsiClass psiClass = PsiTreeUtil.getParentOfType(psiFile.findElementAt(myFixture.getCaretOffset()), PsiClass.class);
  assertNotNull(psiClass);

  // call augmentprovider first time
  final PsiMethod[] psiClassMethods = psiClass.getMethods();
  assertEquals(8, psiClassMethods.length);

  // change something to trigger cache drop
  WriteCommandAction.writeCommandAction(getProject(), psiFile).compute(() ->
    {
      psiClass.getModifierList().addAnnotation("java.lang.SuppressWarnings");
      return true;
    }
  );

  // call augment provider second time
  final PsiMethod[] psiClassMethods2 = psiClass.getMethods();
  assertArrayEquals(psiClassMethods, psiClassMethods2);
}
 
Example 3
Source Project: consulo   Source File: ConcurrentFactoryMap.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public V get(Object key) {
  ConcurrentMap<K, V> map = myMap;
  K k = notNull(key);
  V value = map.get(k);
  if (value == null) {
    RecursionGuard.StackStamp stamp = RecursionManager.markStack();
    //noinspection unchecked
    value = create((K)key);
    if (stamp.mayCacheNow()) {
      V v = notNull(value);
      value = ConcurrencyUtil.cacheOrGet(map, k, v);
    }
  }
  return nullize(value);
}
 
Example 4
Source Project: consulo   Source File: FactoryMap.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public V get(Object key) {
  Map<K, V> map = getMap();
  K k = notNull(key);
  V value = map.get(k);
  if (value == null) {
    RecursionGuard.StackStamp stamp = RecursionManager.markStack();
    //noinspection unchecked
    value = create((K)key);
    if (stamp.mayCacheNow()) {
      V v = notNull(value);
      map.put(k, v);
    }
  }
  return nullize(value);
}
 
Example 5
Source Project: consulo   Source File: StubBasedPsiElementBase.java    License: Apache License 2.0 6 votes vote down vote up
private ASTNode failedToBindStubToAst(@Nonnull PsiFileImpl file, @Nonnull final FileElement fileElement) {
  VirtualFile vFile = file.getVirtualFile();
  StubTree stubTree = file.getStubTree();
  final String stubString = stubTree != null ? ((PsiFileStubImpl)stubTree.getRoot()).printTree() : null;
  final String astString = RecursionManager.doPreventingRecursion("failedToBindStubToAst", true, () -> DebugUtil.treeToString(fileElement, true));

  @NonNls final String message =
          "Failed to bind stub to AST for element " + getClass() + " in " + (vFile == null ? "<unknown file>" : vFile.getPath()) + "\nFile:\n" + file + "@" + System.identityHashCode(file);

  final String creationTraces = ourTraceStubAstBinding ? dumpCreationTraces(fileElement) : null;

  List<Attachment> attachments = new ArrayList<>();
  if (stubString != null) {
    attachments.add(new Attachment("stubTree.txt", stubString));
  }
  if (astString != null) {
    attachments.add(new Attachment("ast.txt", astString));
  }
  if (creationTraces != null) {
    attachments.add(new Attachment("creationTraces.txt", creationTraces));
  }

  throw new RuntimeExceptionWithAttachments(message, attachments.toArray(Attachment.EMPTY_ARRAY));
}
 
Example 6
Source Project: consulo   Source File: FileElement.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public final AstSpine getStubbedSpine() {
  AstSpine result = myStubbedSpine;
  if (result == null) {
    PsiFileImpl file = (PsiFileImpl)getPsi();
    IStubFileElementType type = file.getElementTypeForStubBuilder();
    if (type == null) return AstSpine.EMPTY_SPINE;

    result = RecursionManager.doPreventingRecursion(file, false, () -> new AstSpine(calcStubbedDescendants(type.getBuilder())));
    if (result == null) {
      throw new StackOverflowPreventedException("Endless recursion prevented");
    }
    myStubbedSpine = result;
  }
  return result;
}
 
Example 7
Source Project: consulo-csharp   Source File: CSharpLambdaExpressionImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef toTypeRefForInference()
{
	// recursion when child lambda reference to parameter from parent lambda
	DotNetTypeRef returnType = RecursionManager.doPreventingRecursion("C# lambda return type", false, this::findPossibleReturnTypeRef);
	if(returnType == null)
	{
		returnType = DotNetTypeRef.ERROR_TYPE;
	}
	return new CSharpLambdaTypeRef(this, null, getParameterInfos(true), returnType);
}
 
Example 8
@Override
public void setUp() throws Exception {
  super.setUp();
  // Add dummy classes, which are absent in mockJDK
  myFixture.addClass("package java.util;\n  public interface NavigableMap<K,V> extends java.util.SortedMap<K,V> {}");

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 9
@Override
public void setUp() throws Exception {
  super.setUp();
  myFixture.addClass("package lombok;\npublic @interface val { }");

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 10
public void testFieldDefaultsWithNonFinal() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
  PsiModifierList modifierList = getFieldModifierListAtCaret();

  assertFalse("@FieldDefaults(makeFinal = true) should not make @NonFinal fields final", modifierList.hasModifierProperty(PsiModifier.FINAL));
}
 
Example 11
public void testFieldDefaultsPublicWithPackagePrivate() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
  PsiModifierList modifierList = getFieldModifierListAtCaret();

  assertFalse("@FieldDefaults(level = AccessLevel.PUBLIC) should not make @PackagePrivate fields public", modifierList.hasModifierProperty(PsiModifier.PUBLIC));
  assertTrue("@FieldDefaults should keep @PackagePrivate fields package-private", modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL));
}
 
Example 12
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 13
@Override
public void setUp() throws Exception {
  super.setUp();
  // Add dummy classes, which are absent in mockJDK
  myFixture.addClass("package java.util;\n  public interface NavigableMap<K,V> extends java.util.SortedMap<K,V> {}");

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 14
@Override
public void setUp() throws Exception {
  super.setUp();
  // Add dummy classes, which are absent in mockJDK
  myFixture.addClass("package java.util;\n  public interface NavigableMap<K,V> extends java.util.SortedMap<K,V> {}");

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 15
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 16
@Override
public void setUp() throws Exception {
  super.setUp();
  // Add dummy classes, which are absent in mockJDK
  myFixture.addClass("package java.util;\n  public interface NavigableSet<E> extends java.util.SortedSet<E> {}");
  myFixture.addClass("package java.util;\n  public interface NavigableMap<K,V> extends java.util.SortedMap<K,V> {}");

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 17
public void testGenericTypeDiamond296() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());

  configureClass("new java.util.concurrent.atomic.AtomicReference<>(\"abc\")");
  verifyLocalVariableType("java.util.concurrent.atomic.AtomicReference<java.lang.String>");
}
 
Example 18
@Override
public void setUp() throws Exception {
  super.setUp();
  // Add dummy classes, which are absent in mockJDK
  myFixture.addClass("package java.util;\n  public interface NavigableSet<E> extends java.util.SortedSet<E> {}");
  myFixture.addClass("package java.util;\n  public interface NavigableMap<K,V> extends java.util.SortedMap<K,V> {}");

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 19
@Override
public void setUp() throws Exception {
  super.setUp();
  final Disposable projectDisposable = myFixture.getProjectDisposable();
  final String basePath = new File(getTestDataPath(), getBasePath()).getCanonicalPath();
  VfsRootAccess.allowRootAccess(projectDisposable, basePath, new File(LOMBOK_SRC_PATH).getCanonicalPath());
  VfsRootAccess.allowRootAccess(projectDisposable, basePath, new File(OLD_LOMBOK_SRC_PATH).getCanonicalPath());

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 20
public void testFindUsageWither() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());

  final Collection<UsageInfo> usages = loadTestClass();
  assertUsages(usages, "findUsageWither.withBar", "findUsageWither.getBar");
}
 
Example 21
public void testFindUsageBuilder() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());

  final Collection<UsageInfo> usages = loadTestClass();
  assertUsages(usages, "FindUsageBuilder.builder().bar", "findUsageBuilder.getBar");
}
 
Example 22
public void testFindUsageSingularBuilder() {
  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());

  final Collection<UsageInfo> usages = loadTestClass();
  assertUsages(usages, "FindUsageSingularBuilder.builder().bar", "FindUsageSingularBuilder.builder().bars",
    "FindUsageSingularBuilder.builder().clearBars", "findUsageBuilder.getBars");
}
 
Example 23
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 24
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 25
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 26
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 27
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 28
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 29
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example 30
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}