當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。