Java Code Examples for com.intellij.util.ObjectUtil#NULL

The following examples show how to use com.intellij.util.ObjectUtil#NULL . 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: WizardSessionTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Test
public void testVisibleStep() {
  List<WizardStep<Object>> steps = new ArrayList<>();
  steps.add(new StepStub<>("first", true));
  steps.add(new StepStub<>("second", true));
  steps.add(new StepStub<>("third", false));
  steps.add(new StepStub<>("fourth", true));

  WizardSession<Object> session = new WizardSession<>(ObjectUtil.NULL, steps);

  assertTrue(session.hasNext());

  assertEquals(session.next().toString(), "first");
  assertEquals(session.next().toString(), "second");
  assertEquals(session.next().toString(), "fourth");


  WizardStep<Object> prev = session.prev();

  assertEquals(prev.toString(), "second");
}
 
Example 2
Source File: ApplicationDefaultStoreCache.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public Element findDefaultStoreElement(@Nonnull Class<?> clazz, @Nonnull String path) {
  Object result = myUrlCache.computeIfAbsent(Pair.create(clazz.getClassLoader(), path), pair -> {
    URL resource = pair.getFirst().getResource(pair.getSecond());

    if(resource != null) {
      try {
        Document document = JDOMUtil.loadDocument(resource);
        Element rootElement = document.getRootElement();
        rootElement.detach();
        return rootElement;
      }
      catch (JDOMException | IOException e) {
        throw new RuntimeException(e);
      }
    }

    return ObjectUtil.NULL;
  });

  return result == ObjectUtil.NULL ? null : (Element)result;
}
 
Example 3
Source File: PsiPackageManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public PsiPackage findPackage(@Nonnull String qualifiedName, @Nonnull Class<? extends ModuleExtension> extensionClass) {
  ConcurrentMap<String, Object> map = myPackageCache.get(extensionClass);
  if (map != null) {
    final Object value = map.get(qualifiedName);
    // if we processed - but not found package
    if (value == ObjectUtil.NULL) {
      return null;
    }
    else if (value != null) {
      return (PsiPackage)value;
    }
  }

  PsiPackage newPackage = createPackage(qualifiedName, extensionClass);

  Object valueForInsert = ObjectUtil.notNull(newPackage, ObjectUtil.NULL);

  myPackageCache.computeIfAbsent(extensionClass, aClass -> new ConcurrentHashMap<>()).putIfAbsent(qualifiedName, valueForInsert);

  return newPackage;
}
 
Example 4
Source File: Unity3dPackageOrderEntry.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getEqualObject()
{
	Unity3dRootModuleExtension extension = myModuleRootLayer.getExtension(Unity3dRootModuleExtension.class);
	if(extension == null)
	{
		return ObjectUtil.NULL;
	}
	return extension.getSdk();
}
 
Example 5
Source File: CSharpNamespaceResolveContext.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
@SuppressWarnings("unchecked")
public CSharpElementGroup<CSharpMethodDeclaration> findExtensionMethodGroupByName(@Nonnull String name)
{
	Object o = myExtensionGroups.get(name);
	return o == ObjectUtil.NULL ? null : (CSharpElementGroup<CSharpMethodDeclaration>) o;
}
 
Example 6
Source File: CSharpCompositeTypeDeclaration.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
public static CSharpCompositeTypeDeclaration findCompositeType(@Nonnull CSharpTypeDeclaration parent)
{
	Object cachedValue = CachedValuesManager.getCachedValue(parent, () -> CachedValueProvider.Result.create(findCompositeTypeImpl(parent), PsiModificationTracker
			.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
	return cachedValue == ObjectUtil.NULL ? null : (CSharpCompositeTypeDeclaration) cachedValue;
}
 
Example 7
Source File: BaseDataManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T getData(@Nonnull Key<T> dataId) {
  if (ourSafeKeys.contains(dataId)) {
    Object answer = myCachedData.get(dataId);
    if (answer == null) {
      answer = doGetData(dataId);
      myCachedData.put(dataId, answer == null ? ObjectUtil.NULL : answer);
    }
    return answer != ObjectUtil.NULL ? (T)answer : null;
  }
  else {
    return doGetData(dataId);
  }
}
 
Example 8
Source File: NullableLazyKey.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public final T getValue(H h) {
  T data = h.getUserData(this);
  if (data == null) {
    data = myFunction.fun(h);
    h.putUserData(this, data == null ? (T)ObjectUtil.NULL : data);
  }
  return data == ObjectUtil.NULL ? null : data;
}
 
Example 9
Source File: ExtensionPointImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("unchecked")
public <K extends T> K findExtension(Class<K> extensionClass) {
  Map<Class, Object> value = myInstanceOfCacheValue.getValue();

  Object result = value.computeIfAbsent(extensionClass, aClass -> {
    K instance = ContainerUtil.findInstance(getExtensionList(), extensionClass);
    return instance == null ? ObjectUtil.NULL : instance;
  });

  return result == ObjectUtil.NULL ? null : (K)result;
}
 
Example 10
Source File: WizardSessionTest.java    From consulo with Apache License 2.0 3 votes vote down vote up
@Test
public void testStepEnterAndLeave() {
  StepStub<Object> first, second, third, fourth;

  List<WizardStep<Object>> steps = new ArrayList<>();
  steps.add(first = new StepStub<>("first", true));
  steps.add(second = new StepStub<>("second", true));
  steps.add(third = new StepStub<>("third", false));
  steps.add(fourth = new StepStub<>("fourth", true));

  WizardSession<Object> session = new WizardSession<>(ObjectUtil.NULL, steps);

  assertTrue(session.hasNext());

  session.next();

  assertTrue(first.myStepEnter);

  session.next();

  assertTrue(first.myStepLeave);

  assertTrue(second.myStepEnter);

  session.next();

  assertTrue(second.myStepLeave);

  assertTrue(fourth.myStepEnter);

  assertFalse(third.myStepEnter);

  assertFalse(third.myStepLeave);
}
 
Example 11
Source File: WizardSessionTest.java    From consulo with Apache License 2.0 3 votes vote down vote up
@Test
public void testPrevPrev() {
  List<WizardStep<Object>> steps = new ArrayList<>();
  steps.add(new StepStub<>("first", true));
  steps.add(new StepStub<>("second", true));
  steps.add(new StepStub<>("third", false));
  steps.add(new StepStub<>("fourth", true));

  WizardSession<Object> session = new WizardSession<>(ObjectUtil.NULL, steps);

  assertTrue(session.hasNext());

  session.next();
  session.next();

  WizardStep<Object> _3step = session.next();

  assertEquals(_3step.toString(), "fourth");

  WizardStep<Object> prev = session.prev();

  assertEquals(prev.toString(), "second");

  WizardStep<Object> prev2 = session.prev();

  assertEquals(prev2.toString(), "first");
}