@Test public void notNullByDefault_package_qualifiedName() { String packageInfoSource = String.format( "@%s\n" + "package %s;\n", ParametersAreNonnullByDefault.class.getName(), PACKAGE); String testSource = String.format( "package %s;\n" + "" + "public class %s {\n" + "\n" + " public %s(Integer intParam) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(null);\n" + " }\n" + "}", PACKAGE, CLASS_NAME, CLASS_NAME, CLASS_NAME); expectNpeFromParameterCheck(testSource, "intParam", expectRunResult); doTest(new TestSourceImpl(testSource, PACKAGE + "." + CLASS_NAME), new TestSourceImpl(packageInfoSource, PACKAGE + "." + PACKAGE_INFO)); }
@Test public void notNullByDefault_class() { String testSource = String.format( "@%s\n" + "public class %s {\n" + "\n" + " public %s(Integer intParam) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(null);\n" + " }\n" + "}", ParametersAreNonnullByDefault.class.getName(), CLASS_NAME, CLASS_NAME, CLASS_NAME); expectNpeFromParameterCheck(testSource, "intParam", expectRunResult); doTest(CLASS_NAME, testSource); }
@Test public void notNullByDefault_method() { String testSource = String.format( "public class %s {\n" + "\n" + " @%s\n" + " public %s(Integer intParam) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(null);\n" + " }\n" + "}", CLASS_NAME, ParametersAreNonnullByDefault.class.getName(), CLASS_NAME, CLASS_NAME); expectNpeFromParameterCheck(testSource, "intParam", expectRunResult); doTest(CLASS_NAME, testSource); }
@Test public void notNullByDefault_nullableArgument() { String testSource = String.format( "@%s\n" + "public class %s {\n" + "\n" + " public %s(@%s Integer intParam) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(null);\n" + " }\n" + "}", ParametersAreNonnullByDefault.class.getName(), CLASS_NAME, CLASS_NAME, Nullable.class.getName(), CLASS_NAME); doTest(CLASS_NAME, testSource); }
@Test public void notNullByDefault_customNullableAnnotation() { String testSource = String.format( "@%s\n" + "public class %s {\n" + "\n" + " public %s(@%s Integer intParam) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(null);\n" + " }\n" + "}", ParametersAreNonnullByDefault.class.getName(), CLASS_NAME, CLASS_NAME, NN.class.getName(), CLASS_NAME); settingsBuilder.withNullableAnnotations(NN.class.getName()); doTest(CLASS_NAME, testSource); }
@Test public void booleanParameter() { String testSource = String.format( "package %s;\n" + "\n" + "@%s\n" + "public class %s {\n" + "\n" + " public %s(boolean expression) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(true);\n" + " }\n" + "}", PACKAGE, ParametersAreNonnullByDefault.class.getName(), CLASS_NAME, CLASS_NAME, CLASS_NAME); doTest(testSource); }
@Override @ParametersAreNonnullByDefault public Response intercept(Chain chain) throws IOException { Request original = chain.request(); if (original.url().encodedPath().equals("/oauth/token")) { return chain.proceed(original.newBuilder() .header("Content-Type", "application/x-www-form-urlencoded") .header("Authorization", loginAuthorizationHeader) .build()); } else if (tokenManager.getAccessToken() != null) { return chain.proceed(original.newBuilder() .header("Authorization", "Bearer " + tokenManager.getAccessToken()) .build()); } else { return chain.proceed(original); } }
@Override @ParametersAreNonnullByDefault public boolean doAuthenticate(Context context) { boolean isUserAuthenticated = false; final String userName = context.getUsername(); final String password = context.getPassword(); // Cleanup basic auth windows principal from HttpSession windowsAuthenticationHelper.removeWindowsPrincipalForBasicAuth(context.getRequest()); if (StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password)) { // Cleanup Windows Principal for sso only in case we are doing basic auth windowsAuthenticationHelper.removeWindowsPrincipalForSso(context.getRequest()); WindowsPrincipal windowsPrincipal = windowsAuthenticationHelper.logonUser(userName, password); if (windowsPrincipal != null) { isUserAuthenticated = true; windowsAuthenticationHelper.setWindowsPrincipalForBasicAuth(context.getRequest(), windowsPrincipal); } } else { isUserAuthenticated = windowsAuthenticationHelper.isUserSsoAuthenticated(context.getRequest()); } return isUserAuthenticated; }
@Override @ParametersAreNonnullByDefault public void doRender(EntitySmokeBomb entity, double x, double y, double z, float entityYaw, float partialTicks) { GlStateManager.pushMatrix(); GlStateManager.translate((float)x, (float)y, (float)z); GlStateManager.enableRescaleNormal(); GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); if (this.renderOutlines) { GlStateManager.enableColorMaterial(); GlStateManager.enableOutlineMode(this.getTeamColor(entity)); } this.renderItem.renderItem(this.item, ItemCameraTransforms.TransformType.GROUND); if (this.renderOutlines) { GlStateManager.disableOutlineMode(); GlStateManager.disableColorMaterial(); } GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); }
@Override @ParametersAreNonnullByDefault public void doRender(EntityRopeCoil entity, double x, double y, double z, float entityYaw, float partialTicks) { GlStateManager.pushMatrix(); GlStateManager.translate((float)x, (float)y, (float)z); GlStateManager.enableRescaleNormal(); GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); if (this.renderOutlines) { GlStateManager.enableColorMaterial(); GlStateManager.enableOutlineMode(this.getTeamColor(entity)); } this.renderItem.renderItem(this.item, ItemCameraTransforms.TransformType.GROUND); if (this.renderOutlines) { GlStateManager.disableOutlineMode(); GlStateManager.disableColorMaterial(); } GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); }
@Override @ParametersAreNonnullByDefault public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) { Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(slot, stack); if(slot == EntityEquipmentSlot.OFFHAND || slot == EntityEquipmentSlot.MAINHAND) { if (this.hasSwordBlade(stack)) { multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 3.0 + (ConfigurationHandler.getInstance().damage), 0)); } else { multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 0, 0)); } multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", 1.8, 0)); } return multimap; }
public Cache(final Loader<T> loader) { cache = CacheBuilder.newBuilder() .maximumSize(10000) .expireAfterWrite(10, TimeUnit.MINUTES) .build(new CacheLoader<String, CompletableFuture<Data<T>>>() { @ParametersAreNonnullByDefault @Override public CompletableFuture<Data<T>> load(final String key) { CompletableFuture<Data<T>> result = loader.get(key); result.exceptionally(ex -> { invalidateCache(key); return null; }); return result; } }); }
@Nonnull @ParametersAreNonnullByDefault public static Skin create(BufferedImage image) { Preconditions.checkNotNull(image, "image"); Preconditions.checkArgument(image.getHeight() == 32 && image.getWidth() == 64, "Image is not 32x64"); byte[] mcpeTexture = new byte[32 * 64 * 4]; int at = 0; for (int i = 0; i < image.getHeight(); i++) { for (int i1 = 0; i1 < image.getWidth(); i1++) { int rgb = image.getRGB(i, i1); mcpeTexture[at++] = (byte) ((rgb & 0x00ff0000) >> 16); mcpeTexture[at++] = (byte) ((rgb & 0x0000ff00) >> 8); mcpeTexture[at++] = (byte) (rgb & 0x000000ff); mcpeTexture[at++] = (byte) ((rgb >> 24) & 0xff); } } return new Skin("Standard_Custom", mcpeTexture); }
/** * Create new composite listener for a collection of delegates. */ @SafeVarargs public static <T extends ParseTreeListener> T create(Class<T> type, T... delegates) { ImmutableList<T> listeners = ImmutableList.copyOf(delegates); return Reflection.newProxy(type, new AbstractInvocationHandler() { @Override @ParametersAreNonnullByDefault protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { for (T listener : listeners) { method.invoke(listener, args); } return null; } @Override public String toString() { return MoreObjects.toStringHelper("CompositeParseTreeListener") .add("listeners", listeners) .toString(); } }); }
public RolesCache(int expiryMS) { rolesCache = CacheBuilder.newBuilder() .concurrencyLevel(concurrencyLevel) .maximumSize(maximumSize) .expireAfterWrite(expiryMS, TimeUnit.MILLISECONDS) .removalListener( new RemovalListener<String, Set<String>>() { { LOGGER.debug("Removal Listener created"); } @Override public void onRemoval(@ParametersAreNonnullByDefault RemovalNotification<String, Set<String>> notification) { LOGGER.debug("This data from " + notification.getKey() + " evacuated due:" + notification.getCause()); } } ).build(); fallbackRolesCache = CacheBuilder.newBuilder() .concurrencyLevel(concurrencyLevel) // handle 10 concurrent request without a problem .maximumSize(maximumSize) // Hold 500 sessions before remove them .build(); LOGGER.info("RolesCache initialized with expiry={}", expiryMS); }
@Override public ListenableFuture<Void> log(final String category, final Iterable<String> lines) { ListenableFuture<Void> upload = offlineScribeLogger.log(category, lines); Futures.addCallback( upload, new FutureCallback<Void>() { @Override public void onSuccess(Void result) {} @Override @ParametersAreNonnullByDefault public void onFailure(Throwable t) { if (!blacklistCategories.contains(category)) { storedCategoriesWithLines.incrementAndGet(); } } }, MoreExecutors.directExecutor()); return upload; }
@Test public void customNotBuiltinException() { String testClassSource = String.format( "package %s;\n" + "\n" + "@%s\n" + "public class %s {\n" + "\n" + " public %s(Integer intParam) {\n" + " }\n" + "\n" + " public static void main(String[] args) {\n" + " new %s(null);\n" + " }\n" + "}", PACKAGE, ParametersAreNonnullByDefault.class.getName(), CLASS_NAME, CLASS_NAME, CLASS_NAME); String exceptionPackage = PACKAGE + ".util"; String exceptionClass = "MyException"; String qualifiedExceptionClass = exceptionPackage + "." + exceptionClass; String exceptionSource = String.format( "package %s;\n"+ "\n" + "public class %s extends RuntimeException {\n" + " public %s(String message) {\n" + " super(message);\n" + " }\n" + "}\n" + "\n", exceptionPackage, exceptionClass, exceptionClass); settingsBuilder.withExceptionToThrow(InstrumentationType.METHOD_PARAMETER, qualifiedExceptionClass); expectRunResult.withExceptionClass(qualifiedExceptionClass) .withExceptionMessageSnippet("intParam") .atLine(findLineNumber(testClassSource, "intParam")); doTest(new TestSourceImpl(testClassSource, PACKAGE + "." + CLASS_NAME), new TestSourceImpl(exceptionSource, qualifiedExceptionClass)); }
/** * Retrieves the group information for the user. * * @return A {@link Collection} of groups the user is member of. */ @ParametersAreNonnullByDefault @Override public Collection<String> doGetGroups(Context context) { WindowsPrincipal windowsPrincipal = windowsAuthenticationHelper.getWindowsPrincipal(context.getRequest(), WindowsAuthenticationHelper.BASIC_AUTH_PRINCIPAL_KEY); if (windowsPrincipal == null) { windowsPrincipal = windowsAuthenticationHelper.getWindowsPrincipal(context.getRequest(), WindowsAuthenticationHelper.SSO_PRINCIPAL_KEY); } return windowsPrincipal != null ? windowsAuthenticationHelper.getUserGroups(windowsPrincipal) : null; }
@Override @ParametersAreNonnullByDefault protected void onImpact(RayTraceResult impact) { World world = this.getEntityWorld(); BlockPos pos = this.getBlockPosFromImpact(impact); this.clearRevealedStatus(world, pos); this.createSmokeCloud(world, pos); }
@Override @ParametersAreNonnullByDefault public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if(player.isSneaking()) { if(world.isRemote) { return new ActionResult<>(EnumActionResult.PASS, stack); } else { this.attemptToCreateRopeCoil(player); return new ActionResult<>(EnumActionResult.SUCCESS, stack); } } return new ActionResult<>(EnumActionResult.PASS, stack); }
@Override @ParametersAreNonnullByDefault public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { if(!world.isRemote) { boolean crit = player.isPotionActive(PotionRegistry.getInstance().potionNinjaHidden); EntityShuriken shuriken = new EntityShuriken(world, player, crit); world.spawnEntity(shuriken); if (!player.capabilities.isCreativeMode) { player.inventory.decrStackSize(player.inventory.currentItem, 1); } NinjaAuraHandler.getInstance().revealEntity(player, ConfigurationHandler.getInstance().hidingCoolDown); } return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand)); }
@Override @ParametersAreNonnullByDefault public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { if(!world.isRemote) { EntityRopeCoil rope = new EntityRopeCoil(world, player); world.spawnEntity(rope); if (!player.capabilities.isCreativeMode) { player.inventory.decrStackSize(player.inventory.currentItem, 1); } } return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand)); }
@Override @ParametersAreNonnullByDefault public void doRender(EntityShuriken entity, double x, double y, double z, float entityYaw, float partialTicks) { GlStateManager.pushMatrix(); //translate and rotate according to throwing heading double vX = entity.getDirection().xCoord; double vY = entity.getDirection().yCoord; double vZ = entity.getDirection().zCoord; double alpha = 180*Math.atan2(vZ, vX)/Math.PI; double beta = 180*Math.atan2(vY, Math.sqrt(vX*vX + vZ*vZ))/Math.PI; GlStateManager.translate((float) x, (float) y, (float) z); GlStateManager.rotate((float) -alpha, 0, 1, 0); GlStateManager.rotate((float) beta, 0, 0, 1); //rotate around z-axis int period = 600; int time = (int) (System.currentTimeMillis() % period); float angle = -360 * ((float) time) / ((float) period); float dy = -0.125F; GL11.glRotatef(angle, 0, 0, 1); GL11.glTranslatef(0, dy, 0); GlStateManager.enableRescaleNormal(); this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); if (this.renderOutlines) { GlStateManager.enableColorMaterial(); GlStateManager.enableOutlineMode(this.getTeamColor(entity)); } this.renderItem.renderItem(this.item, ItemCameraTransforms.TransformType.GROUND); if (this.renderOutlines) { GlStateManager.disableOutlineMode(); GlStateManager.disableColorMaterial(); } GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); }
@Override @Deprecated @SuppressWarnings("deprecation") @ParametersAreNonnullByDefault public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(ItemRegistry.getInstance().itemRope); }
@Override @ParametersAreNonnullByDefault public void randomTick(World world, BlockPos pos, IBlockState state, Random random) { int meta = this.getMetaFromState(state); if (meta < 15) { world.setBlockState(pos, this.getStateFromMeta(Math.min(meta + 2 + random.nextInt(3), 15)), 6); } else { world.setBlockToAir(pos); } }
@Override @ParametersAreNonnullByDefault protected void onImpact(RayTraceResult impact) { ManeuverGear.instance.getLogger().debug("impact " + (this.getEntityWorld().isRemote ? "client side" : "server side")); double yaw = -Math.atan2(motionZ, motionX); double pitch = Math.asin(motionY / Math.sqrt(motionX * motionX + motionZ * motionZ)); DartHandler.instance.onDartAnchored(this, impact.hitVec.xCoord, impact.hitVec.yCoord, impact.hitVec.zCoord, (float) yaw, (float) pitch); }
@Override @ParametersAreNonnullByDefault public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { if(world.isRemote) { new MessageEquipManeuverGear(hand).sendToServer(); } return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); }
@Override @ParametersAreNonnullByDefault public void doRender(EntityDart dart, double x, double y, double z, float float1, float partialTicks) { renderEntity(dart, x, y, z, partialTicks); EntityPlayer player = dart.getPlayer(); if (player == null) { return; } if (this.renderManager.options.thirdPersonView > 0 || player != Minecraft.getMinecraft().player) { this.renderWireThirdPerson(dart, player, x, y, z, partialTicks); } else { renderWireFirstPerson(dart, player, x, y, z, partialTicks); } }
@Override @ParametersAreNonnullByDefault public boolean processInitialInteract(EntityPlayer player, EnumHand hand) { if(!this.getEntityWorld().isRemote && !player.isSneaking()) { player.displayGUIChest(this); player.addStat(StatList.CHEST_OPENED); } return true; }
@ParametersAreNonnullByDefault public Decompressor(final InputStream boiled, final OutputStream out, final int bufferSize) throws Exception { super("boildown-decompressor"); setDaemon(true); boiled_ = checkNotNull(boiled, "Boiled input stream cannot be null."); out_ = checkNotNull(out, "Output stream cannot be null."); bufferSize_ = bufferSize; }
@ParametersAreNonnullByDefault public Boiler(final Socket client, final CompressionMethod method, final Strategery strategery, final String forwardHost, final int forwardPort, final int bufferSize) { client_ = checkNotNull(client, "Client socket cannot be null."); method_ = checkNotNull(method, "Compression method cannot be null."); strategery_ = checkNotNull(strategery, "Strategery cannot be null."); forwardHost_ = checkNotNull(forwardHost, "Forwarding host cannot be null."); forwardPort_ = forwardPort; bufferSize_ = bufferSize; }
@ParametersAreNonnullByDefault public Compressor(final InputStream in, final OutputStream boiled, final int bufferSize) throws Exception { super("boildown-compressor"); setDaemon(true); in_ = checkNotNull(in, "Input stream cannot be null."); boiled_ = checkNotNull(boiled, "Boiled output stream cannot be null."); bufferSize_ = bufferSize; }
@ParametersAreNonnullByDefault public List<GitHubRepositoryHook> getHooks(Repository repository, String username, String password) { WebResource hooksWebResource = resource(repository, "/hooks"); final HTTPBasicAuthFilter httpBasicFilter = new HTTPBasicAuthFilter(username, password); return getAll(hooksWebResource, GitHubRepositoryHook[].class, httpBasicFilter); }
/** * Creates a dynamic proxy implementing the given interface. * All of the proxy's one-arg methods will return their argument. * All other methods return a List containing their arguments. */ protected <T> T newEchoProxyInstance(Class<T> clazz) { return clazz.cast(newProxyInstance(getClass().getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() { @Override @ParametersAreNonnullByDefault protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { return args.length == 0 ? null : args.length == 1 ? args[0] : Arrays.asList(args); } })); }
@Override @ParametersAreNonnullByDefault public void setInventorySlotContents(int slot, ItemStack stack) { ItemStack nonnullstack = stack == null ? ItemStack.EMPTY : stack; this.inv[slot] = nonnullstack; if (!nonnullstack.isEmpty() && nonnullstack.getCount() > this.getInventoryStackLimit()) { nonnullstack.setCount(this.getInventoryStackLimit()); } this.markDirty(); }
@Override @ParametersAreNonnullByDefault public boolean isUsableByPlayer(EntityPlayer player) { return this.world.getTileEntity(this.pos) == this && player.getDistanceSq(this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5) < 64; }
@ParametersAreNonnullByDefault public List<Webhook> load(Guild guild) { return guild.getWebhooks().complete(); }
@Override @ParametersAreNonnullByDefault public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getTileEntity(pos) == this && player.getDistanceSq(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) < 64; }
@Override @ParametersAreNonnullByDefault public void openInventory(EntityPlayer player) { }
@Override @ParametersAreNonnullByDefault public void closeInventory(EntityPlayer player) { }