Java Code Examples for com.intellij.util.ObjectUtil#notNull()

The following examples show how to use com.intellij.util.ObjectUtil#notNull() . 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: LocalFileSystemImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Set<WatchRequest> replaceWatchedRoots(@Nonnull Collection<WatchRequest> watchRequests,
                                             @Nullable Collection<String> recursiveRoots,
                                             @Nullable Collection<String> flatRoots) {
  recursiveRoots = ObjectUtil.notNull(recursiveRoots, Collections.emptyList());
  flatRoots = ObjectUtil.notNull(flatRoots, Collections.emptyList());

  Set<WatchRequest> result = new HashSet<>();
  synchronized (myLock) {
    boolean update = doAddRootsToWatch(recursiveRoots, flatRoots, result) |
                     doRemoveWatchedRoots(watchRequests);
    if (update) {
      myNormalizedTree = null;
      setUpFileWatcher();
    }
  }
  return result;
}
 
Example 2
Source File: ModuleImportProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Will execute module importing. Will show popup for selecting import providers if more that one, and then show import wizard
 *
 * @param project - null mean its new project creation
 * @return
 */
@RequiredUIAccess
public static <C extends ModuleImportContext> AsyncResult<Pair<C, ModuleImportProvider<C>>> showFileChooser(@Nullable Project project, @Nullable FileChooserDescriptor chooserDescriptor) {
  boolean isModuleImport = project != null;

  FileChooserDescriptor descriptor = ObjectUtil.notNull(chooserDescriptor, createAllImportDescriptor(isModuleImport));

  VirtualFile toSelect = null;
  String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION);
  if (lastLocation != null) {
    toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation);
  }

  AsyncResult<Pair<C, ModuleImportProvider<C>>> result = AsyncResult.undefined();

  AsyncResult<VirtualFile> fileChooseAsync = FileChooser.chooseFile(descriptor, project, toSelect);
  fileChooseAsync.doWhenDone((f) -> {
    PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, f.getPath());

    showImportChooser(project, f, AsyncResult.undefined());
  });

  fileChooseAsync.doWhenRejected((Runnable)result::setRejected);

  return 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: JBColor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JBColor namedColor(@Nonnull final String propertyName, @Nonnull final Color defaultColor) {
  return new JBColor(() -> {
    Color color = ObjectUtil.notNull(UIManager.getColor(propertyName), () -> ObjectUtil.notNull(findPatternMatch(propertyName), defaultColor));
    if (UIManager.get(propertyName) == null) {
      UIManager.put(propertyName, color);
    }
    return color;
  });
}
 
Example 5
Source File: ShowDiffWithLocalAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getRequiredData(CommonDataKeys.PROJECT);
  if (ChangeListManager.getInstance(project).isFreezedWithNotification(null)) return;

  VcsRevisionNumber currentRevisionNumber = e.getRequiredData(VcsDataKeys.HISTORY_SESSION).getCurrentRevisionNumber();
  VcsFileRevision selectedRevision = e.getRequiredData(VcsDataKeys.VCS_FILE_REVISIONS)[0];
  FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);

  if (currentRevisionNumber != null && selectedRevision != null) {
    DiffFromHistoryHandler diffHandler =
            ObjectUtil.notNull(e.getRequiredData(VcsDataKeys.HISTORY_PROVIDER).getHistoryDiffHandler(), new StandardDiffFromHistoryHandler());
    diffHandler.showDiffForTwo(project, filePath, selectedRevision, new CurrentRevision(filePath.getVirtualFile(), currentRevisionNumber));
  }
}
 
Example 6
Source File: LanguageSubstitutors.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processLanguageSubstitution(@Nonnull final VirtualFile file,
                                                @Nonnull Language originalLang,
                                                @Nonnull final Language substitutedLang) {
  if (file instanceof VirtualFileWindow) {
    // Injected files are created with substituted language, no need to reparse:
    //   com.intellij.psi.impl.source.tree.injected.MultiHostRegistrarImpl#doneInjecting
    return;
  }
  Language prevSubstitutedLang = SUBSTITUTED_LANG_KEY.get(file);
  final Language prevLang = ObjectUtil.notNull(prevSubstitutedLang, originalLang);
  if (!prevLang.is(substitutedLang)) {
    if (file.replace(SUBSTITUTED_LANG_KEY, prevSubstitutedLang, substitutedLang)) {
      if (prevSubstitutedLang == null) {
        return; // no need to reparse for the first language substitution
      }
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
      }
      file.putUserData(REPARSING_SCHEDULED, true);
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (file.replace(REPARSING_SCHEDULED, true, null)) {
            LOG.info("Reparsing " + file.getPath() + " because of language substitution " +
                     prevLang.getID() + "->" + substitutedLang.getID());
            FileContentUtilCore.reparseFiles(file);
          }
        }
      }, ModalityState.defaultModalityState());
    }
  }
}
 
