Skip to content

Commit

Permalink
Merge branch '6.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 7, 2023
2 parents 714d380 + dfbed61 commit aa2a067
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,26 +251,17 @@ private static String map(String type) {
}

public static Type getBoxedType(Type type) {
switch (type.getSort()) {
case Type.CHAR:
return Constants.TYPE_CHARACTER;
case Type.BOOLEAN:
return Constants.TYPE_BOOLEAN;
case Type.DOUBLE:
return Constants.TYPE_DOUBLE;
case Type.FLOAT:
return Constants.TYPE_FLOAT;
case Type.LONG:
return Constants.TYPE_LONG;
case Type.INT:
return Constants.TYPE_INTEGER;
case Type.SHORT:
return Constants.TYPE_SHORT;
case Type.BYTE:
return Constants.TYPE_BYTE;
default:
return type;
}
return switch (type.getSort()) {
case Type.CHAR -> Constants.TYPE_CHARACTER;
case Type.BOOLEAN -> Constants.TYPE_BOOLEAN;
case Type.DOUBLE -> Constants.TYPE_DOUBLE;
case Type.FLOAT -> Constants.TYPE_FLOAT;
case Type.LONG -> Constants.TYPE_LONG;
case Type.INT -> Constants.TYPE_INTEGER;
case Type.SHORT -> Constants.TYPE_SHORT;
case Type.BYTE -> Constants.TYPE_BYTE;
default -> type;
};
}

