Skip to content

Commit

Permalink
IGNITE-14823 Class abbrevation (#11092)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Dec 13, 2023
1 parent 34b9616 commit 1ed6d18
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2025,12 +2025,12 @@ private List<Expression> harmonize(final List<Expression> argValueList,
return argValueList;
}
assert (nullCount > 0) == type.isNullable();
final Type javaClass =
final Type javaCls =
translator.typeFactory.getJavaClass(type);
final List<Expression> harmonizedArgValues = new ArrayList<>();
for (Expression argValue : argValueList) {
harmonizedArgValues.add(
EnumUtils.convert(argValue, javaClass));
EnumUtils.convert(argValue, javaCls));
}
return harmonizedArgValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,16 @@ public static Expression translateLiteral(
return RexImpTable.FALSE_EXPR;
}
}
Type javaClass = typeFactory.getJavaClass(type);
Type javaCls = typeFactory.getJavaClass(type);
final Object value2;
switch (literal.getType().getSqlTypeName()) {
case DECIMAL:
final BigDecimal bd = literal.getValueAs(BigDecimal.class);
if (javaClass == float.class)
return Expressions.constant(bd, javaClass);
else if (javaClass == double.class)
return Expressions.constant(bd, javaClass);
assert javaClass == BigDecimal.class;
if (javaCls == float.class)
return Expressions.constant(bd, javaCls);
else if (javaCls == double.class)
return Expressions.constant(bd, javaCls);
assert javaCls == BigDecimal.class;
return Expressions.call(
IgniteSqlFunctions.class,
"toBigDecimal",
Expand All @@ -711,7 +711,7 @@ else if (javaClass == double.class)
case INTERVAL_YEAR_MONTH:
case INTERVAL_MONTH:
value2 = literal.getValueAs(Integer.class);
javaClass = int.class;
javaCls = int.class;
break;
case TIMESTAMP:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
Expand All @@ -726,7 +726,7 @@ else if (javaClass == double.class)
case INTERVAL_MINUTE_SECOND:
case INTERVAL_SECOND:
value2 = literal.getValueAs(Long.class);
javaClass = long.class;
javaCls = long.class;
break;
case CHAR:
case VARCHAR:
Expand All @@ -743,15 +743,15 @@ else if (javaClass == double.class)
throw new IllegalStateException("Unsupported data type: " + literal.getType());
case SYMBOL:
value2 = literal.getValueAs(Enum.class);
javaClass = value2.getClass();
javaCls = value2.getClass();
break;
default:
final Primitive primitive = Primitive.ofBoxOr(javaClass);
final Primitive primitive = Primitive.ofBoxOr(javaCls);
final Comparable value = literal.getValueAs(Comparable.class);

value2 = primitive != null && value instanceof Number ? primitive.number((Number)value) : value;
}
return Expressions.constant(value2, javaClass);
return Expressions.constant(value2, javaCls);
}

