Skip to content

Commit

Permalink
Make changes suggested by the IDEA [new version] code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Gleyzer committed Nov 9, 2023
1 parent 933840f commit bc12c22
Show file tree
Hide file tree
Showing 35 changed files with 45 additions and 99 deletions.
8 changes: 0 additions & 8 deletions javatools/src/main/java/org/xvm/asm/Annotation.java
Expand Up @@ -4,7 +4,6 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintWriter;

import java.util.Arrays;
import java.util.Set;
Expand Down Expand Up @@ -392,13 +391,6 @@ public String getDescription()
return sb.toString();
}

@Override
protected void dump(PrintWriter out, String sIndent)
{
out.print(sIndent);
out.println(this);
}


// ----- Object methods ------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion javatools/src/main/java/org/xvm/asm/ClassStructure.java
Expand Up @@ -1275,7 +1275,7 @@ public boolean isIntoClassMixin(TypeConstant typeMixin)
}

/**
* @return true iff any contribution for this class has a cyclical dependency
* @return a contribution for this class that has a cyclical dependency; null otherwise
*/
public Contribution hasCyclicalContribution()
{
Expand Down
6 changes: 0 additions & 6 deletions javatools/src/main/java/org/xvm/asm/ErrorList.java
Expand Up @@ -79,12 +79,6 @@ public boolean hasError(String sCode)
return f_list.stream().anyMatch(info -> info.getCode().equals(sCode));
}

@Override
public boolean isSilent()
{
return false;
}


// ----- accessors -----------------------------------------------------------------------------

Expand Down
6 changes: 0 additions & 6 deletions javatools/src/main/java/org/xvm/asm/ErrorListener.java
Expand Up @@ -194,12 +194,6 @@ public boolean log(ErrorInfo err)
}
}

@Override
public boolean isSilent()
{
return false;
}

