本文整理汇总了Java中com.intellij.util.ObjectUtils类的典型用法代码示例。如果您正苦于以下问题:Java ObjectUtils类的具体用法?Java ObjectUtils怎么用?Java ObjectUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectUtils类属于com.intellij.util包,在下文中一共展示了ObjectUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResolvedProperty
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
@Nullable
private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) {
return CachedValuesManager.getCachedValue(codeValue, KEY, () -> {
List<IProperty> allProperties = new SmartList<>();
for (PsiReference nextRef : codeValue.getReferences()) {
if (nextRef instanceof PsiPolyVariantReference) {
Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false))
.filter(ResolveResult::isValidResult)
.map(ResolveResult::getElement)
.map(o -> ObjectUtils.tryCast(o, IProperty.class))
.filter(Objects::nonNull)
.forEach(allProperties::add);
} else {
Optional.ofNullable(nextRef.resolve())
.map(o -> ObjectUtils.tryCast(o, IProperty.class))
.ifPresent(allProperties::add);
}
}
IProperty theChosenOne = chooseForLocale(allProperties);
return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT);
});
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:24,代码来源:JspPropertyFoldingBuilder.java
示例2: expectDomAttributeValue
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue(
@NotNull final PsiElement element,
@NotNull final Class<? extends T> domTagClass,
@NotNull final Function<T, GenericAttributeValue<V>> domGetter
) {
final DomManager domManager = DomManager.getDomManager(element.getProject());
if (!(element instanceof XmlElement)) {
return null;
}
final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
if (xmlAttribute == null) {
return null;
}
final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
DomElement domParentTag = domManager.getDomElement(xmlParentTag);
return Optional.ofNullable(domParentTag)
.map(o -> ObjectUtils.tryCast(o, domTagClass))
.map(domGetter)
.filter(val -> val == domManager.getDomElement(xmlAttribute))
.orElse(null);
}
示例3: getKeyValue
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
public static YAMLKeyValue getKeyValue(YAMLFile yamlFile, List<String> key) {
YAMLDocument document = (YAMLDocument) yamlFile.getDocuments().get(0);
YAMLMapping mapping = (YAMLMapping) ObjectUtils.tryCast(document.getTopLevelValue(), YAMLMapping.class);
for (int i = 0; i < key.size(); ++i) {
if (mapping == null) {
return null;
}
YAMLKeyValue keyValue = null;
for (YAMLKeyValue each : mapping.getKeyValues()) {
if (each.getKeyText().equals(key.get(i))) {
keyValue = each;
break;
}
}
if (keyValue == null || i + 1 == key.size()) {
return keyValue;
}
mapping = ObjectUtils.tryCast(keyValue.getValue(), YAMLMapping.class);
}
throw new IllegalStateException("Should have returned from the loop");
}
示例4: setupSshAuthenticator
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
private void setupSshAuthenticator() throws IOException {
GitXmlRpcSshService ssh = ServiceManager.getService(GitXmlRpcSshService.class);
myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
mySshHandler = ssh.registerHandler(new GitSSHGUIHandler(myProject));
myEnvironmentCleanedUp = false;
myEnv.put(GitSSHHandler.SSH_HANDLER_ENV, Integer.toString(mySshHandler));
int port = ssh.getXmlRcpPort();
myEnv.put(GitSSHHandler.SSH_PORT_ENV, Integer.toString(port));
LOG.debug(String.format("handler=%s, port=%s", mySshHandler, port));
final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance();
boolean useHttpProxy = httpConfigurable.USE_HTTP_PROXY && !isSshUrlExcluded(httpConfigurable, ObjectUtils.assertNotNull(myUrls));
myEnv.put(GitSSHHandler.SSH_USE_PROXY_ENV, String.valueOf(useHttpProxy));
if (useHttpProxy) {
myEnv.put(GitSSHHandler.SSH_PROXY_HOST_ENV, StringUtil.notNullize(httpConfigurable.PROXY_HOST));
myEnv.put(GitSSHHandler.SSH_PROXY_PORT_ENV, String.valueOf(httpConfigurable.PROXY_PORT));
boolean proxyAuthentication = httpConfigurable.PROXY_AUTHENTICATION;
myEnv.put(GitSSHHandler.SSH_PROXY_AUTHENTICATION_ENV, String.valueOf(proxyAuthentication));
if (proxyAuthentication) {
myEnv.put(GitSSHHandler.SSH_PROXY_USER_ENV, StringUtil.notNullize(httpConfigurable.PROXY_LOGIN));
myEnv.put(GitSSHHandler.SSH_PROXY_PASSWORD_ENV, StringUtil.notNullize(httpConfigurable.getPlainProxyPassword()));
}
}
}
示例5: actionPerformed
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
@Override
public void actionPerformed(@NotNull 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 = ObjectUtils.notNull(e.getRequiredData(VcsDataKeys.HISTORY_PROVIDER).getHistoryDiffHandler(),
new StandardDiffFromHistoryHandler());
diffHandler.showDiffForTwo(project, filePath,
selectedRevision, new CurrentRevision(filePath.getVirtualFile(), currentRevisionNumber));
}
}
示例6: visitClassType
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
@Override
public Type visitClassType(PsiClassType type) {
PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
PsiClass aClass = resolveResult.getElement();
if (aClass instanceof PsiAnonymousClass) {
return visitClassType(((PsiAnonymousClass)aClass).getBaseClassType());
}
else if (aClass == null) {
return new UnresolvedType(type);
}
else {
Map<String, Type> substitutionMap = ContainerUtil.newHashMap();
PsiSubstitutor substitutor = resolveResult.getSubstitutor();
for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) {
PsiType substitute = substitutor.substitute(typeParameter);
substitutionMap.put(typeParameter.getName(), substitute != null ? substitute.accept(this) : null);
}
String qualifiedName = ObjectUtils.notNull(aClass.getQualifiedName(), aClass.getName());
return new ClassType(type, qualifiedName, substitutionMap);
}
}
示例7: createLookupElement
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
@Nullable
@Override
public LookupElement createLookupElement(ActionOrGroup actionOrGroup) {
if (actionOrGroup instanceof Action) {
Action action = (Action)actionOrGroup;
final PsiElement element = getPsiElement(actionOrGroup);
if (element == null) {
throw new IllegalStateException(action.getId().getStringValue() + " in " + DomUtil.getFile(action) + " " + action.isValid() + " ");
}
LookupElementBuilder builder =
LookupElementBuilder.create(ObjectUtils.assertNotNull(element),
ObjectUtils.assertNotNull(getName(action)));
final String text = action.getText().getStringValue();
if (StringUtil.isNotEmpty(text)) {
String withoutMnemonic = StringUtil.replace(text, "_", "");
builder = builder.withTailText(" \"" + withoutMnemonic + "\"", true);
}
return builder;
}
return super.createLookupElement(actionOrGroup);
}
示例8: getDocument
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
@Override
@Nullable
public Document getDocument() {
if (myDocument == null) {
if (isBinary()) return null;
String text = null;
try {
Charset charset = ObjectUtils.notNull(myCharset, EncodingProjectManager.getInstance(myProject).getDefaultCharset());
text = CharsetToolkit.bytesToString(myBytes, charset);
}
catch (IllegalCharsetNameException ignored) { }
// Still NULL? only if not supported or an exception was thrown.
// Decode a string using the truly default encoding.
if (text == null) text = new String(myBytes);
text = LineTokenizer.correctLineSeparators(text);
myDocument = EditorFactory.getInstance().createDocument(text);
myDocument.setReadOnly(true);
}
return myDocument;
}
示例9: show
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
@Messages.YesNoCancelResult
public int show() {
String yesText = ObjectUtils.chooseNotNull(myYesText, Messages.YES_BUTTON);
String noText = ObjectUtils.chooseNotNull(myNoText, Messages.NO_BUTTON);
String cancelText = ObjectUtils.chooseNotNull(myCancelText, Messages.CANCEL_BUTTON);
try {
if (Messages.canShowMacSheetPanel() && !Messages.isApplicationInUnitTestOrHeadless()) {
return MacMessages.getInstance().showYesNoCancelDialog(myTitle, myMessage, yesText, noText, cancelText, WindowManager.getInstance().suggestParentWindow(myProject), myDoNotAskOption);
}
}
catch (Exception ignored) {}
int buttonNumber = Messages.showDialog(myProject, myMessage, myTitle, new String[]{yesText, noText, cancelText}, 0, myIcon, myDoNotAskOption);
return buttonNumber == 0 ? Messages.YES : buttonNumber == 1 ? Messages.NO : Messages.CANCEL;
}
示例10: paintOnComponentUnderViewport
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
private void paintOnComponentUnderViewport(Component component, Graphics g) {
JBViewport viewport = ObjectUtils.tryCast(myOwner, JBViewport.class);
if (viewport == null || viewport.getView() != component || viewport.isPaintingNow()) return;
// We're painting a component which has a viewport as it's ancestor.
// As the viewport paints status text, we'll erase it, so we need to schedule a repaint for the viewport with status text's bounds.
// But it causes flicker, so we paint status text over the component first and then schedule the viewport repaint.
Rectangle textBoundsInViewport = getTextComponentBound();
int xInOwner = textBoundsInViewport.x - component.getX();
int yInOwner = textBoundsInViewport.y - component.getY();
Rectangle textBoundsInOwner = new Rectangle(xInOwner, yInOwner, textBoundsInViewport.width, textBoundsInViewport.height);
doPaintStatusText(g, textBoundsInOwner);
viewport.repaint(textBoundsInViewport);
}
示例11: replaceAction
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
private AnAction replaceAction(@NotNull String actionId, @NotNull AnAction newAction, @Nullable PluginId pluginId) {
AnAction oldAction = getActionOrStub(actionId);
if (oldAction != null) {
boolean isGroup = oldAction instanceof ActionGroup;
if (isGroup != newAction instanceof ActionGroup) {
throw new IllegalStateException("cannot replace a group with an action and vice versa: " + actionId);
}
unregisterAction(actionId);
if (isGroup) {
myId2GroupId.values().remove(actionId);
}
}
registerAction(actionId, newAction, pluginId);
for (String groupId : myId2GroupId.get(actionId)) {
DefaultActionGroup group = ObjectUtils.assertNotNull((DefaultActionGroup)getActionOrStub(groupId));
group.replaceAction(oldAction, newAction);
}
return oldAction;
}
示例12: generateDocstring
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
private static void generateDocstring(@Nullable PyNamedParameter param, @NotNull PyFunction pyFunction) {
if (!DocStringUtil.ensureNotPlainDocstringFormat(pyFunction)) {
return;
}
final PyDocstringGenerator docstringGenerator = PyDocstringGenerator.forDocStringOwner(pyFunction);
String type = "object";
if (param != null) {
final String paramName = StringUtil.notNullize(param.getName());
final PySignature signature = PySignatureCacheManager.getInstance(pyFunction.getProject()).findSignature(pyFunction);
if (signature != null) {
type = ObjectUtils.chooseNotNull(signature.getArgTypeQualifiedName(paramName), type);
}
docstringGenerator.withParamTypedByName(param, type);
}
else {
docstringGenerator.withReturnValue(type);
}
docstringGenerator.addFirstEmptyLine().buildAndInsert();
docstringGenerator.startTemplate();
}
示例13: calculateRoot
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
private Object calculateRoot(DataContext dataContext) {
// Narrow down the root element to the first interesting one
Object root = LangDataKeys.MODULE.getData(dataContext);
if (root != null) return root;
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) return null;
Object projectChild;
Object projectGrandChild = null;
CommonProcessors.FindFirstAndOnlyProcessor<Object> processor = new CommonProcessors.FindFirstAndOnlyProcessor<Object>();
processChildren(project, processor);
projectChild = processor.reset();
if (projectChild != null) {
processChildren(projectChild, processor);
projectGrandChild = processor.reset();
}
return ObjectUtils.chooseNotNull(projectGrandChild, ObjectUtils.chooseNotNull(projectChild, project));
}
示例14: fillTable
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
void fillTable() {
Class<?> clazz0 = myComponent.getClass();
Class<?> clazz = clazz0.isAnonymousClass() ? clazz0.getSuperclass() : clazz0;
myProperties.add(new PropertyBean("class", clazz.getName()));
for (String name: PROPERTIES) {
String propertyName = ObjectUtils.notNull(StringUtil.getPropertyName(name), name);
Object propertyValue;
try {
try {
//noinspection ConstantConditions
propertyValue = ReflectionUtil.findMethod(Arrays.asList(clazz.getMethods()), name).invoke(myComponent);
}
catch (Exception e) {
propertyValue = ReflectionUtil.findField(clazz, null, name).get(myComponent);
}
myProperties.add(new PropertyBean(propertyName, propertyValue));
}
catch (Exception ignored) {
}
}
Object addedAt = myComponent instanceof JComponent ? ((JComponent)myComponent).getClientProperty("uiInspector.addedAt") : null;
myProperties.add(new PropertyBean("added-at", addedAt));
}
示例15: testUnsavedDocument_DoNotGC
import com.intellij.util.ObjectUtils; //导入依赖的package包/类
public void testUnsavedDocument_DoNotGC() throws Exception {
final VirtualFile file = createFile();
Document document = myDocumentManager.getDocument(file);
int idCode = System.identityHashCode(document);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
@Override
public void run() {
ObjectUtils.assertNotNull(myDocumentManager.getDocument(file)).insertString(0, "xxx");
}
});
//noinspection UnusedAssignment
document = null;
System.gc();
System.gc();
document = myDocumentManager.getDocument(file);
assertEquals(idCode, System.identityHashCode(document));
}