public static Type getUnboxedType(Type type) {
Expand Down Expand Up @@ -307,13 +298,10 @@ public static Type getComponentType(Type type) {
}

public static boolean isPrimitive(Type type) {
switch (type.getSort()) {
case Type.ARRAY:
case Type.OBJECT:
return false;
default:
return true;
}
return switch (type.getSort()) {
case Type.ARRAY, Type.OBJECT -> false;
default -> true;
};
}

public static String emulateClassGetName(Type type) {
Expand All @@ -340,17 +328,17 @@ public static Type[] getTypes(Class[] classes) {
}

public static int ICONST(int value) {
switch (value) {
case -1: return Constants.ICONST_M1;
case 0: return Constants.ICONST_0;
case 1: return Constants.ICONST_1;
case 2: return Constants.ICONST_2;
case 3: return Constants.ICONST_3;
case 4: return Constants.ICONST_4;
case 5: return Constants.ICONST_5;
}
return -1; // error
}
return switch (value) {
case -1 -> Constants.ICONST_M1;
case 0 -> Constants.ICONST_0;
case 1 -> Constants.ICONST_1;
case 2 -> Constants.ICONST_2;
case 3 -> Constants.ICONST_3;
case 4 -> Constants.ICONST_4;
case 5 -> Constants.ICONST_5;
default -> -1; // error
};
}

public static int LCONST(long value) {
if (value == 0L) {
Expand Down Expand Up @@ -385,43 +373,33 @@ public static int DCONST(double value) {
}

public static int NEWARRAY(Type type) {
switch (type.getSort()) {
case Type.BYTE:
return Constants.T_BYTE;
case Type.CHAR:
return Constants.T_CHAR;
case Type.DOUBLE:
return Constants.T_DOUBLE;
case Type.FLOAT:
return Constants.T_FLOAT;
case Type.INT:
return Constants.T_INT;
case Type.LONG:
return Constants.T_LONG;
case Type.SHORT:
return Constants.T_SHORT;
case Type.BOOLEAN:
return Constants.T_BOOLEAN;
default:
return -1; // error
}
return switch (type.getSort()) {
case Type.BYTE -> Constants.T_BYTE;
case Type.CHAR -> Constants.T_CHAR;
case Type.DOUBLE -> Constants.T_DOUBLE;
case Type.FLOAT -> Constants.T_FLOAT;
case Type.INT -> Constants.T_INT;
case Type.LONG -> Constants.T_LONG;
case Type.SHORT -> Constants.T_SHORT;
case Type.BOOLEAN -> Constants.T_BOOLEAN;
default -> -1; // error
};
}

public static String escapeType(String s) {
StringBuilder sb = new StringBuilder();
for (int i = 0, len = s.length(); i < len; i++) {
char c = s.charAt(i);
switch (c) {
case '$': sb.append("$24"); break;
case '.': sb.append("$2E"); break;
case '[': sb.append("$5B"); break;
case ';': sb.append("$3B"); break;
case '(': sb.append("$28"); break;
case ')': sb.append("$29"); break;
case '/': sb.append("$2F"); break;
default:
sb.append(c);
}
switch (c) {
case '$' -> sb.append("$24");
case '.' -> sb.append("$2E");
case '[' -> sb.append("$5B");
case ';' -> sb.append("$3B");
case '(' -> sb.append("$28");
case ')' -> sb.append("$29");
case '/' -> sb.append("$2F");
default -> sb.append(c);
}
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,47 +104,33 @@ protected void parseInternal() throws SAXException, XMLStreamException {
documentStarted = true;
}
switch (event.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
case XMLStreamConstants.START_DOCUMENT -> {
handleStartDocument(event);
documentStarted = true;
break;
case XMLStreamConstants.START_ELEMENT:
}
case XMLStreamConstants.START_ELEMENT -> {
elementDepth++;
handleStartElement(event.asStartElement());
break;
case XMLStreamConstants.END_ELEMENT:
}
case XMLStreamConstants.END_ELEMENT -> {
elementDepth--;
if (elementDepth >= 0) {
handleEndElement(event.asEndElement());
}
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
handleProcessingInstruction((ProcessingInstruction) event);
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CDATA:
handleCharacters(event.asCharacters());
break;
case XMLStreamConstants.END_DOCUMENT:
}
case XMLStreamConstants.PROCESSING_INSTRUCTION ->
handleProcessingInstruction((ProcessingInstruction) event);
case XMLStreamConstants.CHARACTERS, XMLStreamConstants.SPACE, XMLStreamConstants.CDATA ->
handleCharacters(event.asCharacters());
case XMLStreamConstants.END_DOCUMENT -> {
handleEndDocument();
documentEnded = true;
break;
case XMLStreamConstants.NOTATION_DECLARATION:
handleNotationDeclaration((NotationDeclaration) event);
break;
case XMLStreamConstants.ENTITY_DECLARATION:
handleEntityDeclaration((EntityDeclaration) event);
break;
case XMLStreamConstants.COMMENT:
handleComment((Comment) event);
break;
case XMLStreamConstants.DTD:
handleDtd((DTD) event);
break;
case XMLStreamConstants.ENTITY_REFERENCE:
handleEntityReference((EntityReference) event);
break;
}
case XMLStreamConstants.NOTATION_DECLARATION -> handleNotationDeclaration((NotationDeclaration) event);
case XMLStreamConstants.ENTITY_DECLARATION -> handleEntityDeclaration((EntityDeclaration) event);
case XMLStreamConstants.COMMENT -> handleComment((Comment) event);
case XMLStreamConstants.DTD -> handleDtd((DTD) event);
case XMLStreamConstants.ENTITY_REFERENCE -> handleEntityReference((EntityReference) event);
}
}
if (documentStarted && !documentEnded) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -84,41 +84,29 @@ protected void parseInternal() throws SAXException, XMLStreamException {
documentStarted = true;
}
switch (eventType) {
case XMLStreamConstants.START_ELEMENT:
case XMLStreamConstants.START_ELEMENT -> {
elementDepth++;
handleStartElement();
break;
case XMLStreamConstants.END_ELEMENT:
}
case XMLStreamConstants.END_ELEMENT -> {
elementDepth--;
if (elementDepth >= 0) {
handleEndElement();
}
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
handleProcessingInstruction();
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CDATA:
handleCharacters();
break;
case XMLStreamConstants.START_DOCUMENT:
}
case XMLStreamConstants.PROCESSING_INSTRUCTION -> handleProcessingInstruction();
case XMLStreamConstants.CHARACTERS, XMLStreamConstants.SPACE, XMLStreamConstants.CDATA -> handleCharacters();
case XMLStreamConstants.START_DOCUMENT -> {
handleStartDocument();
documentStarted = true;
break;
case XMLStreamConstants.END_DOCUMENT:
}
case XMLStreamConstants.END_DOCUMENT -> {
handleEndDocument();
documentEnded = true;
break;
case XMLStreamConstants.COMMENT:
handleComment();
break;
case XMLStreamConstants.DTD:
handleDtd();
break;
case XMLStreamConstants.ENTITY_REFERENCE:
handleEntityReference();
break;
}
case XMLStreamConstants.COMMENT -> handleComment();
case XMLStreamConstants.DTD -> handleDtd();
case XMLStreamConstants.ENTITY_REFERENCE -> handleEntityReference();
}
if (this.reader.hasNext() && elementDepth >= 0) {
eventType = this.reader.next();
Expand Down

0 comments on commit aa2a067

Please sign in to comment.