Example 7
Source File: WriteAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Deprecated
@DeprecationInfo("Use AccessRule.writeAsync()")
public static AccessToken start() {
  // get useful information about the write action
  Class aClass = ObjectUtil.notNull(ReflectionUtil.getGrandCallerClass(), WriteAction.class);
  return start(aClass);
}
 
Example 8
Source File: Platform.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Deprecated
@DeprecationInfo("Use jvm().getRuntimeProperty()")
@SuppressWarnings("deprecation")
default String getRuntimeProperty(@Nonnull String key, @Nonnull String defaultValue) {
  return ObjectUtil.notNull(getRuntimeProperty(key), defaultValue);
}
 
Example 9
Source File: CS0102.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static List<CompilerCheckBuilder> doCheck(@Nonnull CompilerCheck<? extends DotNetMemberOwner> compilerCheck, @Nonnull DotNetMemberOwner t)
{
	List<CompilerCheckBuilder> results = new SmartList<>();

	final DotNetNamedElement[] members = t.getMembers();

	List<DotNetNamedElement> duplicateMembers = new ArrayList<>();
	for(DotNetNamedElement searchElement : members)
	{
		if(!(searchElement instanceof PsiNameIdentifierOwner))
		{
			continue;
		}

		String searchName = searchElement.getName();
		if(searchName == null)
		{
			continue;
		}

		for(DotNetNamedElement mayDuplicate : members)
		{
			if(searchElement == mayDuplicate)
			{
				continue;
			}

			if(!(mayDuplicate instanceof PsiNameIdentifierOwner))
			{
				continue;
			}

			String targetName = mayDuplicate.getName();
			if(searchName.equals(targetName))
			{
				// skip type declarations if partial
				if(searchElement instanceof CSharpTypeDeclaration && mayDuplicate instanceof CSharpTypeDeclaration && CSharpElementCompareUtil.isEqualWithVirtualImpl(searchElement, mayDuplicate,
						searchElement) && isPartial(searchElement) && isPartial(mayDuplicate))
				{
					continue;
				}

				if(searchElement instanceof CSharpTypeDeclaration && mayDuplicate instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) searchElement).getGenericParametersCount() !=
						((CSharpTypeDeclaration) mayDuplicate).getGenericParametersCount())
				{
					continue;
				}

				if(searchElement instanceof DotNetLikeMethodDeclaration && mayDuplicate instanceof DotNetLikeMethodDeclaration && !CSharpElementCompareUtil.isEqualWithVirtualImpl(searchElement,
						mayDuplicate, searchElement))
				{
					continue;
				}

				if(searchElement instanceof CSharpPropertyDeclaration && mayDuplicate instanceof CSharpPropertyDeclaration && !CSharpElementCompareUtil.isEqualWithVirtualImpl(searchElement,
						mayDuplicate, searchElement))
				{
					continue;
				}

				duplicateMembers.add(mayDuplicate);
			}
		}
	}

	String name = t instanceof PsiFile ? "<global namespace>" : ((DotNetQualifiedElement) t).getPresentableQName();
	for(DotNetNamedElement duplicateMember : duplicateMembers)
	{
		PsiElement toHighlight = duplicateMember;
		if(duplicateMember instanceof PsiNameIdentifierOwner)
		{
			PsiElement nameIdentifier = ((PsiNameIdentifierOwner) duplicateMember).getNameIdentifier();
			toHighlight = ObjectUtil.notNull(nameIdentifier, duplicateMember);
		}
		results.add(compilerCheck.newBuilder(toHighlight, name, duplicateMember.getName()));
	}
	return results;
}
 
Example 10
Source File: ThisObjectEvaluator.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static DotNetValueProxy calcThisObject(@Nonnull DotNetStackFrameProxy proxy, DotNetValueProxy thisObject)
{
	return ObjectUtil.notNull(tryToFindObjectInsideYieldOrAsyncThis(proxy, thisObject), thisObject);
}
 
