com.intellij.openapi.util.RecursionManager Java Examples

The following examples show how to use com.intellij.openapi.util.RecursionManager. 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 File: ExceptionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #2
Source File: CSharpTypeResolveContext.java    From consulo-csharp with 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 #3
Source File: ConcurrentFactoryMap.java    From consulo with 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 File: FactoryMap.java    From consulo with 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 File: StubBasedPsiElementBase.java    From consulo with 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 File: FileElement.java    From consulo with 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 File: ResolveCache.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private <TRef extends PsiReference, TResult> TResult resolve(@Nonnull final TRef ref,
                                                             @Nonnull final AbstractResolver<? super TRef, TResult> resolver,
                                                             boolean needToPreventRecursion,
                                                             final boolean incompleteCode,
                                                             boolean isPoly,
                                                             boolean isPhysical) {
  ProgressIndicatorProvider.checkCanceled();
  if (isPhysical) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
  }
  int index = getIndex(incompleteCode, isPoly);
  Map<TRef, TResult> map = getMap(isPhysical, index);
  TResult result = map.get(ref);
  if (result != null) {
    return result;
  }

  RecursionGuard.StackStamp stamp = RecursionManager.markStack();
  result = needToPreventRecursion
           ? RecursionManager.doPreventingRecursion(Trinity.create(ref, incompleteCode, isPoly), true, () -> resolver.resolve(ref, incompleteCode))
           : resolver.resolve(ref, incompleteCode);
  if (result instanceof ResolveResult) {
    ensureValidPsi((ResolveResult)result);
  }
  else if (result instanceof ResolveResult[]) {
    ensureValidResults((ResolveResult[])result);
  }
  else if (result instanceof PsiElement) {
    PsiUtilCore.ensureValid((PsiElement)result);
  }

  if (stamp.mayCacheNow()) {
    cache(ref, map, result);
  }
  return result;
}
 
Example #8
Source File: ResolveCache.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public <T extends PsiPolyVariantReference> ResolveResult[] resolveWithCaching(@Nonnull final T ref,
                                                                              @Nonnull final PolyVariantContextResolver<T> resolver,
                                                                              boolean needToPreventRecursion,
                                                                              final boolean incompleteCode,
                                                                              @Nonnull final PsiFile containingFile) {
  ProgressIndicatorProvider.checkCanceled();
  ApplicationManager.getApplication().assertReadAccessAllowed();

  boolean physical = containingFile.isPhysical();
  int index = getIndex(incompleteCode, true);
  Map<T, ResolveResult[]> map = getMap(physical, index);
  ResolveResult[] result = map.get(ref);
  if (result != null) {
    return result;
  }

  RecursionGuard.StackStamp stamp = RecursionManager.markStack();
  result = needToPreventRecursion
           ? RecursionManager.doPreventingRecursion(Pair.create(ref, incompleteCode), true, () -> resolver.resolve(ref, containingFile, incompleteCode))
           : resolver.resolve(ref, containingFile, incompleteCode);
  if (result != null) {
    ensureValidResults(result);
  }

  if (stamp.mayCacheNow()) {
    cache(ref, map, result);
  }
  return result == null ? ResolveResult.EMPTY_ARRAY : result;
}
 
Example #9
Source File: DelombokValueActionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #10
Source File: DelombokBuilderActionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #11
Source File: FieldNameConstantsOldTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #12
Source File: SuperBuilderInspectionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #13
Source File: BuilderInspectionTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #14
Source File: LombokVarPostfixTemplateTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #15
Source File: FieldDefaultsTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #16
Source File: AccessorsTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #17
Source File: FieldNameConstantsTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #18
Source File: LombokUsageTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #19
Source File: LombokUsageTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #20
Source File: SemServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public <T extends SemElement> List<T> getSemElements(final SemKey<T> key, @Nonnull final PsiElement psi) {
  List<T> cached = _getCachedSemElements(key, true, psi);
  if (cached != null) {
    return cached;
  }

  ensureInitialized();

  RecursionGuard.StackStamp stamp = RecursionManager.createGuard("semService").markStack();

  LinkedHashSet<T> result = new LinkedHashSet<>();
  final Map<SemKey, List<SemElement>> map = new THashMap<>();
  for (final SemKey each : key.getInheritors()) {
    List<SemElement> list = createSemElements(each, psi);
    map.put(each, list);
    result.addAll((List<T>)list);
  }

  if (stamp.mayCacheNow()) {
    final SemCacheChunk persistent = getOrCreateChunk(psi);
    for (SemKey semKey : map.keySet()) {
      persistent.putSemElements(semKey, map.get(semKey));
    }
  }

  return new ArrayList<>(result);
}
 
Example #21
Source File: BuilderSingularTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #22
Source File: CSharpLambdaExpressionImpl.java    From consulo-csharp with 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 #23
Source File: SuperBuilderTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #24
Source File: ValModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #25
Source File: FieldDefaultsModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #26
Source File: FieldDefaultsModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #27
Source File: FieldNameConstantsTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  //TODO disable assertions for the moment
  RecursionManager.disableMissedCacheAssertions(myFixture.getProjectDisposable());
}
 
Example #28
Source File: BuilderToBuilderTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #29
Source File: BuilderTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #30
Source File: ValTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

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