public WrapImpl(WrapType type, boolean wrapFirstElement) { Type myType; switch (type) { case NORMAL: myType = Type.WRAP_AS_NEEDED; break; case NONE: myType = Type.DO_NOT_WRAP; break; case ALWAYS: myType = Type.WRAP_ALWAYS; break; case CHOP_DOWN_IF_LONG: default: myType = Type.CHOP_IF_NEEDED; } int myId = ourId++; assert myId < ID_MAX; myFlags |= (wrapFirstElement ? WRAP_FIRST_ELEMENT_MASK : 0) | (myType.ordinal() << TYPE_SHIFT) | (myId << ID_SHIFT); }
public MethodCollector visitMethod(int access, String name, String desc) { // already found the method, skip any processing if (collector != null) { return null; } // not the same name if (!name.equals(methodName)) { return null; } Type[] argumentTypes = Type.getArgumentTypes(desc); int longOrDoubleQuantity = 0; for (Type t : argumentTypes) { if (t.getClassName().equals("long") || t.getClassName().equals("double")) { longOrDoubleQuantity++; } } int paramCount = argumentTypes.length; // not the same quantity of parameters if (paramCount != this.parameterTypes.length) { return null; } for (int i = 0; i < argumentTypes.length; i++) { if (!correctTypeName(argumentTypes, i).equals(this.parameterTypes[i].getName())) { return null; } } this.collector = new MethodCollector( (Modifier.isStatic(access) ? 0 : 1), argumentTypes.length + longOrDoubleQuantity); return collector; }
/** * Returns the new target type, or {@code null} if conversion is not necessary. * * @param curr old item * @param it new item * @return result (or {@code null}) * @throws QueryException query exception */ private AtomType numType(final Item curr, final Item it) throws QueryException { final Type ti = it.type; if (ti.isUntyped()) return DBL; final Type tc = curr.type; if (!(it instanceof ANum)) throw EXPTYPE_X_X_X.get(info, tc, ti, it); return tc == ti ? null : tc == DBL || ti == DBL ? DBL : tc == FLT || ti == FLT ? FLT : null; }
/** * check if the field saves an object. * * @param instr * @return */ private boolean isFieldIsObjectBased(GCInstruction instr) { if (instr.getOpCode() == JavaInstructionsOpcodes.AALOAD || instr.getOpCode() == JavaInstructionsOpcodes.AASTORE) { return true; } if (instr.getOpCode() != JavaInstructionsOpcodes.PUTFIELD && instr.getOpCode() != JavaInstructionsOpcodes.GETFIELD && instr.getOpCode() != JavaInstructionsOpcodes.GETSTATIC && instr.getOpCode() != JavaInstructionsOpcodes.PUTSTATIC) { return false; } GlobalConstantPool pOne = GlobalConstantPool.getInstanceOf(); int index = instr.getOperandsData().intValueUnsigned(); FieldRefInfo fInfo = (FieldRefInfo) pOne.get(index, TagValues.CONSTANT_Fieldref); int nameAndTypeIndex = fInfo.getNameAndTypeIndex().intValueUnsigned(); NameAndTypeInfo nAtInfo = (NameAndTypeInfo) pOne.get(nameAndTypeIndex, TagValues.CONSTANT_NameAndType); String description = ((UTF8Info) pOne.get(nAtInfo.getDescriptorIndex().intValueUnsigned(), TagValues.CONSTANT_Utf8)) .convertBytes(); VerificationFrameFactory frameFactory = VerificationPlaceHolder.getInstanceOf().getFactory(); Type fieldType = frameFactory.createType(); InitializeFirstInstruction.getType(description, 0, fieldType); return fieldType.isReference(); }
public static void main(String[] args) { Type type = null; int y = 2; switch (args.length) { case 1: y = 6; break; case 2: y = 4; } for (int i = 1; i < y; i++) { if (i > y / 2) { type.increment(); } if (i == y / 2) { type = new Type(1); } assert i < y; } assert y / 2 == type.getField(); }
public static void extra(Player player, int[] possibilities, boolean tavern) { if (possibilities.length > 0) { int extra = Random.integer_of(possibilities); if (player.water + extra > player.water_max) { extra = player.water_max - player.water; if (extra == 0) Type.delay_line( "💧: " + Random.text_of( new String[] { "Your waterskin is already full of water, so you add no more.", "There is no room in your waterskin to carry any more water." })); } else if (extra == 0 && !tavern) Type.delay_line("💧: " + Random.text_of(new String[] {"You acquire no extra water."})); player.water += extra; if (extra > 0) Type.delay_line( "💧: " + Random.text_of( new String[] { "You fill up your waterskin, increasing your amount of water by " + extra + " to now be " + player.water, "You add " + extra + " water to your waterskin" }) + "."); } }
/* 120: */ /* 121: */ public int distanceTo(Type other) /* 122: */ { /* 123:132 */ int result = 2147483647; /* 124:133 */ if ((other instanceof MethodType)) /* 125: */ { /* 126:134 */ MethodType mtype = (MethodType) other; /* 127:135 */ if (this._argsType != null) /* 128: */ { /* 129:136 */ int len = this._argsType.size(); /* 130:137 */ if (len == mtype._argsType.size()) /* 131: */ { /* 132:138 */ result = 0; /* 133:139 */ for (int i = 0; i < len; i++) /* 134: */ { /* 135:140 */ Type arg1 = (Type) this._argsType.elementAt(i); /* 136:141 */ Type arg2 = (Type) mtype._argsType.elementAt(i); /* 137:142 */ int temp = arg1.distanceTo(arg2); /* 138:143 */ if (temp == 2147483647) /* 139: */ { /* 140:144 */ result = temp; /* 141:145 */ break; /* 142: */ } /* 143:148 */ result += arg1.distanceTo(arg2); /* 144: */ } /* 145: */ } /* 146: */ } /* 147:153 */ else if (mtype._argsType == null) /* 148: */ { /* 149:154 */ result = 0; /* 150: */ } /* 151: */ } /* 152:157 */ return result; /* 153: */ }
protected Type checkUnaryNumericOp(Type t, Token op) { // Checks Unary operators + and - if (t.isArrayKind()) { System.out.println( "line " + op.getLine() + ": invalid argument to operator `" + op.getText() + "'\n" + " -- expects a numeric argument but found " + t.toString() + "[]"); errorCount++; return Type.errorType; } if (t.isNumericType()) { if (t.isCharType() && op.getText().equals("-")) { return Type.intValue; } else { return t; } } else { System.out.println( "line " + op.getLine() + ": invalid argument type for unary operator `" + op.getText() + "'\n" + " -- expects a numeric argument but found " + t.toString()); errorCount++; return Type.errorType; } } /* End of checkUnaryNumericOp */
protected Type checkBinaryNumericOp(Node exp1, Node exp2, Token op) { // Checks Binary operators +, -, *, /, and % // Do not forget to handle + for pairs of strings. Type t1 = null; // the type attribute of exp1 Type t2 = null; // the type attribute of exp2 // Below are the error messages to be printed when // the type is wrong. The first is for t1 and second for t2. System.out.println( "line " + op.getLine() + ": invalid argument 1 ` " + exp1 + "' for arithmetic operator `" + op.getText() + "'\n" + " -- expects a numeric argument but found " + t1.toString()); System.out.println( "line " + op.getLine() + ": invalid argument 2 ` " + exp2 + "' for arithmetic operator `" + op.getText() + "'\n" + " -- expects a numeric argument but found " + t2.toString()); return null; } /* End of checkBinaryNumericOp */
public static List<Type> subst(List<Type> types, List<Type> arguments, List<Type> parameters) { ArrayList<Type> result = new ArrayList<Type>(types.size()); for (Type type : types) { result.add(type.subst(arguments, parameters)); } return result; }
protected Type checkUnaryBooleanOp(Type t, Token op) { // Checks Unary operator ! if (t.isArrayKind()) { System.out.println( "line " + op.getLine() + ": invalid argument to operator `" + op.getText() + "'\n" + " -- expects a boolean argument but found " + t.toString() + "[]"); errorCount++; return Type.boolValue; } if (t.isBoolType()) { return t; } else { System.out.println( "line " + op.getLine() + ": unary operator `!' expects a boolean argument " + "but found " + t.toString()); errorCount++; return Type.boolValue; } } /* End of checkUnaryBooleanOp */
public boolean equals(Object o) { if (!(o instanceof Type)) return false; Type t = resolve(o); if (this == t) return true; return t.isWildcard(); }
@Nullable private static TypeWrapper wrap(Type type) { if (type == null) { return null; } else if (type instanceof Class) { return new ClassTypeWrapper((Class<?>) type); } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; return new ParameterizedTypeWrapper( toWrappers(parameterizedType.getActualTypeArguments()), (ClassTypeWrapper) wrap(parameterizedType.getRawType()), wrap(parameterizedType.getOwnerType())); } else if (type instanceof WildcardType) { WildcardType wildcardType = (WildcardType) type; return new WildcardTypeWrapper( toWrappers(wildcardType.getUpperBounds()), toWrappers(wildcardType.getLowerBounds()), type.hashCode()); } else if (type instanceof TypeVariable) { TypeVariable<?> typeVariable = (TypeVariable<?>) type; return new TypeVariableTypeWrapper( typeVariable.getName(), toWrappers(typeVariable.getBounds()), type.hashCode()); } else if (type instanceof GenericArrayType) { GenericArrayType genericArrayType = (GenericArrayType) type; return new GenericArrayTypeWrapper( wrap(genericArrayType.getGenericComponentType()), type.hashCode()); } else { throw new IllegalArgumentException("cannot wrap type of type " + type.getClass()); } }
/** * Compare two types in the type lattice. This method returns one of ptolemy.graph.CPO.LOWER, * ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating * the first argument is lower than, equal to, higher than, or incomparable with the second * argument in the type hierarchy, respectively. * * @param type1 an instance of Type. * @param type2 an instance of Type. * @return An integer. */ public static synchronized int compare(Type type1, Type type2) { if ((type1 == null) || (type2 == null)) { throw new IllegalArgumentException( "TypeLattice.compare(Type, Type): " + "one or both of the argument types is null: " + " type1 = " + type1 + ", type2 = " + type2); } // System.out.println("compare " + type1 + " and " + type2 + " = " + _lattice.compare(type1, // type2)); int i1 = type1.getTypeHash(); int i2 = type2.getTypeHash(); // Uncommment the false below to measure the impact of // _lattice.compare() on ptolemy.data package performance... Run // ptolemy/data/type/test/performance.xml before and after...(zk) if ( /*false &&*/ (i1 != Type.HASH_INVALID) && (i2 != Type.HASH_INVALID)) { if (_getCachedTypeComparisonResult(i1, i2) == Type.HASH_INVALID) { _setCachedTypeComparisonResult(i1, i2, _lattice.compare(type1, type2)); } return _getCachedTypeComparisonResult(i1, i2); } return _lattice.compare(type1, type2); }
@Test public void testTerserGetPrimitive_VariesCompositeFirstComponent() throws HL7Exception { final Varies variesField = new Varies(mshOnly); final Primitive comp1Sub1 = Terser.getPrimitive(variesField, 1, 1); comp1Sub1.setValue("comp1Sub1"); final Primitive comp1Sub2 = Terser.getPrimitive(variesField, 1, 2); comp1Sub2.setValue("comp1Sub2"); final Primitive comp2Sub1 = Terser.getPrimitive(variesField, 2, 1); comp2Sub1.setValue("comp2Sub1"); assertEquals(GenericComposite.class, variesField.getData().getClass()); final GenericComposite field = (GenericComposite) variesField.getData(); final Type typeComp1 = field.getComponent(0); assertEquals(typeComp1.getClass(), Varies.class); final Varies variesComp1 = (Varies) typeComp1; assertEquals(GenericComposite.class, variesComp1.getData().getClass()); final GenericComposite comp1 = (GenericComposite) variesComp1.getData(); final Type typeSub1 = comp1.getComponent(1); assertEquals(typeSub1.getClass(), Varies.class); final Varies variesSub1 = (Varies) typeSub1; assertEquals(GenericPrimitive.class, variesSub1.getData().getClass()); assertEquals("comp1Sub1&comp1Sub2^comp2Sub1", PipeParser.encode(variesField, encoders)); }
/** * Resolve current method generic return type to a {@link GenericMetadataSupport}. * * @param method Method to resolve the return type. * @return {@link GenericMetadataSupport} representing this generic return type. */ public GenericMetadataSupport resolveGenericReturnType(Method method) { Type genericReturnType = method.getGenericReturnType(); // logger.log("Method '" + method.toGenericString() + "' has return type : " + // genericReturnType.getClass().getInterfaces()[0].getSimpleName() + " : " + genericReturnType); if (genericReturnType instanceof Class) { return new NotGenericReturnTypeSupport(genericReturnType); } if (genericReturnType instanceof ParameterizedType) { return new ParameterizedReturnType( this, method.getTypeParameters(), (ParameterizedType) method.getGenericReturnType()); } if (genericReturnType instanceof TypeVariable) { return new TypeVariableReturnType( this, method.getTypeParameters(), (TypeVariable) genericReturnType); } throw new MockitoException( "Ouch, it shouldn't happen, type '" + genericReturnType.getClass().getCanonicalName() + "' on method : '" + method.toGenericString() + "' is not supported : " + genericReturnType); }
/** * Checks if the specified item is a QName. Returns the item or throws an exception. * * @param it item * @param empty allow empty result * @return QNm item * @throws QueryException query exception */ protected final QNm toQNm(final Item it, final boolean empty) throws QueryException { if (empty && it == null) return null; final Type ip = checkNoEmpty(it, AtomType.QNM).type; if (ip == AtomType.QNM) return (QNm) it; if (ip.isUntyped()) throw NSSENS_X_X.get(info, ip, AtomType.QNM); throw castError(it, AtomType.QNM, info); }
@Override public AnnotationVisitor visitParameterAnnotation( final int parameter, final String desc, final boolean visible) { AnnotationNode an = new AnnotationNode(desc); if (visible) { if (visibleParameterAnnotations == null) { int params = Type.getArgumentTypes(this.desc).length; visibleParameterAnnotations = (List<AnnotationNode>[]) new List<?>[params]; } if (visibleParameterAnnotations[parameter] == null) { visibleParameterAnnotations[parameter] = new ArrayList<AnnotationNode>(1); } visibleParameterAnnotations[parameter].add(an); } else { if (invisibleParameterAnnotations == null) { int params = Type.getArgumentTypes(this.desc).length; invisibleParameterAnnotations = (List<AnnotationNode>[]) new List<?>[params]; } if (invisibleParameterAnnotations[parameter] == null) { invisibleParameterAnnotations[parameter] = new ArrayList<AnnotationNode>(1); } invisibleParameterAnnotations[parameter].add(an); } return an; }
private void setWorldConfigFile(File newFile) { if ((worldConfigFile == null) || (!newFile.getAbsolutePath().equals(worldConfigFile.getAbsolutePath()))) { worldConfigFile = newFile; if (usable(worldConfigFile)) { // usable world logger.info(worldConfigFile.getPath()); if (newFile.exists()) { worldSpecific = new Configuration(worldConfigFile); logger.info("exists "); worldSpecific.load(); settings.readFrom(worldSpecific); } else { logger.info("doesn't exist"); worldSpecific = new Configuration(worldConfigFile); // else we use the default; settings.readFrom(general); settings.copyTo(worldSpecific); } worldSpecific.save(); } else { logger.info("null file"); worldSpecific = null; settings.readFrom(general); } } }
@Override protected String getMangledNameWithGenerics(boolean convertArrays) { StringBuilder builder = new StringBuilder("_L"); // to distinguish generics that have the same type name, we have to add packages as well for (ModifiedType modifiedType : types) { Type type = modifiedType.getType(); if (type instanceof TypeParameter) // always print _T to avoid problems with CanEqual<T> and CanEqual<V> builder.append("_T"); else if (type instanceof ArrayType) // only convert the first layer { if (convertArrays) builder.append(((ArrayType) type).convertToGeneric().getMangledNameWithGenerics(false)); else builder.append(type.getMangledNameWithGenerics(true)); } else builder.append(type.getMangledNameWithGenerics(true)); // Type type = modifiedType.getType(); // shadow.typecheck.Package _package = type.getPackage(); // builder.append(type.getPackage().getMangledName() + type.getMangledNameWithGenerics()); } builder.append("_R"); return builder.toString(); }
@Test public void equals_different_TYPE() { final Attribute a = new Blueprint().type(Type.of(String.class)).build(); final Attribute b = new Blueprint().type(Type.of(Integer.class)).build(); assertFalse(a.equals(b)); assertFalse(a.hashCode() == b.hashCode()); }
public Map<String, List<Type>> getTypeMapForDocumentType( String typeName, DocumentModel currentDoc) { Type type = getType(typeName); if (type != null) { Map<String, List<Type>> docTypesMap = new HashMap<String, List<Type>>(); Map<String, SubType> allowedSubTypes = type.getAllowedSubTypes(); allowedSubTypes = filterSubTypesFromConfiguration(allowedSubTypes, currentDoc); for (Map.Entry<String, SubType> entry : allowedSubTypes.entrySet()) { if (canCreate(entry.getValue())) { Type subType = getType(entry.getKey()); if (subType != null) { String key = subType.getCategory(); if (key == null) { key = DEFAULT_CATEGORY; } if (!docTypesMap.containsKey(key)) { docTypesMap.put(key, new ArrayList<Type>()); } docTypesMap.get(key).add(subType); } } } return docTypesMap; } return new HashMap<String, List<Type>>(); }
public boolean checkCanPut(Type put_type, Coord c) { int[] dx = {0, -1, -1, -1, 0, 1, 1, 1}; int[] dy = {1, 1, 0, -1, -1, -1, 0, 1}; for (int i = 0; i < 8; i++) { Coord temp; try { temp = new Coord(c.x + dx[i], c.y + dy[i]); } catch (IllegalArgumentException e) { continue; } if (st_board.get(temp).equals(put_type.getReverse().toState()) == true) { boolean flag = false; while (true) { try { temp = new Coord(temp.x + dx[i], temp.y + dy[i]); } catch (IllegalArgumentException e) { break; } if (st_board.get(temp).equals(put_type.toState()) == true) { flag = true; break; } } if (flag == true) return true; } } return false; }
private void checkCompoundIds(Class<?> javaClass) throws IOException { String javaClassName = javaClass.getCanonicalName(); PsiClass psiClass = myJavaPsiFacade.findClass( javaClassName, GlobalSearchScope.moduleWithLibrariesScope(myModule)); assertNotNull(psiClass); for (java.lang.reflect.Method javaMethod : javaClass.getDeclaredMethods()) { Method method = new Method( Type.getType(javaClass).getInternalName(), javaMethod.getName(), Type.getMethodDescriptor(javaMethod)); boolean noKey = javaMethod.getAnnotation(ExpectNoPsiKey.class) != null; PsiMethod psiMethod = psiClass.findMethodsByName(javaMethod.getName(), false)[0]; checkCompoundId(method, psiMethod, noKey); } for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) { Method method = new Method( Type.getType(javaClass).getInternalName(), "<init>", Type.getConstructorDescriptor(constructor)); boolean noKey = constructor.getAnnotation(ExpectNoPsiKey.class) != null; PsiMethod[] constructors = psiClass.getConstructors(); PsiMethod psiMethod = constructors[0]; checkCompoundId(method, psiMethod, noKey); } }
/** * Adds a number or string constant to the constant pool of the class being build. Does nothing if * the constant pool already contains a similar item. * * @param cst the value of the constant to be added to the constant pool. This parameter must be * an {@link Integer}, a {@link Float}, a {@link Long}, a {@link Double}, a {@link String} or * a {@link Type}. * @return a new or already existing constant item with the given value. */ Item newConstItem(final Object cst) { if (cst instanceof Integer) { int val = ((Integer) cst).intValue(); return newInteger(val); } else if (cst instanceof Byte) { int val = ((Byte) cst).intValue(); return newInteger(val); } else if (cst instanceof Character) { int val = ((Character) cst).charValue(); return newInteger(val); } else if (cst instanceof Short) { int val = ((Short) cst).intValue(); return newInteger(val); } else if (cst instanceof Boolean) { int val = ((Boolean) cst).booleanValue() ? 1 : 0; return newInteger(val); } else if (cst instanceof Float) { float val = ((Float) cst).floatValue(); return newFloat(val); } else if (cst instanceof Long) { long val = ((Long) cst).longValue(); return newLong(val); } else if (cst instanceof Double) { double val = ((Double) cst).doubleValue(); return newDouble(val); } else if (cst instanceof String) { return newString((String) cst); } else if (cst instanceof Type) { Type t = (Type) cst; return newClassItem(t.getSort() == Type.OBJECT ? t.getInternalName() : t.getDescriptor()); } else { throw new IllegalArgumentException("value " + cst); } }
/** internal reality checks on param/arg kinds */ private boolean checkKindAgreement(final Type abs, final Type argDeref) { final Kind absKind = abs.getKind(); if (!(absKind instanceof ArrowKind)) { Session.error( loc, "internal error: abs {0} has non-lambda kind {1} in type app {2}", abs.dump(), absKind.dump(), dump()); return false; } final Kind paramKind = ((ArrowKind) absKind).getParamKind(); final Kind argKind = argDeref.getKind(); if (!paramKind.equals(argKind)) { Session.error( loc, "internal error: param kind {0} incompatible with arg kind {1} in type app {2}", paramKind.dump(), argKind.dump(), dump()); return false; } return true; }
protected static String calcLabel(ValueDescriptor descriptor) { final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl) descriptor; final Value value = valueDescriptor.getValue(); if (value instanceof ObjectReference) { if (value instanceof StringReference) { return ((StringReference) value).value(); } else if (value instanceof ClassObjectReference) { ReferenceType type = ((ClassObjectReference) value).reflectedType(); return (type != null) ? type.name() : "{...}"; } else { final ObjectReference objRef = (ObjectReference) value; final Type type = objRef.type(); if (type instanceof ClassType && ((ClassType) type).isEnum()) { final String name = getEnumConstantName(objRef, (ClassType) type); if (name != null) { return name; } else { return type.name(); } } else { return ""; } } } else if (value == null) { //noinspection HardCodedStringLiteral return "null"; } else { return DebuggerBundle.message("label.undefined"); } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + base.hashCode(); result = 31 * result + arg.hashCode(); return result; }
@Test public void testWithGenericType() { val arrayDequeCallable = Type.of("java.util.ArrayDeque").withTypeArgument(Type.of("java.util.Callable")); assertEquals("java.util.ArrayDeque", arrayDequeCallable.getClassName()); assertEquals("java.util.Callable", arrayDequeCallable.getTypeArguments().get(0).getClassName()); }
protected String getTypeString(SootField soot_field) { Type type = soot_field.getType(); String name = type.toString(); char[] name_array = name.toCharArray(); name_array[0] = Character.toUpperCase(name_array[0]); return new String(name_array); }