当前位置: 首页>>代码示例>>Java>>正文


Java Contract类代码示例

本文整理汇总了Java中org.jetbrains.annotations.Contract的典型用法代码示例。如果您正苦于以下问题:Java Contract类的具体用法?Java Contract怎么用?Java Contract使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Contract类属于org.jetbrains.annotations包,在下文中一共展示了Contract类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadMH

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Contract("null, null, _, _ -> fail")
private static void loadMH(GeneratorAdapter adapter, Type reflectorClass, int flags, int mhIndex) {
    if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) == 0) return;

    /* Load MethodHandle field */
    adapter.loadThis();
    adapter.getField(notNull(reflectorClass, "Reflector class shouldn't be null!"), MHF, MH_ARRAY);

    /* Load index */
    if(mhIndex >= 0 && mhIndex <= 5)
        /* ICONST_x offset is 3, iow ICONST_0 = 3, ICONST_1 = 4 */
        adapter.visitInsn(ICONST_0 + mhIndex);
    else
        adapter.visitIntInsn(BIPUSH, mhIndex);

    /* Load MethodHandle from array */
    adapter.visitInsn(AALOAD);
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:19,代码来源:MethodGenerator.java

示例2: prevElementIsUserRightsMacros

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Nullable
@Contract(pure = true)
public static boolean prevElementIsUserRightsMacros(@NotNull final PsiElement element) {
    Validate.notNull(element);

    final Class[] skipClasses = {ImpexValueLine.class, PsiComment.class, PsiWhiteSpace.class};
    PsiElement prevElement = PsiTreeUtil.skipSiblingsBackward(element, skipClasses);

    while (null != prevElement) {
        if (isHeaderLine(prevElement)) {
            return false;
        }
        if (isUserRightsMacros(prevElement)) {
            return true;
        }
        prevElement = PsiTreeUtil.skipSiblingsBackward(prevElement, skipClasses);
    }

    return false;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ImpexPsiUtils.java

示例3: getHeaderTypeNamePsiElementOfAttribute

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Nullable
@Contract("null -> null")
protected ImpexHeaderTypeName getHeaderTypeNamePsiElementOfAttribute(@Nullable final PsiElement headerAttributePsiElement) {
    if (null == headerAttributePsiElement || null == headerAttributePsiElement.getNode()) {
        return null;
    }

    final ImpexHeaderLine impexHeaderLine = PsiTreeUtil.getParentOfType(
        headerAttributePsiElement,
        ImpexHeaderLine.class
    );

    if (null == impexHeaderLine) {
        return null;
    }

    final ImpexFullHeaderType impexFullHeaderType = impexHeaderLine.getFullHeaderType();

    return null == impexFullHeaderType ? null : impexFullHeaderType.getHeaderTypeName();
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ImpexHeaderItemTypeAttributeNameCompletionProvider.java

示例4: nextElementIsHeaderLine

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Nullable
@Contract(pure = true)
public static boolean nextElementIsHeaderLine(@NotNull final PsiElement element) {
    Validate.notNull(element);

    PsiElement nextSibling = element.getNextSibling();

    while (null != nextSibling) {
        if (isImpexValueLine(nextSibling)) {
            return false;
        }
        if (isUserRightsMacros(nextSibling)) {
            return false;
        }
        if (isHeaderLine(nextSibling)) {
            return true;
        }
        nextSibling = nextSibling.getNextSibling();
    }

    return true;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:23,代码来源:ImpexPsiUtils.java

示例5: skipAllExceptLineBreaksAndGetImpexValueGroup

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Nullable
@Contract(pure = true)
public static ImpexValueGroup skipAllExceptLineBreaksAndGetImpexValueGroup(
    @NotNull final PsiElement psiElement
) {
    Validate.notNull(psiElement);

    if (isLineBreak(psiElement.getPrevSibling())) {
        return null;
    }

    PsiElement prevSibling = psiElement.getPrevSibling();
    while (!isImpexValueLine(prevSibling)) {
        if (null == prevSibling || isLineBreak(prevSibling)) {
            return null;
        }

        prevSibling = prevSibling.getPrevSibling();
    }

    if (!isImpexValueLine(prevSibling)) {
        return null;
    }

    return PsiTreeUtil.getParentOfType(PsiTreeUtil.lastChild(prevSibling), ImpexValueGroup.class);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:ImpexPsiUtils.java

示例6: isDecimalNumber

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Contract("null -> false")
public static boolean isDecimalNumber(@Nullable PsiType type) {
	if (type == null) {
		return false;
	}

	return NUMERIC_TYPES.contains(type) || NUMERIC_TYPES.contains(PsiPrimitiveType.getUnboxedType(type));
}
 
开发者ID:xylo,项目名称:intellij-postfix-templates,代码行数:9,代码来源:MyJavaPostfixTemplatesUtils.java

示例7: convert

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Contract(pure = true)
@NotNull
@NonNls
public static String[] convert(Pair... origin) {
	String[] ret = new String[origin.length];
	for (int i = 0; i < ret.length; ++i) ret[i] = origin[i].getCombined();
	return ret;
}
 
开发者ID:ProgramLeague,项目名称:strictfp-back-end,代码行数:9,代码来源:Pair.java

示例8: getField

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
/**
 * Get class field
 *
 * @param fieldName Field's name
 * @param type Field's type class
 * @param <V> Field's type
 * @return {@link FieldWrapper} object or empty, if field wasn't found
 */
@Contract("null, null -> fail")
@SuppressWarnings("unchecked")
public <V> Optional<FieldWrapper<V>> getField(String fieldName, Class<V> type) {
    /* Check arguments */
    if(fieldName == null) throw new IllegalStateException("Field name shouldn't be null!");
    if(type == null) throw new IllegalStateException("Field type shouldn't be null!");

    /* Try to find cached field */
    FieldInfo fieldInfo = new FieldInfo(fieldName, type);

    /* Get field */
    Integer found = FIELD_INDEX.get(fieldInfo);
    Field[] field = new Field[] { found != null ? FIELD_CACHE.get(found) : null };
    field[0] = field[0] != null ? field[0] : findDeclaredField(fieldName, type);
    if(field[0] == null) return Optional.empty();

    /* Wrap field */
    return Optional.of((FieldWrapper<V>)FIELDWRAPPER_CACHE.computeIfAbsent(found,
            k -> MethodHandleFieldWrapper.of(this, field[0], type)));
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:29,代码来源:ClassWrapper.java

示例9: getHeaderParametersSeparatorFromHeaderLineByNumber

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Nullable
@Contract(pure = true)
public static PsiElement getHeaderParametersSeparatorFromHeaderLineByNumber(
    final int columnNumber,
    @NotNull final ImpexHeaderLine impexHeaderLine
) {
    Validate.isTrue(columnNumber >= 0);
    Validate.notNull(impexHeaderLine);

    final List<PsiElement> parameterSeparators = CommonPsiUtils.findChildrenByIElementType(
        impexHeaderLine, ImpexTypes.PARAMETERS_SEPARATOR
    );

    if (columnNumber >= parameterSeparators.size()) {
        return null;
    }

    return parameterSeparators.get(columnNumber);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:20,代码来源:ImpexPsiUtils.java

示例10: checkFields

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
/**
 * Check fields availability in class agains info defined in
 * {@link FieldDescriptor} objects
 *
 * @param clazz Class to perform check on
 * @param fields {@link FieldDescriptor} objects
 */
@Contract("null, _ -> fail")
public static void checkFields(Class<?> clazz, FieldDescriptor... fields) {
    ClassWrapper<?> cw = Reflect.wrapClass(clazz);
    Stream.of(fields).forEach(fieldDescriptor -> {
        try {
            Ensure.ensurePresent(
                    cw.getField(fieldDescriptor.getFieldName(), fieldDescriptor.getFieldType()),
                    String.format("Field %s %s not found",
                            fieldDescriptor.getFieldType(),
                            fieldDescriptor.getFieldName())
            );
        } catch (Exception e) {
            throw new NullPointerException(e.getLocalizedMessage());
        }
    });
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:24,代码来源:Validate.java

示例11: generateName

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@NotNull
@Contract("null, _, null -> fail")
private String generateName(ClassWrapper<?> target, int flags, Class<?> intf) {
    notNull(target, "Target class must not be null!");
    notNull(intf, "Interface class must not be null!");

    StringBuilder classNameBuilder = new StringBuilder();
    classNameBuilder.append(MethodReflector.class.getName());
    classNameBuilder.append('.');
    classNameBuilder.append("$Target$");
    classNameBuilder.append(getClassName(target.getWrappedClass().getName()));
    classNameBuilder.append('$');
    classNameBuilder.append(getClassName(intf.getName()));
    classNameBuilder.append('$');
    classNameBuilder.append(COUNTER.computeIfAbsent(intf, k -> new AtomicInteger(0)).getAndIncrement());
    return classNameBuilder.toString();
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:18,代码来源:MethodReflectorFactory.java

示例12: highlightArea

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@Contract(pure = false)
protected void highlightArea(
    @NotNull final Editor editor,
    @NotNull final PsiElement impexFullHeaderParameter
) {
    Validate.notNull(editor);
    Validate.notNull(impexFullHeaderParameter);

    if (isAlreadyHighlighted(editor, impexFullHeaderParameter)) {
        return;
    }

    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            final PsiElement currentHighlightedElement = highlightedBlocks.remove(editor);
            if (null != currentHighlightedElement) {
                modifyHighlightedArea(editor, currentHighlightedElement, true);
            }

            highlightedBlocks.put(editor, impexFullHeaderParameter);
            modifyHighlightedArea(editor, impexFullHeaderParameter, false);
        }
    });
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:DefaultImpexHeaderNameHighlighterService.java

示例13: splitByWhitespace

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@NotNull
@Contract("null -> fail")
public static List<String> splitByWhitespace(@NotNull String args) {
    @NotNull Matcher matcher = Regexes.WHITESPACE_SPLIT.pattern().matcher(Objects.requireNonNull(args));

    //As seen on http://stackoverflow.com/a/7804472
    @NotNull List<String> list = new ArrayList<>();
    while (matcher.find()) {
        list.add(matcher.group(1).replace("\"", ""));
    }
    return list;
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:13,代码来源:Commands.java

示例14: getTags

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@NotNull
@Contract(pure = true)
public Set<String> getTags() {
	Set<String> tagSet = new HashSet<>();
	for (Tag thisTag : tags)
		tagSet.add(thisTag.getName());
	return tagSet;
}
 
开发者ID:ProgramLeague,项目名称:strictfp-back-end,代码行数:9,代码来源:Article.java

示例15: getValueText

import org.jetbrains.annotations.Contract; //导入依赖的package包/类
@NotNull
@Contract(pure = true)
private String getValueText(final @NotNull ImpexAttribute impexAttribute) {
    Validate.notNull(impexAttribute);

    if (null == impexAttribute.getAnyAttributeValue() || (StringUtils.isBlank(impexAttribute.getAnyAttributeValue()
                                                                                            .getText()))) {
        return impexAttribute.getText();
    }

    return impexAttribute.getAnyAttributeValue().getText();
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:13,代码来源:SmartImpexFoldingPlaceholderBuilder.java


注:本文中的org.jetbrains.annotations.Contract类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。