/** */
Expand Down Expand Up @@ -975,15 +975,15 @@ private static Expression scaleIntervalToNumber(
*/
private ConstantExpression getTypedNullLiteral(RexLiteral literal) {
assert literal.isNull();
Type javaClass = typeFactory.getJavaClass(literal.getType());
Type javaCls = typeFactory.getJavaClass(literal.getType());
switch (literal.getType().getSqlTypeName()) {
case DATE:
case TIME:
case TIME_WITH_LOCAL_TIME_ZONE:
case INTERVAL_YEAR:
case INTERVAL_YEAR_MONTH:
case INTERVAL_MONTH:
javaClass = Integer.class;
javaCls = Integer.class;
break;
case TIMESTAMP:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
Expand All @@ -997,12 +997,12 @@ private ConstantExpression getTypedNullLiteral(RexLiteral literal) {
case INTERVAL_MINUTE:
case INTERVAL_MINUTE_SECOND:
case INTERVAL_SECOND:
javaClass = Long.class;
javaCls = Long.class;
break;
}
return javaClass == null || javaClass == Void.class
return javaCls == null || javaCls == Void.class
? RexImpTable.NULL_EXPR
: Expressions.constant(null, javaClass);
: Expressions.constant(null, javaCls);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ SqlOperator toOp(Map<String, Object> map) {
for (SqlOperator operator : operators)
if (operator.kind == sqlKind)
return operator;
String class_ = (String)map.get("class");
if (class_ != null)
return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
String cls_ = (String)map.get("class");
if (cls_ != null)
return AvaticaUtils.instantiatePlugin(SqlOperator.class, cls_);
return null;
}

Expand All @@ -601,9 +601,9 @@ <T> Map<String, T> map() {
<T extends Enum<T>> T toEnum(Object o) {
if (o instanceof Map) {
Map<String, Object> map = (Map<String, Object>)o;
String class_ = (String)map.get("class");
String cls_ = (String)map.get("class");
String name = map.get("name").toString();
return Util.enumVal((Class<T>)classForName(class_, false), name);
return Util.enumVal((Class<T>)classForName(cls_, false), name);
}

assert o instanceof String && ENUM_BY_NAME.containsKey(o);
Expand Down
2 changes: 1 addition & 1 deletion modules/checkstyle/src/main/resources/abbrevations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ array,arr
attribute,attr
attributes,attrs
buffer,buf
#class,cls
class,cls
#command,cmd
#config,cfg
#context,ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ public static void main(String[] args) throws Exception {
* @throws IOException If generation failed.
*/
private <T> void generateAndWrite(Class<T> clazz, String srcRoot) throws IOException {
File walkerClass = new File(srcRoot + '/' + WALKER_PACKAGE.replaceAll("\\.", "/") + '/' +
File walkerCls = new File(srcRoot + '/' + WALKER_PACKAGE.replaceAll("\\.", "/") + '/' +
clazz.getSimpleName() + "Walker.java");

Collection<String> code = generate(clazz);

walkerClass.createNewFile();
walkerCls.createNewFile();

try (FileWriter writer = new FileWriter(walkerClass)) {
try (FileWriter writer = new FileWriter(walkerCls)) {
for (String line : code) {
writer.write(line);
writer.write('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ private GridByteArrayList sendClassRequest(String name, String path) throws Clas
nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap);
}

List<IgniteException> classRequestExceptions = new ArrayList<>();
List<IgniteException> clsRequestExceptions = new ArrayList<>();

for (UUID nodeId : nodeListCp) {
if (nodeId.equals(ctx.discovery().localNode().id()))
Expand Down Expand Up @@ -644,7 +644,7 @@ private GridByteArrayList sendClassRequest(String name, String path) throws Clas

LT.warn(log, msg);

classRequestExceptions.add(new IgniteException(msg));
clsRequestExceptions.add(new IgniteException(msg));

synchronized (mux) {
if (missedRsrcs != null)
Expand Down Expand Up @@ -683,20 +683,20 @@ else if (log.isDebugEnabled())
else if (log.isDebugEnabled())
log.debug(msg);

classRequestExceptions.add(new IgniteException(msg, e));
clsRequestExceptions.add(new IgniteException(msg, e));
}
}
catch (TimeoutException e) {
classRequestExceptions.add(new IgniteException("Failed to send class-loading request to node (is node alive?) " +
clsRequestExceptions.add(new IgniteException("Failed to send class-loading request to node (is node alive?) " +
"[node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId +
", clsLoadersHierarchy=" + clsLdrHierarchy + ']', e));
}
}

if (!classRequestExceptions.isEmpty()) {
IgniteException exception = classRequestExceptions.remove(0);
if (!clsRequestExceptions.isEmpty()) {
IgniteException exception = clsRequestExceptions.remove(0);

for (Exception e : classRequestExceptions)
for (Exception e : clsRequestExceptions)
exception.addSuppressed(e);

LT.warn(log, exception.getMessage(), exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public void topologyVersion(AffinityTopologyVersion topVer) {
@Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
super.finishUnmarshal(ctx, ldr);

ClassLoader classLoader = U.resolveClassLoader(ldr, ctx.gridConfig());
ClassLoader clsLoader = U.resolveClassLoader(ldr, ctx.gridConfig());

Collection<byte[]> objectsToUnmarshall = new ArrayList<>();

Expand Down Expand Up @@ -598,8 +598,8 @@ public void topologyVersion(AffinityTopologyVersion topVer) {
new IgniteThrowableFunction<byte[], Object>() {
@Override public Object apply(byte[] binary) throws IgniteCheckedException {
return compressed()
? U.unmarshalZip(ctx.marshaller(), binary, classLoader)
: U.unmarshal(ctx, binary, classLoader);
? U.unmarshalZip(ctx.marshaller(), binary, clsLoader)
: U.unmarshal(ctx, binary, clsLoader);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class ClassPathContentLoggingTest extends GridCommonAbstractTest {
*/
@Test
public void testClassPathContentLogging() throws Exception {
String javaClassPath = System.getProperty("java.class.path", ".");
String javaClsPath = System.getProperty("java.class.path", ".");

LogListener lsnr = LogListener
.matches("List of files containing in classpath")
Expand All @@ -110,7 +110,7 @@ public void testClassPathContentLogging() throws Exception {
for (Path jar : jars)
contenLsnrBuilder.andMatches(jar.getFileName().toString());

Arrays.stream(javaClassPath.split(File.separator))
Arrays.stream(javaClsPath.split(File.separator))
.filter(fileName -> new File(fileName).isDirectory())
.forEach(contenLsnrBuilder::andMatches);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class MarshallerContextLockingSelfTest extends GridCommonAbstractTest {
public void testMultithreadedUpdate() throws Exception {
multithreaded(new Callable<Object>() {
@Override public Object call() throws Exception {
GridTestClassLoader classLoader = new GridTestClassLoader(
GridTestClassLoader clsLoader = new GridTestClassLoader(
InternalExecutor.class.getName(),
MarshallerContextImpl.class.getName(),
MarshallerContextImpl.CombinedMap.class.getName(),
Expand All @@ -93,9 +93,9 @@ public void testMultithreadedUpdate() throws Exception {
MarshallerMappingTransport.class.getName()
);

Thread.currentThread().setContextClassLoader(classLoader);
Thread.currentThread().setContextClassLoader(clsLoader);

Class clazz = classLoader.loadClass(InternalExecutor.class.getName());
Class clazz = clsLoader.loadClass(InternalExecutor.class.getName());

Object internelExecutor = clazz.newInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1541,8 +1541,8 @@ else if ("val2".equals(fieldName))
*/
@Test
public void testSimpleNameLowerCaseMappers() throws Exception {
BinaryTypeConfiguration innerClassType = new BinaryTypeConfiguration(InnerMappedObject.class.getName());
BinaryTypeConfiguration publicClassType = new BinaryTypeConfiguration(TestMappedObject.class.getName());
BinaryTypeConfiguration innerClsType = new BinaryTypeConfiguration(InnerMappedObject.class.getName());
BinaryTypeConfiguration publicClsType = new BinaryTypeConfiguration(TestMappedObject.class.getName());
BinaryTypeConfiguration typeWithCustomMapper = new BinaryTypeConfiguration(CustomMappedObject2.class.getName());

typeWithCustomMapper.setIdMapper(new BinaryIdMapper() {
Expand All @@ -1565,7 +1565,7 @@ else if ("val2".equals(fieldName))
});

BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true),
Arrays.asList(innerClassType, publicClassType, typeWithCustomMapper));
Arrays.asList(innerClsType, publicClsType, typeWithCustomMapper));

InnerMappedObject innerObj = new InnerMappedObject(10, "str1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,62 +150,62 @@ private static String asBinaryObjectString(IgniteCache<Object, Object> cache, Ob

/** */
private Object newExtInstance1() throws Exception {
ClassPool classPool = new ClassPool(ClassPool.getDefault());

CtClass aClass = classPool.makeClass("ExternalTestClass1");
aClass.addInterface(classPool.get("java.io.Externalizable"));
aClass.addField(CtField.make("private int x;", aClass));
aClass.addConstructor(CtNewConstructor.make("public ExternalTestClass1() {}", aClass));
aClass.addConstructor(CtNewConstructor.make("public ExternalTestClass1(int x0) { x = x0; }", aClass));
aClass.addMethod(CtNewMethod.make(
ClassPool clsPool = new ClassPool(ClassPool.getDefault());

CtClass aCls = clsPool.makeClass("ExternalTestClass1");
aCls.addInterface(clsPool.get("java.io.Externalizable"));
aCls.addField(CtField.make("private int x;", aCls));
aCls.addConstructor(CtNewConstructor.make("public ExternalTestClass1() {}", aCls));
aCls.addConstructor(CtNewConstructor.make("public ExternalTestClass1(int x0) { x = x0; }", aCls));
aCls.addMethod(CtNewMethod.make(
"public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { out.writeInt(x); }",
aClass));
aClass.addMethod(CtNewMethod.make(
aCls));
aCls.addMethod(CtNewMethod.make(
"public void readExternal(java.io.ObjectInput in) throws java.io.IOException { x = in.readInt(); }",
aClass));
aCls));

ClassLoader extClsLdr = new ClassLoader() {
{
byte[] bytecode = aClass.toBytecode();
byte[] bytecode = aCls.toBytecode();

defineClass("ExternalTestClass1", bytecode, 0, bytecode.length);
}
};

Class<?> extClass = extClsLdr.loadClass("ExternalTestClass1");
Class<?> extCls = extClsLdr.loadClass("ExternalTestClass1");

Constructor<?> ctor = extClass.getConstructor(int.class);
Constructor<?> ctor = extCls.getConstructor(int.class);

return ctor.newInstance(42);
}

/** */
private Object newExtInstance2() throws Exception {
ClassPool classPool = new ClassPool(ClassPool.getDefault());

CtClass aClass = classPool.makeClass("ExternalTestClass2");
aClass.addInterface(classPool.get("java.io.Serializable"));
aClass.addField(CtField.make("private int x;", aClass));
aClass.addConstructor(CtNewConstructor.make("public ExternalTestClass2() {}", aClass));
aClass.addConstructor(CtNewConstructor.make("public ExternalTestClass2(int x0) { x = x0; }", aClass));
aClass.addMethod(CtNewMethod.make(
ClassPool clsPool = new ClassPool(ClassPool.getDefault());

CtClass aCls = clsPool.makeClass("ExternalTestClass2");
aCls.addInterface(clsPool.get("java.io.Serializable"));
aCls.addField(CtField.make("private int x;", aCls));
aCls.addConstructor(CtNewConstructor.make("public ExternalTestClass2() {}", aCls));
aCls.addConstructor(CtNewConstructor.make("public ExternalTestClass2(int x0) { x = x0; }", aCls));
aCls.addMethod(CtNewMethod.make(
"private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { out.writeInt(x); }",
aClass));
aClass.addMethod(CtNewMethod.make(
aCls));
aCls.addMethod(CtNewMethod.make(
"private void readObject(java.io.ObjectInputStream in) throws java.io.IOException { x = in.readInt(); }",
aClass));
aCls));

ClassLoader extClsLdr = new ClassLoader() {
{
byte[] bytecode = aClass.toBytecode();
byte[] bytecode = aCls.toBytecode();

defineClass("ExternalTestClass2", bytecode, 0, bytecode.length);
}
};

Class<?> extClass = extClsLdr.loadClass("ExternalTestClass2");
Class<?> extCls = extClsLdr.loadClass("ExternalTestClass2");

Constructor<?> ctor = extClass.getConstructor(int.class);
Constructor<?> ctor = extCls.getConstructor(int.class);

return ctor.newInstance(42);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public abstract class IgniteCacheAbstractExecutionContextTest extends IgniteCach
*/
@Test
public void testUsersClassLoader() throws Exception {
UsersClassLoader testClassLdr = (UsersClassLoader)grid(0).configuration().getClassLoader();
UsersClassLoader testClsLdr = (UsersClassLoader)grid(0).configuration().getClassLoader();

Object val = testClassLdr.loadClass(TEST_VALUE).newInstance();
Object val = testClsLdr.loadClass(TEST_VALUE).newInstance();

IgniteCache<Object, Object> jcache = grid(0).cache(DEFAULT_CACHE_NAME);

Expand All @@ -79,7 +79,7 @@ public void testUsersClassLoader() throws Exception {

// Check that entry was loaded by user's classloader.
if (idx == 0)
assertEquals(testClassLdr, jcache.get(i).getClass().getClassLoader());
assertEquals(testClsLdr, jcache.get(i).getClass().getClassLoader());
else
assertEquals(grid(idx).configuration().getClassLoader(),
grid(idx).cache(DEFAULT_CACHE_NAME).get(i).getClass().getClassLoader());
Expand Down
Loading

0 comments on commit 1ed6d18

Please sign in to comment.