Example 11
Source File: DarculaButtonUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected Color getButtonColor2() {
  return ObjectUtil.notNull(UIManager.getColor("Button.darcula.color2"), new ColorUIResource(0x414648));
}
 
Example 12
Source File: DarculaButtonUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected Color getSelectedButtonColor1() {
  return ObjectUtil.notNull(UIManager.getColor("Button.darcula.selection.color1"), new ColorUIResource(0x384f6b));
}
 
Example 13
Source File: CharsetToolkit.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve the platform charset of the system (determined by "sun.jnu.encoding" property)
 */
@Nonnull
public static Charset getPlatformCharset() {
  String name = System.getProperty("sun.jnu.encoding");
  return ObjectUtil.notNull(forName(name), getDefaultSystemCharset());
}
 
Example 14
Source File: Platform.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
default String getEnvironmentVariable(@Nonnull String key, @Nonnull String defaultValue) {
  return ObjectUtil.notNull(getEnvironmentVariable(key), defaultValue);
}
 
Example 15
Source File: Platform.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
default String getRuntimeProperty(@Nonnull String key, @Nonnull String defaultValue) {
  return ObjectUtil.notNull(getRuntimeProperty(key), defaultValue);
}
 
Example 16
Source File: DesktopDeferredIconImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static consulo.ui.image.Image nonNull(final consulo.ui.image.Image icon) {
  return ObjectUtil.notNull(icon, EMPTY_ICON);
}
 
Example 17
Source File: CSharpOutRefVariableImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
private DotNetTypeRef searchTypeRefFromCall()
{
	CSharpOutRefVariableExpressionImpl expression = (CSharpOutRefVariableExpressionImpl) getParent();
	PsiElement exprParent = expression.getParent();
	if(!(exprParent instanceof CSharpCallArgument))
	{
		return DotNetTypeRef.ERROR_TYPE;
	}

	CSharpCallArgument callArgument = (CSharpCallArgument) exprParent;

	CSharpCallArgumentListOwner listOwner = PsiTreeUtil.getParentOfType(exprParent, CSharpCallArgumentListOwner.class);
	if(listOwner == null)
	{
		return DotNetTypeRef.ERROR_TYPE;
	}

	ResolveResult[] resolveResults = listOwner.multiResolve(false);
	if(resolveResults.length != 1)
	{
		return DotNetTypeRef.ERROR_TYPE;
	}

	ResolveResult result = resolveResults[0];
	if(!(result instanceof MethodResolveResult))
	{
		return DotNetTypeRef.ERROR_TYPE;
	}

	List<NCallArgument> arguments = ((MethodResolveResult) result).getCalcResult().getArguments();

	for(NCallArgument argument : arguments)
	{
		CSharpCallArgument searchCallArgument = argument.getCallArgument();
		if(callArgument == searchCallArgument)
		{
			DotNetTypeRef parameterTypeRef = argument.getParameterTypeRef();
			return ObjectUtil.notNull(parameterTypeRef, DotNetTypeRef.ERROR_TYPE);
		}
	}
	return DotNetTypeRef.ERROR_TYPE;
}
 
Example 18
Source File: DarculaButtonUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected Color getButtonColor1() {
  return ObjectUtil.notNull(UIManager.getColor("Button.darcula.color1"), new ColorUIResource(0x555a5c));
}
 
Example 19
Source File: UnityLogPostHandlerRequest.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@MagicConstant(valuesFromClass = MessageCategory.class)
public int getMessageCategory()
{
	return ObjectUtil.notNull(ourTypeMap.get(type), MessageCategory.INFORMATION);
}
 
Example 20
Source File: ComboBoxButtonImpl.java    From consulo with Apache License 2.0 3 votes vote down vote up
@Override
public void updateUI() {
  ComboBoxUIFactory factory = ObjectUtil.notNull((ComboBoxUIFactory)UIManager.get(ComboBoxUIFactory.class), DefaultComboBoxUIFactory.INSTANCE);

  ComboBoxUI delegate = (ComboBoxUI)UIManager.getUI(this);

  setUI(factory.create(delegate, this));

  // refresh state
  setLikeButton(myOnClickListener);

  SwingUIDecorator.apply(SwingUIDecorator::decorateToolbarComboBox, this);
}