Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/groovy/grape/Grape.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class Grape {
private static final URI[] EMPTY_URI_ARRAY = new URI[0];
private static final Map[] EMPTY_MAP_ARRAY = new Map[0];

private static boolean enableGrapes = Boolean.valueOf(System.getProperty("groovy.grape.enable", "true"));
private static boolean enableAutoDownload = Boolean.valueOf(System.getProperty("groovy.grape.autoDownload", "true"));
private static boolean disableChecksums = Boolean.valueOf(System.getProperty("groovy.grape.disableChecksums", "false"));
private static boolean enableGrapes = Boolean.parseBoolean(System.getProperty("groovy.grape.enable", "true"));
private static boolean enableAutoDownload = Boolean.parseBoolean(System.getProperty("groovy.grape.autoDownload", "true"));
private static boolean disableChecksums = Boolean.parseBoolean(System.getProperty("groovy.grape.disableChecksums", "false"));
protected static GrapeEngine instance;

/**
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/groovy/lang/GroovyClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ protected Class createClass(byte[] code, ClassNode classNode) {
SourceUnit msu = null;
if (mn != null) msu = mn.getContext();
ClassNode main = null;
if (mn != null) main = (ClassNode) mn.getClasses().get(0);
if (mn != null) main = mn.getClasses().get(0);
if (msu == su && main == classNode) generatedClass = theClass;
}

Expand Down Expand Up @@ -788,8 +788,7 @@ protected boolean isRecompilable(Class cls) {
if (recompile != null && !recompile) return false;
if (!GroovyObject.class.isAssignableFrom(cls)) return false;
long timestamp = getTimeStamp(cls);
if (timestamp == Long.MAX_VALUE) return false;
return true;
return timestamp != Long.MAX_VALUE;
}

/**
Expand Down Expand Up @@ -1176,7 +1175,7 @@ protected void addTimeStamp(ClassNode node) {
node.addField(timeTagField);

timeTagField = new FieldNode(
Verifier.__TIMESTAMP__ + String.valueOf(System.currentTimeMillis()),
Verifier.__TIMESTAMP__ + System.currentTimeMillis(),
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC,
ClassHelper.long_TYPE,
//"",
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/groovy/lang/MetaClassImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1027,11 +1027,11 @@ public Object invokeMethod(Object object, String methodName, Object[] originalAr
return invokeMethod(theClass, object, methodName, originalArguments, false, false);
}

private Object invokeMethodClosure(Object object, String methodName, Object[] arguments) {
private Object invokeMethodClosure(Object object, Object[] arguments) {
final MethodClosure mc = (MethodClosure) object;
final Object owner = mc.getOwner();

methodName = mc.getMethod();
String methodName = mc.getMethod();
final Class ownerClass = owner instanceof Class ? (Class) owner : owner.getClass();
final MetaClass ownerMetaClass = registry.getMetaClass(ownerClass);

Expand Down Expand Up @@ -1131,7 +1131,7 @@ public Object invokeMethod(Class sender, Object object, String methodName, Objec
if (CLOSURE_CALL_METHOD.equals(methodName) || CLOSURE_DO_CALL_METHOD.equals(methodName)) {
final Class objectClass = object.getClass();
if (objectClass == MethodClosure.class) {
return this.invokeMethodClosure(object, methodName, arguments);
return this.invokeMethodClosure(object, arguments);
} else if (objectClass == CurriedClosure.class) {
final CurriedClosure cc = (CurriedClosure) object;
// change the arguments for an uncurried call
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/groovy/lang/NumberRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -94,7 +95,7 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
* @param from the first value in the range
* @param to the last value in the range
*/
public <T extends Number & Comparable, U extends Number & Comparable>
public <T extends Number, U extends Number>
NumberRange(T from, U to) {
this(from, to, null, true);
}
Expand All @@ -107,7 +108,7 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
* @param to end of the range
* @param inclusive whether the range is inclusive
*/
public <T extends Number & Comparable, U extends Number & Comparable>
public <T extends Number, U extends Number>
NumberRange(T from, U to, boolean inclusive) {
this(from, to, null, inclusive);
}
Expand All @@ -120,7 +121,7 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
* @param to end of the range
* @param stepSize the gap between discrete elements in the range
*/
public <T extends Number & Comparable, U extends Number & Comparable, V extends
public <T extends Number, U extends Number, V extends
Number & Comparable<? super Number>>
NumberRange(T from, U to, V stepSize) {
this(from, to, stepSize, true);
Expand All @@ -135,8 +136,8 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
* @param stepSize the gap between discrete elements in the range
* @param inclusive whether the range is inclusive
*/
public <T extends Number & Comparable, U extends Number & Comparable, V extends
Number & Comparable>
public <T extends Number, U extends Number, V extends
Number>
NumberRange(T from, U to, V stepSize, boolean inclusive) {
if (from == null) {
throw new IllegalArgumentException("Must specify a non-null value for the 'from' index in a Range");
Expand Down Expand Up @@ -185,20 +186,20 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
* @param stepSize the desired step size
* @return a new NumberRange
*/
public <T extends Number & Comparable> NumberRange by(T stepSize) {
public <T extends Number> NumberRange by(T stepSize) {
if (!Integer.valueOf(1).equals(this.stepSize)) {
throw new IllegalStateException("by only allowed on ranges with original stepSize = 1 but found " + this.stepSize);
}
return new NumberRange(comparableNumber(from), comparableNumber(to), stepSize, inclusive);
}

@SuppressWarnings("unchecked")
/* package private */ static <T extends Number & Comparable> T comparableNumber(Comparable c) {
/* package private */ static <T extends Number> T comparableNumber(Comparable c) {
return (T) c;
}

@SuppressWarnings("unchecked")
/* package private */ static <T extends Number & Comparable> T comparableNumber(Number n) {
/* package private */ static <T extends Number> T comparableNumber(Number n) {
return (T) n;
}

Expand Down Expand Up @@ -402,7 +403,7 @@ void calcSize(Comparable from, Comparable to, Number stepSize) {
final BigInteger fromNum = new BigInteger(from.toString());
final BigInteger toTemp = new BigInteger(to.toString());
final BigInteger toNum = inclusive ? toTemp : toTemp.subtract(BigInteger.ONE);
final BigInteger sizeNum = new BigDecimal(toNum.subtract(fromNum)).divide(new BigDecimal(stepSize.longValue()), BigDecimal.ROUND_DOWN).toBigInteger().add(BigInteger.ONE);
final BigInteger sizeNum = new BigDecimal(toNum.subtract(fromNum)).divide(new BigDecimal(stepSize.longValue()), RoundingMode.DOWN).toBigInteger().add(BigInteger.ONE);
tempsize = sizeNum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) < 0 ? sizeNum.intValue() : Integer.MAX_VALUE;
shortcut = true;
} else if (((from instanceof BigDecimal || from instanceof BigInteger) && to instanceof Number) ||
Expand All @@ -411,7 +412,7 @@ void calcSize(Comparable from, Comparable to, Number stepSize) {
final BigDecimal fromNum = new BigDecimal(from.toString());
final BigDecimal toTemp = new BigDecimal(to.toString());
final BigDecimal toNum = inclusive ? toTemp : toTemp.subtract(new BigDecimal("1.0"));
final BigInteger sizeNum = toNum.subtract(fromNum).divide(new BigDecimal(stepSize.longValue()), BigDecimal.ROUND_DOWN).toBigInteger().add(BigInteger.ONE);
final BigInteger sizeNum = toNum.subtract(fromNum).divide(new BigDecimal(stepSize.longValue()), RoundingMode.DOWN).toBigInteger().add(BigInteger.ONE);
tempsize = sizeNum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) < 0 ? sizeNum.intValue() : Integer.MAX_VALUE;
shortcut = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/groovy/transform/stc/MapEntryOrKeyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static Options parse(MethodNode mn, ASTNode source, String[] options) throws Inc
if ("argNum".equals(key)) {
pIndex = Integer.parseInt(value);
} else if ("index".equals(key)) {
generateIndex = Boolean.valueOf(value);
generateIndex = Boolean.parseBoolean(value);
} else {
throw new IncorrectTypeHintException(mn, "Unrecognized option: "+key, source.getLineNumber(), source.getColumnNumber());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/groovy/util/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public void depthFirst(Closure c) {
* @since 2.5.0
*/
public void depthFirst(Map<String, Object> options, Closure c) {
boolean preorder = Boolean.valueOf(options.get("preorder").toString());
boolean preorder = Boolean.parseBoolean(options.get("preorder").toString());
if (preorder) callClosureForNode(c, this, 1);
depthFirstRest(preorder, 2, c);
if (!preorder) callClosureForNode(c, this, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static Expression cloneArrayOrCloneableExpr(Expression fieldExpr, ClassNo
args(
fieldExpr,
constX("clone"),
new ArrayExpression(ClassHelper.OBJECT_TYPE.makeArray(), Collections.<Expression>emptyList())
new ArrayExpression(ClassHelper.OBJECT_TYPE.makeArray(), Collections.emptyList())
)
);
return castX(type, smce);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@Incubating
public class UncheckedThrow {
public static void rethrow( final Throwable checkedException ) {
UncheckedThrow.<RuntimeException>thrownInsteadOf( checkedException );
UncheckedThrow.thrownInsteadOf( checkedException );
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void thrownInsteadOf(Throwable t) throws T {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/groovy/util/Maps.java
Original file line number Diff line number Diff line change
Expand Up @@ -5815,7 +5815,7 @@ public static <K, V> Map<V, K> inverse(Map<K, V> map, boolean force) {
resultMap.put(value, entry.getKey());
}

return Collections.<V, K>unmodifiableMap(resultMap);
return Collections.unmodifiableMap(resultMap);
}

private Maps() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ public Builder<K, V> listener(EvictionListener<K, V> listener) {
*/
public Builder<K, V> weigher(Weigher<? super V> weigher) {
this.weigher = (weigher == org.apache.groovy.util.concurrent.concurrentlinkedhashmap.Weighers.singleton())
? org.apache.groovy.util.concurrent.concurrentlinkedhashmap.Weighers.<K, V>entrySingleton()
? org.apache.groovy.util.concurrent.concurrentlinkedhashmap.Weighers.entrySingleton()
: new BoundedEntryWeigher<K, V>(org.apache.groovy.util.concurrent.concurrentlinkedhashmap.Weighers.asEntryWeigher(weigher));
return this;
}
Expand All @@ -1680,8 +1680,8 @@ public Builder<K, V> weigher(Weigher<? super V> weigher) {
*/
public Builder<K, V> weigher(EntryWeigher<? super K, ? super V> weigher) {
this.weigher = (weigher == org.apache.groovy.util.concurrent.concurrentlinkedhashmap.Weighers.entrySingleton())
? Weighers.<K, V>entrySingleton()
: new BoundedEntryWeigher<K, V>(weigher);
? Weighers.entrySingleton()
: new BoundedEntryWeigher<>(weigher);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private Weighers() {
public static <K, V> EntryWeigher<K, V> asEntryWeigher(
final org.apache.groovy.util.concurrent.concurrentlinkedhashmap.Weigher<? super V> weigher) {
return (weigher == singleton())
? Weighers.<K, V>entrySingleton()
? Weighers.entrySingleton()
: new EntryWeigherView<K, V>(weigher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2361,14 +2361,14 @@ protected Expression binaryExpression(int type, AST node) {
} else if (leftExpression instanceof BinaryExpression) {
int lefttype = ((BinaryExpression) leftExpression).getOperation().getType();
if (!Types.ofType(lefttype, Types.ASSIGNMENT_OPERATOR) && lefttype != Types.LEFT_SQUARE_BRACKET) {
throw new ASTRuntimeException(node, "\n" + ((BinaryExpression) leftExpression).getText() + " is a binary expression, but it should be a variable expression");
throw new ASTRuntimeException(node, "\n" + leftExpression.getText() + " is a binary expression, but it should be a variable expression");
}
} else if (leftExpression instanceof GStringExpression) {
throw new ASTRuntimeException(node, "\n\"" + ((GStringExpression) leftExpression).getText() + "\" is a GString expression, but it should be a variable expression");
throw new ASTRuntimeException(node, "\n\"" + leftExpression.getText() + "\" is a GString expression, but it should be a variable expression");
} else if (leftExpression instanceof MethodCallExpression) {
throw new ASTRuntimeException(node, "\n\"" + ((MethodCallExpression) leftExpression).getText() + "\" is a method call expression, but it should be a variable expression");
throw new ASTRuntimeException(node, "\n\"" + leftExpression.getText() + "\" is a method call expression, but it should be a variable expression");
} else if (leftExpression instanceof MapExpression) {
throw new ASTRuntimeException(node, "\n'" + ((MapExpression) leftExpression).getText() + "' is a map expression, but it should be a variable expression");
throw new ASTRuntimeException(node, "\n'" + leftExpression.getText() + "' is a map expression, but it should be a variable expression");
} else {
throw new ASTRuntimeException(node, "\n" + leftExpression.getClass() + ", with its value '" + leftExpression.getText() + "', is a bad expression as the left hand side of an assignment operator");
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/codehaus/groovy/antlr/GroovySourceAST.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,8 @@ public int compareTo(Object object) {
return 1;
}

if (this.getColumn() < that.getColumn()) {
return -1;
}
if (this.getColumn() > that.getColumn()) {
return 1;
}
return Integer.compare(this.getColumn(), that.getColumn());

return 0;
}

public GroovySourceAST childAt(int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ public void push(GroovySourceAST t) {
public GroovySourceAST pop() {
GroovySourceAST lastNodePopped = null;
for (Object backToFrontVisitor : backToFrontVisitors) {
lastNodePopped = (GroovySourceAST) ((Visitor) backToFrontVisitor).pop();
lastNodePopped = ((Visitor) backToFrontVisitor).pop();
}
return lastNodePopped;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void visit(GroovyCodeVisitor visitor) {
return;
}
for (BytecodeInstruction instruction : instructions) {
Object part = (Object) instruction;
Object part = instruction;
if (part instanceof ASTNode) {
((ASTNode) part).visit(visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void visitClass(ClassNode classNode) {
Opcodes.V1_3,
classNode.getModifiers(),
internalClassName,
(String) null,
null,
internalBaseClassName,
BytecodeHelper.getClassInternalNames(classNode.getInterfaces())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public void pop(final boolean propagateFlags) {
public String toString() {
StringBuilder ret = new StringBuilder();
if (current.shouldOptimize) {
ret.append("should optimize, can = " + current.canOptimize);
ret.append("should optimize, can = ").append(current.canOptimize);
} else if (current.canOptimize) {
ret.append("can optimize");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ protected void assertImportIsAllowed(final String className) {
return;
}
if (starImportsWhitelist != null) {
String packageName = className.substring(0, className.lastIndexOf('.') + 1) + "*";
String packageName = getWildCardImport(className);
if (starImportsWhitelist.contains(packageName)
|| starImportsWhitelist.stream().filter(it -> it.endsWith(".")).anyMatch(packageName::startsWith)) {
return;
Expand All @@ -680,7 +680,7 @@ protected void assertImportIsAllowed(final String className) {
throw new SecurityException("Importing [" + className + "] is not allowed");
}
if (starImportsBlacklist != null) {
String packageName = className.substring(0, className.lastIndexOf('.') + 1) + "*";
String packageName = getWildCardImport(className);
if (starImportsBlacklist.contains(packageName) ||
starImportsBlacklist.stream().filter(it -> it.endsWith(".")).anyMatch(packageName::startsWith)) {
throw new SecurityException("Importing [" + className + "] is not allowed");
Expand All @@ -689,12 +689,16 @@ protected void assertImportIsAllowed(final String className) {
}
}

private String getWildCardImport(String className) {
return className.substring(0, className.lastIndexOf('.') + 1) + "*";
}

protected void assertStaticImportIsAllowed(final String member, final String className) {
final String fqn = member.equals(className) ? member : className + "." + member;
if (staticImportsWhitelist != null && !staticImportsWhitelist.contains(fqn)) {
if (staticStarImportsWhitelist != null) {
// we should now check if the import is in the star imports
String packageName = className.substring(0, className.lastIndexOf('.') + 1) + "*";
String packageName = getWildCardImport(className);
if (!staticStarImportsWhitelist.contains(className + ".*")
&& !staticStarImportsWhitelist.stream().filter(it -> it.endsWith(".")).anyMatch(packageName::startsWith)) {
throw new SecurityException("Importing [" + fqn + "] is not allowed");
Expand All @@ -708,7 +712,7 @@ protected void assertStaticImportIsAllowed(final String member, final String cla
}
// check that there's no star import blacklist
if (staticStarImportsBlacklist != null) {
String packageName = className.substring(0, className.lastIndexOf('.') + 1) + "*";
String packageName = getWildCardImport(className);
if (staticStarImportsBlacklist.contains(className + ".*")
|| staticStarImportsBlacklist.stream().filter(it -> it.endsWith(".")).anyMatch(packageName::startsWith)) {
throw new SecurityException("Importing [" + fqn + "] is not allowed");
Expand Down
Loading