@Override
public String toString()
{
Expand Down
2 changes: 1 addition & 1 deletion javatools/src/main/java/org/xvm/asm/ModuleRepository.java
Expand Up @@ -154,7 +154,7 @@ default ModuleStructure loadModule(String sModule, Version version, boolean fExa
*
* @throws IOException various IO exceptions could be thrown to
* indicate that the repository is read-only, that the specified
* module is not able to be stored in the repository, etc.
* module won't be stored in the repository, etc.
*/
void storeModule(ModuleStructure module)
throws IOException;
Expand Down
2 changes: 1 addition & 1 deletion javatools/src/main/java/org/xvm/asm/ModuleStructure.java
Expand Up @@ -645,7 +645,7 @@ public boolean equals(Object obj)
* module is obtained and linked in by the linker.</li>
* </ul>
*/
enum ModuleType
public enum ModuleType
{
Primary, Optional, Desired, Required, Embedded;

Expand Down
4 changes: 2 additions & 2 deletions javatools/src/main/java/org/xvm/asm/OpCondJump.java
Expand Up @@ -181,15 +181,15 @@ protected TypeConstant calculateCommonType(Frame frame)
}

/**
* A completion of a unary op; must me overridden by all binary ops.
* A completion of a unary op; must be overridden by all binary ops.
*/
protected int completeUnaryOp(Frame frame, int iPC, ObjectHandle hValue)
{
throw new UnsupportedOperationException();
}

/**
* A completion of a binary op; must me overridden by all binary ops.
* A completion of a binary op; must be overridden by all binary ops.
*/
protected int completeBinaryOp(Frame frame, int iPC, TypeConstant type,
ObjectHandle hValue1, ObjectHandle hValue2)
Expand Down
1 change: 0 additions & 1 deletion javatools/src/main/java/org/xvm/asm/ast/ForStmtAST.java
Expand Up @@ -8,7 +8,6 @@
import org.xvm.util.Handy;

import static org.xvm.asm.ast.BinaryAST.NodeType.ForStmt;
import static org.xvm.util.Handy.indentLines;


/**
Expand Down
7 changes: 1 addition & 6 deletions javatools/src/main/java/org/xvm/asm/ast/OuterExprAST.java
Expand Up @@ -55,11 +55,6 @@ protected void writeBody(DataOutput out, ConstantResolver res)

@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getExpr());
for (int i = 0; i < depth; ++i) {
buf.append(".outer");
}
return buf.toString();
return getExpr() + ".outer".repeat(Math.max(0, depth));
}
}
1 change: 0 additions & 1 deletion javatools/src/main/java/org/xvm/asm/ast/RegisterAST.java
Expand Up @@ -6,7 +6,6 @@
import java.io.IOException;

import org.xvm.asm.Op;
import org.xvm.asm.Constant;
import org.xvm.asm.OpProperty;

import org.xvm.asm.constants.StringConstant;
Expand Down
2 changes: 0 additions & 2 deletions javatools/src/main/java/org/xvm/asm/ast/StmtExprAST.java
Expand Up @@ -8,8 +8,6 @@
import java.util.Arrays;
import java.util.Objects;

import org.xvm.asm.Constant;

import org.xvm.asm.constants.TypeConstant;

import static org.xvm.asm.ast.BinaryAST.NodeType.StmtExpr;
Expand Down
6 changes: 3 additions & 3 deletions javatools/src/main/java/org/xvm/asm/ast/SwitchAST.java
Expand Up @@ -283,7 +283,7 @@ protected void writeBody(DataOutput out, ConstantResolver res)
int count = cases.length;
writePackedLong(out, count);
for (int i = 0; i < count; ++i) {
Constant value = (Constant) cases[i];
Constant value = cases[i];
writePackedLong(out, value == null ? -1 : res.indexOf(value));
}

Expand Down Expand Up @@ -331,8 +331,8 @@ protected void writeBody(DataOutput out, ConstantResolver res)
@Override
public String toString() {
StringBuilder buf = new StringBuilder("switch (");
if (cond instanceof MultiExprAST meast) {
ExprAST[] exprs = meast.getExprs();
if (cond instanceof MultiExprAST meAst) {
ExprAST[] exprs = meAst.getExprs();
for (ExprAST expr : exprs) {
buf.append(expr);
buf.append(", ");
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class TemplateExprAST
TemplateExprAST() {}

public TemplateExprAST(ExprAST[] exprs) {
assert exprs != null && Arrays.stream(exprs).allMatch(Objects::nonNull);;
assert exprs != null && Arrays.stream(exprs).allMatch(Objects::nonNull);

this.exprs = exprs;
}
Expand Down
10 changes: 4 additions & 6 deletions javatools/src/main/java/org/xvm/asm/ast/TryCatchStmtAST.java
Expand Up @@ -95,12 +95,10 @@ public String toString() {
.append(indentLines(body.toString(), " "))
.append("\n}");

if (catches.length > 0) {
for (BinaryAST catch_ : catches) {
buf.append(" catch (???) {\n")
.append(indentLines(catch_.toString(), " "))
.append("\n}");
}
for (BinaryAST catch_ : catches) {
buf.append(" catch (???) {\n")
.append(indentLines(catch_.toString(), " "))
.append("\n}");
}
return buf.toString();
}
Expand Down
Expand Up @@ -5,6 +5,7 @@
import java.io.DataOutput;
import java.io.IOException;

import java.util.Arrays;
import org.xvm.asm.Constant;
import org.xvm.asm.ConstantPool;

Expand Down Expand Up @@ -126,10 +127,7 @@ public Constant apply(Token.Id op, Constant that)
assert n >= 0 && n < 1000000;

char[] ach = new char[n];
for (int i = 0; i < n; ++i)
{
ach[i] = ch;
}
Arrays.fill(ach, ch);

return getConstantPool().ensureStringConstant(new String(ach));
}
Expand Down
9 changes: 1 addition & 8 deletions javatools/src/main/java/org/xvm/compiler/EvalCompiler.java
Expand Up @@ -376,7 +376,7 @@ public Map<String, Argument> getCaptures()
}

/**
* @return the list of indexes for lambda arguments
* @return the array of indexes for lambda arguments
*/
public int[] getArguments()
{
Expand All @@ -396,13 +396,6 @@ public Source getSource()
return f_source;
}

@Override
public boolean isComponentNode()
{
return true;
}


@Override
public ComponentResolver getComponentResolver()
{
Expand Down
4 changes: 2 additions & 2 deletions javatools/src/main/java/org/xvm/compiler/Parser.java
Expand Up @@ -4456,7 +4456,7 @@ else if (type instanceof ArrayTypeExpression)
exprs.add(expr);
if (match(Id.COMMA) == null)
{
if ("".equals(sType) && exprs.size() == 1)
if (sType.isEmpty() && exprs.size() == 1)
{
// special handling for a map
if (peek().getId() == Id.ASN)
Expand Down Expand Up @@ -6147,7 +6147,7 @@ protected Token expect(Token.Id id)
/**
* Require a token that is either an identifier or the "_" token.
*
* @return a token that is either an identifier or the "_" token)
* @return a token that is either an identifier or the "_" token
*/
protected Token expectNameOrAny()
{
Expand Down
8 changes: 3 additions & 5 deletions javatools/src/main/java/org/xvm/compiler/Source.java
Expand Up @@ -19,7 +19,6 @@
import static org.xvm.util.Handy.isHexit;
import static org.xvm.util.Handy.readFileBytes;
import static org.xvm.util.Handy.readFileChars;
import static org.xvm.util.Handy.toPathString;


/**
Expand Down Expand Up @@ -288,10 +287,9 @@ && isHexit(ach[of+8]))
| hexitValue(ach[of+7]) << 4
| hexitValue(ach[of+8]);

// unfortunately Java does not support characters with code-
// points beyond 16 bits; we could theoretically split this
// up into a Unicode "surrogate pair", but that is not
// supported by this class at this time
// unfortunately Java does not support characters with codepoints beyond 16
// bits; we could theoretically split this up into a Unicode "surrogate pair",
// but that is not supported by this class at this time
ch = nch > Character.MAX_VALUE ? '?' : (char) nch;
of += 9;
cchAdjust += 9;
Expand Down
2 changes: 1 addition & 1 deletion javatools/src/main/java/org/xvm/compiler/Token.java
Expand Up @@ -753,7 +753,7 @@ public static Id valueByPrefix(String sText)
private static final Id[] IDs = Id.values();

/**
* String representations of tokens that have constant representations, excluding context-
* String representations of tokens that have constant representations, excluding context
* sensitive keywords.
*/
private static final Map<String, Id> KEYWORDS = new HashMap<>();
Expand Down
Expand Up @@ -238,7 +238,7 @@ public boolean isConditional()
}

/**
* @return true iff the assignment statement uses the "=" operator
* @return the Category of the statement
*/
public Category getCategory()
{
Expand Down
Expand Up @@ -1283,7 +1283,7 @@ private boolean areAllCasesCovered()

if (constCase instanceof RangeConstant constRange)
{
cCovered += constRange.size();
cCovered += (int) constRange.size();

// compensate for all previous intersections with this range
for (Constant constPrev : m_listsetCase)
Expand Down
Expand Up @@ -267,8 +267,7 @@ public Annotation ensureAnnotation(ConstantPool pool)
}

/**
* @return true iff the incorporates clause is conditional based on the generic parameters
* of the specified type
* @return list of constraints for conditional incorporates; null otherwise
*/
public List<Parameter> getConstraints()
{
Expand Down
2 changes: 1 addition & 1 deletion javatools/src/main/java/org/xvm/compiler/ast/Context.java
Expand Up @@ -884,7 +884,7 @@ protected Argument getVar(String sName, Token name, Branch branch, ErrorListener
}

// we need to call resolveRegisterType() even on registers that are local
// since some formal types could have been narrowed afterwards
// since some formal types could have been narrowed afterward
if (arg instanceof Register reg)
{
arg = resolveRegisterType(branch, reg);
Expand Down
Expand Up @@ -472,7 +472,7 @@ protected Expression validateMulti(Context ctx, TypeConstant[] atypeRequired, Er

// the parent requires more than one type (conditionally), but this expression can only
// return one; this can only be a "False" part of the conditional return; we'll check
// afterwards unless it's already caught by the validation logic
// afterward unless it's already caught by the validation logic
}

if (hasSingleValueImpl())
Expand Down
Expand Up @@ -3588,14 +3588,14 @@ public String getDumpDesc()
/**
* Represents the category of argument that the expression yields.
*/
enum Meaning {Unknown, Reserved, Variable, Property, FormalChildType, Method, Class, Type, Label}
protected enum Meaning {Unknown, Reserved, Variable, Property, FormalChildType, Method, Class, Type, Label}

/**
* Represents the necessary argument/assignable transformation that the expression will have to
* produce as part of compilation, if it is asked to produce an argument, an assignable, or an
* assignment.
*/
enum Plan {None, OuterThis, OuterRef, RegisterRef, PropertyDeref, PropertyRef, PropertySelf,
protected enum Plan {None, OuterThis, OuterRef, RegisterRef, PropertyDeref, PropertyRef, PropertySelf,
TypeOfClass, TypeOfTypedef, Singleton, TypeOfFormalChild, BindTarget, BjarneLambda}

/**
Expand Down Expand Up @@ -3633,7 +3633,7 @@ enum Plan {None, OuterThis, OuterRef, RegisterRef, PropertyDeref, PropertyRef, P
* 4) the property is on "left"
* (left must be not null)
*/
enum PropertyAccess {SingletonParent, Outer, This, Left}
protected enum PropertyAccess {SingletonParent, Outer, This, Left}

/**
* The chosen property access plan.
Expand Down
Expand Up @@ -3,8 +3,6 @@

import java.lang.reflect.Field;

import org.xvm.asm.ast.ExprAST;


/**
* Used for parenthesized expressions.
Expand Down Expand Up @@ -55,12 +53,6 @@ public boolean isStandalone()
return expr.isStandalone();
}

@Override
public ExprAST getExprAST()
{
return expr.getExprAST();
}


// ----- debugging assistance ------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions javatools/src/main/java/org/xvm/compiler/ast/Statement.java
Expand Up @@ -201,7 +201,7 @@ protected Context ensureValidationContext()
* @param ctx the compilation context for the statement
* @param errs the error listener to log to
*
* @return true iff the compilation can proceed
* @return the resulting statement (typically this) or null if the compilation cannot proceed
*/
protected abstract Statement validateImpl(Context ctx, ErrorListener errs);

Expand Down Expand Up @@ -271,7 +271,7 @@ private static class Break
* Holder for BinaryAST objects as they percolate up the emit() call tree.
* TODO get rid of this concept and add a getAST as per Expression tree
*/
static class AstHolder
public static class AstHolder
{
BinaryAST getAst(Statement stmt)
{
Expand Down
Expand Up @@ -6,7 +6,6 @@
import org.xvm.asm.ErrorListener;

import org.xvm.asm.ast.ConstantExprAST;
import org.xvm.asm.ast.ConvertExprAST;
import org.xvm.asm.ast.ExprAST;
import org.xvm.asm.ast.UnaryOpExprAST;
import org.xvm.asm.ast.UnaryOpExprAST.Operator;
Expand Down
Expand Up @@ -2922,7 +2922,7 @@ private MethodConstant findSuperConstructor(Context ctx, TypeConstant typeSuper,
/**
* Validate "extend" parameters and mark the constructor with constant arguments.
*
* @return the MethodConstant for the super constructor; null if the validation failed
* @return false iff the validation failed and an error has been logged
*/
private boolean validateSuperParameters(Context ctx, MethodStructure constructor,
MethodConstant idSuper, MethodStructure constructSuper,
Expand Down

0 comments on commit bc12c22

Please sign in to comment.