Java 类com.intellij.openapi.util.NullableFactory 实例源码

项目:tools-idea    文件:ConfigurableEP.java   
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) {
  myProject = project;
  myPicoContainer = picoContainer;
  myFactory = new AtomicNotNullLazyValue<NullableFactory<T>>() {
    @NotNull
    @Override
    protected NullableFactory<T> compute() {
      if (providerClass != null) {
        return new InstanceFromProviderFactory();
      }
      else if (instanceClass != null) {
        return new NewInstanceFactory();
      }
      else if (implementationClass != null) {
        return new ImplementationFactory();
      }
      throw new RuntimeException();
    }
  };
}
项目:consulo    文件:ConfigurableEP.java   
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) {
  myProject = project;
  myPicoContainer = picoContainer;
  myFactory = new AtomicNotNullLazyValue<NullableFactory<T>>() {
    @Nonnull
    @Override
    protected NullableFactory<T> compute() {
      if (providerClass != null) {
        return new InstanceFromProviderFactory();
      }
      else if (instanceClass != null) {
        return new NewInstanceFactory();
      }
      else if (implementationClass != null) {
        return new ImplementationFactory();
      }
      throw new RuntimeException();
    }
  };
}
项目:intellij-ce-playground    文件:RefManagerImpl.java   
@Nullable
private <T extends RefElement> T getFromRefTableOrCache(final PsiElement element,
                                                        @NotNull NullableFactory<T> factory,
                                                        @Nullable Consumer<T> whenCached) {

  PsiAnchor psiAnchor = createAnchor(element);
  T result;
  synchronized (myRefTable) {
    //noinspection unchecked
    result = (T)myRefTable.get(psiAnchor);

    if (result != null) return result;

    if (!isValidPointForReference()) {
      //LOG.assertTrue(true, "References may become invalid after process is finished");
      return null;
    }

    result = factory.create();
    if (result == null) return null;

    myRefTable.put(psiAnchor, result);
  }
  if (whenCached != null) {
    whenCached.consume(result);
  }

  return result;
}
项目:intellij-ce-playground    文件:ChangeDiffRequest.java   
private void takeStuffFromFactory(final DiffRequest request, final List<? extends AnAction> actions) {
  if (mySteps.size() > 1 || (myActionsFactory != null)) {
    request.setToolbarAddons(new DiffRequest.ToolbarAddons() {
      public void customize(final DiffToolbar toolbar) {
        if (mySteps.size() > 1) {
          toolbar.addSeparator();
        }
        toolbar.addAction(myPrevChangeAction);
        toolbar.addAction(myNextChangeAction);
        toolbar.addAction(mySelectChangeAction);

        if (myActionsFactory != null) {
          toolbar.addSeparator();
          for (AnAction action : actions) {
            toolbar.addAction(action);
          }
        }
      }
    });
  }

  if (myActionsFactory != null) {
    request.setBottomComponentFactory(new NullableFactory<JComponent>() {
      public JComponent create() {
        return myActionsFactory.createBottomComponent();
      }
    });
  }
}
项目:intellij-ce-playground    文件:DomRootInvocationHandler.java   
@Override
public DomElement createPathStableCopy() {
  final DomFileElement stableCopy = myParent.createStableCopy();
  return getManager().createStableValue(new NullableFactory<DomElement>() {
    @Override
    public DomElement create() {
      return stableCopy.isValid() ? stableCopy.getRootElement() : null;
    }
  });
}
项目:tools-idea    文件:ChangeDiffRequest.java   
private void takeStuffFromFactory(final DiffRequest request, final List<? extends AnAction> actions) {
  if (mySteps.size() > 1 || (myActionsFactory != null)) {
    request.setToolbarAddons(new DiffRequest.ToolbarAddons() {
      public void customize(final DiffToolbar toolbar) {
        if (mySteps.size() > 1) {
          toolbar.addSeparator();
        }
        toolbar.addAction(myPrevChangeAction);
        toolbar.addAction(myNextChangeAction);
        toolbar.addAction(mySelectChangeAction);

        if (myActionsFactory != null) {
          toolbar.addSeparator();
          for (AnAction action : actions) {
            toolbar.addAction(action);
          }
        }
      }
    });
  }

  if (myActionsFactory != null) {
    request.setBottomComponentFactory(new NullableFactory<JComponent>() {
      public JComponent create() {
        return myActionsFactory.createBottomComponent();
      }
    });
  }
}
项目:tools-idea    文件:DomRootInvocationHandler.java   
public DomElement createPathStableCopy() {
  final DomFileElement stableCopy = myParent.createStableCopy();
  return getManager().createStableValue(new NullableFactory<DomElement>() {
    public DomElement create() {
      return stableCopy.isValid() ? stableCopy.getRootElement() : null;
    }
  });
}
项目:consulo-xml    文件:DomRootInvocationHandler.java   
public DomElement createPathStableCopy() {
  final DomFileElement stableCopy = myParent.createStableCopy();
  return getManager().createStableValue(new NullableFactory<DomElement>() {
    public DomElement create() {
      return stableCopy.isValid() ? stableCopy.getRootElement() : null;
    }
  });
}
项目:intellij-ce-playground    文件:RefManagerImpl.java   
@Nullable
public RefElement getReference(final PsiElement elem, final boolean ignoreScope) {
  if (ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      return elem == null || !elem.isValid() ||
             elem instanceof LightElement || !(elem instanceof PsiDirectory) && !belongsToScope(elem, ignoreScope);
    }
  })) {
    return null;
  }

  return getFromRefTableOrCache(
    elem,
    new NullableFactory<RefElementImpl>() {
      @Override
      public RefElementImpl create() {
        return ApplicationManager.getApplication().runReadAction(new Computable<RefElementImpl>() {
          @Override
          @Nullable
          public RefElementImpl compute() {
            final RefManagerExtension extension = getExtension(elem.getLanguage());
            if (extension != null) {
              final RefElement refElement = extension.createRefElement(elem);
              if (refElement != null) return (RefElementImpl)refElement;
            }
            if (elem instanceof PsiFile) {
              return new RefFileImpl((PsiFile)elem, RefManagerImpl.this);
            }
            if (elem instanceof PsiDirectory) {
              return new RefDirectoryImpl((PsiDirectory)elem, RefManagerImpl.this);
            }
            return null;
          }
        });
      }
    },
    new Consumer<RefElementImpl>() {
      @Override
      public void consume(RefElementImpl element) {
        element.initialize();
        for (RefManagerExtension each : myExtensions.values()) {
          each.onEntityInitialized(element, elem);
        }
        fireNodeInitialized(element);
      }
    });
}
项目:intellij-ce-playground    文件:RefManagerImpl.java   
@Nullable
protected <T extends RefElement> T getFromRefTableOrCache(final PsiElement element, @NotNull NullableFactory<T> factory) {
  return getFromRefTableOrCache(element, factory, null); 
}