repo stringclasses 1k values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 6 values | commit_sha stringclasses 1k values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/StaticInvokeMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/StaticInvokeMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.stmt.invoke.StaticMethodInvoke;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import java.util.HashMap;
import java.util.Map;
/**
* A matcher for static method invoke instructions.
*/
public class StaticInvokeMatcher implements InstructionMatcher<StaticMethodInvoke> {
private String owner;
private String name;
private String desc;
private Map<Integer, InstructionMatcher<?>> parameters;
StaticInvokeMatcher(String owner, String name, String desc, Map<Integer, InstructionMatcher<?>> parameters) {
this.owner = owner;
this.name = name;
this.desc = desc;
this.parameters = parameters;
}
@Override
public StaticMethodInvoke match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof StaticMethodInvoke)) {
return null;
}
StaticMethodInvoke invoke = (StaticMethodInvoke) insn;
if (this.owner != null && !this.owner.equals(invoke.getOwner())) {
return null;
}
if (this.name != null && !this.name.equals(invoke.getMethodName())) {
return null;
}
if (this.desc != null && !this.desc.equals(invoke.getMethodDescription())) {
return null;
}
Instruction[] params = invoke.getParameters();
for (Map.Entry<Integer, InstructionMatcher<?>> e : this.parameters.entrySet()) {
if (e.getKey() >= params.length) {
return null;
}
if (!e.getValue().matches(ctx, params[e.getKey()])) {
return null;
}
}
return invoke;
}
/**
* A matcher builder.
*/
public static class Builder {
private String owner;
private String name;
private String desc;
private Map<Integer, InstructionMatcher<?>> parameters = new HashMap<>();
public Builder() {
reset();
}
public Builder owner(String owner) {
this.owner = owner;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder desc(String desc) {
this.desc = desc;
return this;
}
public Builder param(int index, InstructionMatcher<?> matcher) {
this.parameters.put(index, matcher);
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.owner = null;
this.name = null;
this.desc = null;
this.parameters.clear();
return this;
}
public StaticInvokeMatcher build() {
return new StaticInvokeMatcher(this.owner, this.name, this.desc, this.parameters);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/IntConstantMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/IntConstantMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.cst.IntConstant;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for integer constants.
*/
public class IntConstantMatcher implements InstructionMatcher<IntConstant> {
private Integer value;
IntConstantMatcher(Integer value) {
this.value = value;
}
@Override
public IntConstant match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof IntConstant)) {
return null;
}
IntConstant invoke = (IntConstant) insn;
if (this.value != null && invoke.getConstant() != this.value.intValue()) {
return null;
}
return invoke;
}
/**
* A matcher builder.
*/
public static class Builder {
private Integer value;
public Builder() {
reset();
}
public Builder value(int val) {
this.value = val;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.value = null;
return this;
}
public IntConstantMatcher build() {
return new IntConstantMatcher(this.value);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/InstanceFieldAccessMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/InstanceFieldAccessMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.var.InstanceFieldAccess;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for instance field accesses.
*/
public class InstanceFieldAccessMatcher implements InstructionMatcher<InstanceFieldAccess> {
private InstructionMatcher<?> owner;
private String name;
private String desc;
InstanceFieldAccessMatcher(InstructionMatcher<?> callee, String name, String desc) {
this.owner = callee == null ? InstructionMatcher.ANY : callee;
this.name = name;
this.desc = desc;
}
@Override
public InstanceFieldAccess match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof InstanceFieldAccess)) {
return null;
}
InstanceFieldAccess invoke = (InstanceFieldAccess) insn;
if (this.name != null && !this.name.equals(invoke.getFieldName())) {
return null;
}
if (this.desc != null && !this.desc.equals(invoke.getTypeDescriptor())) {
return null;
}
if (!this.owner.matches(ctx, invoke.getFieldOwner())) {
return null;
}
return invoke;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> callee;
private String name;
private String desc;
public Builder() {
reset();
}
public Builder owner(InstructionMatcher<?> callee) {
this.callee = callee;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder desc(String desc) {
this.desc = desc;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.callee = null;
this.name = null;
this.desc = null;
return this;
}
public InstanceFieldAccessMatcher build() {
return new InstanceFieldAccessMatcher(this.callee, this.name, this.desc);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/StaticFieldAccessMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/StaticFieldAccessMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.var.StaticFieldAccess;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for instance field accesses.
*/
public class StaticFieldAccessMatcher implements InstructionMatcher<StaticFieldAccess> {
private ClassTypeSignature owner;
private String name;
private String desc;
StaticFieldAccessMatcher(ClassTypeSignature callee, String name, String desc) {
this.owner = callee;
this.name = name;
this.desc = desc;
}
@Override
public StaticFieldAccess match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof StaticFieldAccess)) {
return null;
}
StaticFieldAccess invoke = (StaticFieldAccess) insn;
if (this.name != null && !this.name.equals(invoke.getFieldName())) {
return null;
}
if (this.desc != null && !this.desc.equals(invoke.getTypeDescriptor())) {
return null;
}
if (this.owner != null && !this.owner.getDescriptor().equals(invoke.getOwnerType())) {
return null;
}
return invoke;
}
/**
* A matcher builder.
*/
public static class Builder {
private ClassTypeSignature owner;
private String name;
private String desc;
public Builder() {
reset();
}
public Builder owner(ClassTypeSignature owner) {
this.owner = owner;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder desc(String desc) {
this.desc = desc;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.owner = null;
this.name = null;
this.desc = null;
return this;
}
public StaticFieldAccessMatcher build() {
return new StaticFieldAccessMatcher(this.owner, this.name, this.desc);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/InstanceMethodInvokeMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/InstanceMethodInvokeMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.stmt.invoke.InstanceMethodInvoke;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import java.util.HashMap;
import java.util.Map;
/**
* A matcher for instance method invokes.
*/
public class InstanceMethodInvokeMatcher implements InstructionMatcher<InstanceMethodInvoke> {
private InstructionMatcher<?> callee;
private boolean unwrap;
private String owner;
private String name;
private String desc;
private Map<Integer, InstructionMatcher<?>> parameters;
InstanceMethodInvokeMatcher(InstructionMatcher<?> callee, String owner, String name, String desc, boolean unwrap,
Map<Integer, InstructionMatcher<?>> parameters) {
this.callee = callee == null ? InstructionMatcher.ANY : callee;
this.owner = owner;
this.name = name;
this.desc = desc;
this.unwrap = unwrap;
this.parameters = parameters;
}
@Override
public InstanceMethodInvoke match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof InstanceMethodInvoke)) {
return null;
}
InstanceMethodInvoke invoke = (InstanceMethodInvoke) insn;
if (this.owner != null && !this.owner.equals(invoke.getOwner())) {
return null;
}
if (this.name != null && !this.name.equals(invoke.getMethodName())) {
return null;
}
if (this.desc != null && !this.desc.equals(invoke.getMethodDescription())) {
return null;
}
Instruction callee = invoke.getCallee();
if (this.unwrap) {
callee = InstructionMatcher.unwrapCast(callee);
}
if (!this.callee.matches(ctx, callee)) {
return null;
}
Instruction[] params = invoke.getParameters();
for (Map.Entry<Integer, InstructionMatcher<?>> e : this.parameters.entrySet()) {
if (e.getKey() >= params.length) {
return null;
}
if (!e.getValue().matches(ctx, params[e.getKey()])) {
return null;
}
}
return invoke;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> callee;
private String owner;
private String name;
private String desc;
private boolean unwrap;
private Map<Integer, InstructionMatcher<?>> parameters = new HashMap<>();
public Builder() {
reset();
}
public Builder callee(InstructionMatcher<?> callee) {
this.callee = callee;
return this;
}
public Builder owner(String owner) {
this.owner = owner;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder desc(String desc) {
this.desc = desc;
return this;
}
public Builder autoUnwrap() {
this.unwrap = true;
return this;
}
public Builder param(int index, InstructionMatcher<?> matcher) {
this.parameters.put(index, matcher);
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.callee = null;
this.owner = null;
this.name = null;
this.desc = null;
this.unwrap = false;
this.parameters.clear();
return this;
}
public InstanceMethodInvokeMatcher build() {
return new InstanceMethodInvokeMatcher(this.callee, this.owner, this.name, this.desc, this.unwrap, this.parameters);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/LocalAccessMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/LocalAccessMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.var.LocalAccess;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for local accesses.
*/
public class LocalAccessMatcher implements InstructionMatcher<LocalAccess> {
private boolean allow_missing = false;
private LocalInstance local;
private String ctx_local;
LocalAccessMatcher(LocalInstance local) {
this.local = local;
}
LocalAccessMatcher(String local, boolean allow_missing) {
this.ctx_local = local;
this.allow_missing = allow_missing;
}
@Override
public LocalAccess match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof LocalAccess)) {
return null;
}
LocalAccess acc = (LocalAccess) insn;
if (this.local != null) {
if (!this.local.equals(acc.getLocal())) {
return null;
}
} else if (this.ctx_local != null) {
LocalInstance l = ctx.getLocal(this.ctx_local);
if (l == null) {
if (!this.allow_missing) {
return null;
}
ctx.setLocal(this.ctx_local, acc.getLocal());
} else if (!l.equals(acc.getLocal())) {
return null;
}
}
return acc;
}
/**
* A matcher builder.
*/
public static class Builder {
private boolean allow_missing;
private LocalInstance local;
private String ctx_local;
public Builder() {
reset();
}
public Builder local(LocalInstance local) {
this.local = local;
return this;
}
public Builder fromContext(String identifier) {
this.ctx_local = identifier;
return this;
}
public Builder allowMissing() {
this.allow_missing = true;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.local = null;
this.ctx_local = null;
this.allow_missing = false;
return this;
}
/**
* Creates a new matcher.
*/
public LocalAccessMatcher build() {
if (this.ctx_local != null) {
return new LocalAccessMatcher(this.ctx_local, this.allow_missing);
}
return new LocalAccessMatcher(this.local);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/ArrayAccessMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/ArrayAccessMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.var.ArrayAccess;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for {@link ArrayAccess} instructions.
*/
public class ArrayAccessMatcher implements InstructionMatcher<ArrayAccess> {
private InstructionMatcher<?> array;
private InstructionMatcher<?> index;
ArrayAccessMatcher(InstructionMatcher<?> array, InstructionMatcher<?> index) {
this.array = array == null ? InstructionMatcher.ANY : array;
this.index = index == null ? InstructionMatcher.ANY : index;
}
@Override
public ArrayAccess match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof ArrayAccess)) {
return null;
}
ArrayAccess invoke = (ArrayAccess) insn;
if (!this.array.matches(ctx, invoke.getArrayVar())) {
return null;
}
if (!this.index.matches(ctx, invoke.getIndex())) {
return null;
}
return invoke;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> array;
private InstructionMatcher<?> index;
public Builder() {
reset();
}
/**
* Sets the matcher for the array value.
*/
public Builder array(InstructionMatcher<?> val) {
this.array = val;
return this;
}
/**
* Sets the matcher for the array index.
*/
public Builder index(InstructionMatcher<?> index) {
this.index = index;
return this;
}
/**
* Resets the builder.
*/
public Builder reset() {
this.array = null;
this.index = null;
return this;
}
/**
* Creates a new matcher.
*/
public ArrayAccessMatcher build() {
return new ArrayAccessMatcher(this.array, this.index);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/instruction/NullConstantMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/instruction/NullConstantMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.instruction;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.cst.NullConstant;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for integer constants.
*/
public class NullConstantMatcher implements InstructionMatcher<NullConstant> {
NullConstantMatcher() {
}
@Override
public NullConstant match(MatchContext ctx, Instruction insn) {
if (!(insn instanceof NullConstant)) {
return null;
}
return (NullConstant) insn;
}
/**
* A matcher builder.
*/
public static class Builder {
public Builder() {
}
/**
* Resets this builder.
*/
public Builder reset() {
return this;
}
public NullConstantMatcher build() {
return new NullConstantMatcher();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/StaticFieldAssignmentMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/StaticFieldAssignmentMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.misc.Cast;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.assign.StaticFieldAssignment;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
/**
* A matcher for local assignments.
*/
public class StaticFieldAssignmentMatcher implements StatementMatcher<StaticFieldAssignment> {
private InstructionMatcher<?> value;
private boolean unwrap;
private String owner;
private String name;
private TypeSignature type;
StaticFieldAssignmentMatcher(InstructionMatcher<?> value, String owner, String name, TypeSignature type, boolean unwrap) {
this.value = value == null ? InstructionMatcher.ANY : value;
this.owner = owner;
this.name = name;
this.type = type;
this.unwrap = unwrap;
}
@Override
public StaticFieldAssignment match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof StaticFieldAssignment)) {
return null;
}
StaticFieldAssignment assign = (StaticFieldAssignment) stmt;
Instruction val = assign.getValue();
if (this.unwrap && val instanceof Cast) {
val = ((Cast) val).getValue();
}
if (!this.value.matches(ctx, val)) {
return null;
}
if (this.owner != null && !this.owner.equals(assign.getOwnerType())) {
return null;
}
if (this.name != null && !this.name.equals(assign.getFieldName())) {
return null;
}
if (this.type != null && !this.type.equals(assign.getFieldDescription())) {
return null;
}
return assign;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> value;
private String owner;
private String name;
private TypeSignature type;
private boolean unwrap;
public Builder() {
reset();
}
public Builder value(InstructionMatcher<?> val) {
this.value = val;
return this;
}
public Builder owner(String owner) {
this.owner = owner;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder type(TypeSignature type) {
this.type = type;
return this;
}
public Builder autoUnwrap() {
this.unwrap = true;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.value = null;
this.type = null;
this.unwrap = false;
this.owner = null;
this.name = null;
return this;
}
public StaticFieldAssignmentMatcher build() {
return new StaticFieldAssignmentMatcher(this.value, this.owner, this.name, this.type, this.unwrap);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/ForLoopMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/ForLoopMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.branch.For;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
import java.util.HashMap;
import java.util.Map;
/**
* A matcher for for loops.
*/
public class ForLoopMatcher implements StatementMatcher<For> {
private StatementMatcher<?> init;
private ConditionMatcher<?> condition;
private StatementMatcher<?> incr;
private Map<Integer, StatementMatcher<?>> body;
ForLoopMatcher(StatementMatcher<?> init, ConditionMatcher<?> cond, StatementMatcher<?> incr, Map<Integer, StatementMatcher<?>> body) {
this.init = init == null ? StatementMatcher.ANY : init;
this.condition = cond == null ? ConditionMatcher.ANY : cond;
this.incr = incr == null ? StatementMatcher.ANY : incr;
this.body = body;
}
@Override
public For match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof For)) {
return null;
}
For loop = (For) stmt;
if (!this.init.matches(ctx, loop.getInit())) {
return null;
}
if (!this.condition.matches(ctx, loop.getCondition())) {
return null;
}
if (!this.incr.matches(ctx, loop.getIncr())) {
return null;
}
for (Map.Entry<Integer, StatementMatcher<?>> e : this.body.entrySet()) {
int index = e.getKey();
if (index < 0) {
index = loop.getBody().getStatementCount() - index;
}
if (index < 0 || index >= loop.getBody().getStatementCount()) {
return null;
}
Statement body_stmt = loop.getBody().getStatement(index);
if (!e.getValue().matches(ctx, body_stmt)) {
return null;
}
}
return loop;
}
/**
* A builder for for loop matchers.
*/
public static class Builder {
private StatementMatcher<?> init;
private ConditionMatcher<?> condition;
private StatementMatcher<?> incr;
private final Map<Integer, StatementMatcher<?>> body = new HashMap<>();
public Builder() {
reset();
}
public Builder init(StatementMatcher<?> s) {
this.init = s;
return this;
}
public Builder condition(ConditionMatcher<?> s) {
this.condition = s;
return this;
}
public Builder incr(StatementMatcher<?> s) {
this.incr = s;
return this;
}
public Builder body(int index, StatementMatcher<?> matcher) {
this.body.put(index, matcher);
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.incr = null;
this.init = null;
this.condition = null;
this.body.clear();
return this;
}
public ForLoopMatcher build() {
return new ForLoopMatcher(this.init, this.condition, this.incr, this.body);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/package-info.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.transform.matcher.statement;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/InstanceFieldAssignmentMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/InstanceFieldAssignmentMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.misc.Cast;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.assign.InstanceFieldAssignment;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
/**
* A matcher for local assignments.
*/
public class InstanceFieldAssignmentMatcher implements StatementMatcher<InstanceFieldAssignment> {
private InstructionMatcher<?> value;
private boolean unwrap;
private String owner;
private String name;
private TypeSignature type;
private InstructionMatcher<?> owner_val;
InstanceFieldAssignmentMatcher(InstructionMatcher<?> value, String owner, String name, TypeSignature type, InstructionMatcher<?> owner_val,
boolean unwrap) {
this.value = value == null ? InstructionMatcher.ANY : value;
this.owner = owner;
this.name = name;
this.type = type;
this.unwrap = unwrap;
this.owner_val = owner_val;
}
@Override
public InstanceFieldAssignment match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof InstanceFieldAssignment)) {
return null;
}
InstanceFieldAssignment assign = (InstanceFieldAssignment) stmt;
Instruction val = assign.getValue();
if (this.unwrap && val instanceof Cast) {
val = ((Cast) val).getValue();
}
if (!this.value.matches(ctx, val)) {
return null;
}
if (this.owner != null && !this.owner.equals(assign.getOwnerType())) {
return null;
}
if (this.name != null && !this.name.equals(assign.getFieldName())) {
return null;
}
if (this.type != null && !this.type.equals(assign.getFieldDescription())) {
return null;
}
if (!this.owner_val.matches(ctx, assign.getOwner())) {
return null;
}
return assign;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> value;
private String owner;
private String name;
private TypeSignature type;
private InstructionMatcher<?> owner_val;
private boolean unwrap;
public Builder() {
reset();
}
public Builder value(InstructionMatcher<?> val) {
this.value = val;
return this;
}
public Builder owner(String owner) {
this.owner = owner;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder type(TypeSignature type) {
this.type = type;
return this;
}
public Builder ownerValue(InstructionMatcher<?> val) {
this.owner_val = val;
return this;
}
public Builder autoUnwrap() {
this.unwrap = true;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.value = null;
this.type = null;
this.unwrap = false;
this.owner = null;
this.name = null;
this.owner_val = null;
return this;
}
public InstanceFieldAssignmentMatcher build() {
return new InstanceFieldAssignmentMatcher(this.value, this.owner, this.name, this.type, this.owner_val, this.unwrap);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/LocalAssignmentMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/LocalAssignmentMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.misc.Cast;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.assign.LocalAssignment;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
/**
* A matcher for local assignments.
*/
public class LocalAssignmentMatcher implements StatementMatcher<LocalAssignment> {
private InstructionMatcher<?> value;
private boolean unwrap;
private TypeSignature type;
LocalAssignmentMatcher(InstructionMatcher<?> value, TypeSignature type, boolean unwrap) {
this.value = value == null ? InstructionMatcher.ANY : value;
this.type = type;
this.unwrap = unwrap;
}
public InstructionMatcher<?> getValueMatcher() {
return this.value;
}
@Override
public LocalAssignment match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof LocalAssignment)) {
return null;
}
LocalAssignment assign = (LocalAssignment) stmt;
Instruction val = assign.getValue();
if (this.unwrap && val instanceof Cast) {
val = ((Cast) val).getValue();
}
if (!this.value.matches(ctx, val)) {
return null;
}
if (this.type != null && !this.type.equals(assign.getLocal().getType())) {
return null;
}
return assign;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> value;
private TypeSignature type;
private boolean unwrap;
public Builder() {
reset();
}
public Builder value(InstructionMatcher<?> val) {
this.value = val;
return this;
}
public Builder type(TypeSignature type) {
this.type = type;
return this;
}
public Builder autoUnwrap() {
this.unwrap = true;
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.value = null;
this.type = null;
this.unwrap = false;
return this;
}
public LocalAssignmentMatcher build() {
return new LocalAssignmentMatcher(this.value, this.type, this.unwrap);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/InvokeMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/InvokeMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.invoke.InvokeStatement;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
/**
* A matcher for increment statements.
*/
public class InvokeMatcher implements StatementMatcher<InvokeStatement> {
private InstructionMatcher<?> value;
InvokeMatcher(InstructionMatcher<?> value) {
this.value = value;
}
@Override
public InvokeStatement match(MatchContext ctx, Statement insn) {
if (!(insn instanceof InvokeStatement)) {
return null;
}
InvokeStatement invoke = (InvokeStatement) insn;
if (!this.value.matches(ctx, invoke.getInstruction())) {
return null;
}
return invoke;
}
/**
* A builder for increment matchers.
*/
public static class Builder {
private InstructionMatcher<?> value;
public Builder() {
reset();
}
public Builder value(InstructionMatcher<?> val) {
this.value = val;
return this;
}
public Builder reset() {
this.value = null;
return this;
}
public InvokeMatcher build() {
return new InvokeMatcher(this.value);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/IfMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/IfMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.branch.If;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
import java.util.HashMap;
import java.util.Map;
/**
* A matcher for if statements.
*/
public class IfMatcher implements StatementMatcher<If> {
private ConditionMatcher<?> condition;
private Map<Integer, StatementMatcher<?>> body;
IfMatcher(ConditionMatcher<?> cond, Map<Integer, StatementMatcher<?>> body) {
this.condition = cond == null ? ConditionMatcher.ANY : cond;
this.body = body;
}
public ConditionMatcher<?> getConditionMatcher() {
return this.condition;
}
@Override
public If match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof If)) {
return null;
}
If loop = (If) stmt;
if (!this.condition.matches(ctx, loop.getCondition())) {
return null;
}
for (Map.Entry<Integer, StatementMatcher<?>> e : this.body.entrySet()) {
int index = e.getKey();
if (index < 0) {
index = loop.getBody().getStatementCount() - index;
}
if (index < 0 || index >= loop.getBody().getStatementCount()) {
return null;
}
Statement body_stmt = loop.getBody().getStatement(index);
if (!e.getValue().matches(ctx, body_stmt)) {
return null;
}
}
return loop;
}
/**
* A matcher builder.
*/
public static class Builder {
private ConditionMatcher<?> condition;
private final Map<Integer, StatementMatcher<?>> body = new HashMap<>();
public Builder() {
reset();
}
public Builder condition(ConditionMatcher<?> s) {
this.condition = s;
return this;
}
public Builder body(int index, StatementMatcher<?> matcher) {
this.body.put(index, matcher);
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.condition = null;
this.body.clear();
return this;
}
public IfMatcher build() {
return new IfMatcher(this.condition, this.body);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/IncrementMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/IncrementMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.misc.Increment;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
/**
* A matcher for increment statements.
*/
public class IncrementMatcher implements StatementMatcher<Increment> {
private Integer value;
IncrementMatcher(Integer value) {
this.value = value;
}
@Override
public Increment match(MatchContext ctx, Statement insn) {
if (!(insn instanceof Increment)) {
return null;
}
Increment invoke = (Increment) insn;
if (this.value != null && invoke.getIncrementValue() != this.value.intValue()) {
return null;
}
return invoke;
}
/**
* A builder for increment matchers.
*/
public static class Builder {
private Integer value;
public Builder() {
reset();
}
public Builder value(int val) {
this.value = val;
return this;
}
public Builder reset() {
this.value = null;
return this;
}
public IncrementMatcher build() {
return new IncrementMatcher(this.value);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/ForEachMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/ForEachMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.branch.ForEach;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
import java.util.HashMap;
import java.util.Map;
/**
* A matcher for for-each loops.
*/
public class ForEachMatcher implements StatementMatcher<ForEach> {
private LocalInstance init;
private InstructionMatcher<?> value;
private Map<Integer, StatementMatcher<?>> body;
ForEachMatcher(LocalInstance init, InstructionMatcher<?> value, Map<Integer, StatementMatcher<?>> body) {
this.init = init;
this.value = value == null ? InstructionMatcher.ANY : value;
this.body = body;
}
@Override
public ForEach match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof ForEach)) {
return null;
}
ForEach loop = (ForEach) stmt;
if (this.init != null && !this.init.equals(loop.getValueAssignment())) {
return null;
}
if (!this.value.matches(ctx, loop.getCollectionValue())) {
return null;
}
for (Map.Entry<Integer, StatementMatcher<?>> e : this.body.entrySet()) {
int index = e.getKey();
if (index < 0) {
index = loop.getBody().getStatementCount() - index;
}
if (index < 0 || index >= loop.getBody().getStatementCount()) {
return null;
}
Statement body_stmt = loop.getBody().getStatement(index);
if (!e.getValue().matches(ctx, body_stmt)) {
return null;
}
}
return loop;
}
/**
* A builder for for-each loop matchers.
*/
public static class Builder {
private LocalInstance init;
private InstructionMatcher<?> value;
private final Map<Integer, StatementMatcher<?>> body = new HashMap<>();
public Builder() {
reset();
}
public Builder init(LocalInstance s) {
this.init = s;
return this;
}
public Builder value(InstructionMatcher<?> s) {
this.value = s;
return this;
}
public Builder body(int index, StatementMatcher<?> matcher) {
this.body.put(index, matcher);
return this;
}
/**
* Resets the builder.
*/
public Builder reset() {
this.init = null;
this.value = null;
this.body.clear();
return this;
}
public ForEachMatcher build() {
return new ForEachMatcher(this.init, this.value, this.body);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/ReturnValueMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/ReturnValueMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.misc.Return;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
/**
* A matcher for increment statements.
*/
public class ReturnValueMatcher implements StatementMatcher<Return> {
private InstructionMatcher<?> value;
ReturnValueMatcher(InstructionMatcher<?> value) {
this.value = value;
}
@Override
public Return match(MatchContext ctx, Statement insn) {
if (!(insn instanceof Return)) {
return null;
}
Return invoke = (Return) insn;
if (!invoke.getValue().isPresent()) {
return null;
}
if (this.value != null && !this.value.matches(ctx, invoke.getValue().get())) {
return null;
}
return invoke;
}
/**
* A builder for increment matchers.
*/
public static class Builder {
private InstructionMatcher<?> value;
public Builder() {
reset();
}
public Builder value(InstructionMatcher<?> val) {
this.value = val;
return this;
}
public Builder reset() {
this.value = null;
return this;
}
public ReturnValueMatcher build() {
return new ReturnValueMatcher(this.value);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/statement/WhileLoopMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/statement/WhileLoopMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.statement;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.branch.While;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.transform.matcher.StatementMatcher;
import java.util.HashMap;
import java.util.Map;
/**
* A matcher for while loops.
*/
public class WhileLoopMatcher implements StatementMatcher<While> {
private ConditionMatcher<?> condition;
private Map<Integer, StatementMatcher<?>> body;
WhileLoopMatcher(ConditionMatcher<?> cond, Map<Integer, StatementMatcher<?>> body) {
this.condition = cond == null ? ConditionMatcher.ANY : cond;
this.body = body;
}
@Override
public While match(MatchContext ctx, Statement stmt) {
if (!(stmt instanceof While)) {
return null;
}
While loop = (While) stmt;
if (!this.condition.matches(ctx, loop.getCondition())) {
return null;
}
for (Map.Entry<Integer, StatementMatcher<?>> e : this.body.entrySet()) {
int index = e.getKey();
if (index < 0) {
index = loop.getBody().getStatementCount() - index;
}
if (index < 0 || index >= loop.getBody().getStatementCount()) {
return null;
}
Statement body_stmt = loop.getBody().getStatement(index);
if (!e.getValue().matches(ctx, body_stmt)) {
return null;
}
}
return loop;
}
/**
* A matcher builder.
*/
public static class Builder {
private ConditionMatcher<?> condition;
private final Map<Integer, StatementMatcher<?>> body = new HashMap<>();
public Builder() {
reset();
}
public Builder condition(ConditionMatcher<?> s) {
this.condition = s;
return this;
}
public Builder body(int index, StatementMatcher<?> matcher) {
this.body.put(index, matcher);
return this;
}
/**
* Resets this builder.
*/
public Builder reset() {
this.condition = null;
this.body.clear();
return this;
}
public WhileLoopMatcher build() {
return new WhileLoopMatcher(this.condition, this.body);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/BooleanConditionMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/BooleanConditionMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.condition;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.insn.condition.BooleanCondition;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.util.Tristate;
/**
* A matcher for boolean conditions.
*/
public class BooleanConditionMatcher implements ConditionMatcher<BooleanCondition> {
private InstructionMatcher<?> value;
private Tristate inverse;
BooleanConditionMatcher(InstructionMatcher<?> val, Tristate inv) {
this.value = val == null ? InstructionMatcher.ANY : val;
this.inverse = checkNotNull(inv, "inverse");
}
@Override
public BooleanCondition match(MatchContext ctx, Condition cond) {
if (!(cond instanceof BooleanCondition)) {
return null;
}
BooleanCondition bool = (BooleanCondition) cond;
if (!this.value.matches(ctx, bool.getConditionValue())) {
return null;
}
if (this.inverse != Tristate.UNDEFINED && this.inverse.asBoolean() != bool.isInverse()) {
return null;
}
return bool;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> value;
private Tristate inverse;
public Builder() {
reset();
}
/**
* Sets the matcher for the boolean value.
*/
public Builder value(InstructionMatcher<?> val) {
this.value = val;
return this;
}
/**
* Sets the expected inverse state.
*/
public Builder inverse(Tristate inv) {
this.inverse = checkNotNull(inv, "inverse");
return this;
}
/**
* Resets the builder to default values.
*/
public Builder reset() {
this.value = null;
this.inverse = Tristate.UNDEFINED;
return this;
}
/**
* Creates a new matcher.
*/
public BooleanConditionMatcher build() {
return new BooleanConditionMatcher(this.value, this.inverse);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/package-info.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.transform.matcher.condition;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/OrConditionMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/OrConditionMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.condition;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.ast.insn.condition.OrCondition;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import java.util.ArrayList;
import java.util.List;
/**
* A matcher for or conditions.
*/
public class OrConditionMatcher implements ConditionMatcher<OrCondition> {
private List<ConditionMatcher<?>> operands;
OrConditionMatcher(List<ConditionMatcher<?>> operands) {
this.operands = checkNotNull(operands, "operands");
}
@Override
public OrCondition match(MatchContext ctx, Condition cond) {
if (!(cond instanceof OrCondition)) {
return null;
}
OrCondition and = (OrCondition) cond;
if (and.getOperands().size() != this.operands.size()) {
return null;
}
for (int i = 0; i < this.operands.size(); i++) {
ConditionMatcher<?> op_match = this.operands.get(i);
if (!op_match.matches(ctx, and.getOperands().get(i))) {
return null;
}
}
return and;
}
/**
* A matcher builder.
*/
public static class Builder {
private List<ConditionMatcher<?>> operands = new ArrayList<>();
public Builder() {
reset();
}
/**
* Adds the given matcher to the operand matchers.
*/
public Builder operand(ConditionMatcher<?> val) {
this.operands.add(val);
return this;
}
/**
* Resets the builder to default values.
*/
public Builder reset() {
this.operands.clear();
return this;
}
/**
* Creates a new matcher.
*/
public OrConditionMatcher build() {
return new OrConditionMatcher(this.operands);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/InverseConditionMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/InverseConditionMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.condition;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.ast.insn.condition.InverseCondition;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
/**
* A matcher for boolean conditions.
*/
public class InverseConditionMatcher implements ConditionMatcher<InverseCondition> {
private ConditionMatcher<?> value;
InverseConditionMatcher(ConditionMatcher<?> val) {
this.value = val == null ? ConditionMatcher.ANY : val;
}
@Override
public InverseCondition match(MatchContext ctx, Condition cond) {
if (!(cond instanceof InverseCondition)) {
return null;
}
InverseCondition bool = (InverseCondition) cond;
if (!this.value.matches(ctx, bool.getConditionValue())) {
return null;
}
return bool;
}
/**
* A matcher builder.
*/
public static class Builder {
private ConditionMatcher<?> value;
public Builder() {
reset();
}
/**
* Sets the matcher for the boolean value.
*/
public Builder value(ConditionMatcher<?> val) {
this.value = val;
return this;
}
/**
* Resets the builder to default values.
*/
public Builder reset() {
this.value = null;
return this;
}
/**
* Creates a new matcher.
*/
public InverseConditionMatcher build() {
return new InverseConditionMatcher(this.value);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/AndConditionMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/AndConditionMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.condition;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.insn.condition.AndCondition;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import java.util.ArrayList;
import java.util.List;
/**
* A matcher for and conditions.
*/
public class AndConditionMatcher implements ConditionMatcher<AndCondition> {
private List<ConditionMatcher<?>> operands;
AndConditionMatcher(List<ConditionMatcher<?>> operands) {
this.operands = checkNotNull(operands, "operands");
}
@Override
public AndCondition match(MatchContext ctx, Condition cond) {
if (!(cond instanceof AndCondition)) {
return null;
}
AndCondition and = (AndCondition) cond;
if (and.getOperands().size() != this.operands.size()) {
return null;
}
for (int i = 0; i < this.operands.size(); i++) {
ConditionMatcher<?> op_match = this.operands.get(i);
if (!op_match.matches(ctx, and.getOperands().get(i))) {
return null;
}
}
return and;
}
/**
* A matcher builder.
*/
public static class Builder {
private List<ConditionMatcher<?>> operands = new ArrayList<>();
public Builder() {
reset();
}
/**
* Adds the given matcher to the operand matchers.
*/
public Builder operand(ConditionMatcher<?> val) {
this.operands.add(val);
return this;
}
/**
* Resets the builder to default values.
*/
public Builder reset() {
this.operands.clear();
return this;
}
/**
* Creates a new matcher.
*/
public AndConditionMatcher build() {
return new AndConditionMatcher(this.operands);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/CompareConditionMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/CompareConditionMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.condition;
import org.spongepowered.despector.ast.insn.condition.CompareCondition;
import org.spongepowered.despector.ast.insn.condition.CompareCondition.CompareOperator;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.InstructionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import javax.annotation.Nullable;
/**
* A matcher for compare conditions.
*/
public class CompareConditionMatcher implements ConditionMatcher<CompareCondition> {
private InstructionMatcher<?> left;
private InstructionMatcher<?> right;
private CompareOperator op;
CompareConditionMatcher(InstructionMatcher<?> left, InstructionMatcher<?> right, CompareOperator op) {
this.left = left == null ? InstructionMatcher.ANY : left;
this.right = right == null ? InstructionMatcher.ANY : right;
this.op = op;
}
@Override
public CompareCondition match(MatchContext ctx, Condition cond) {
if (!(cond instanceof CompareCondition)) {
return null;
}
CompareCondition compare = (CompareCondition) cond;
if (!this.left.matches(ctx, compare.getLeft())) {
return null;
}
if (!this.right.matches(ctx, compare.getRight())) {
return null;
}
if (this.op != null && !this.op.equals(compare.getOperator())) {
return null;
}
return compare;
}
/**
* A matcher builder.
*/
public static class Builder {
private InstructionMatcher<?> left;
private InstructionMatcher<?> right;
private CompareOperator op;
public Builder() {
reset();
}
/**
* Sets the matcher for the left value.
*/
public Builder left(InstructionMatcher<?> val) {
this.left = val;
return this;
}
/**
* Sets the matcher for the right value.
*/
public Builder right(InstructionMatcher<?> val) {
this.right = val;
return this;
}
/**
* Sets the operator.
*/
public Builder operator(@Nullable CompareOperator op) {
this.op = op;
return this;
}
/**
* Resets the builder to default values.
*/
public Builder reset() {
this.left = null;
this.right = null;
this.op = null;
return this;
}
/**
* Creates a new matcher.
*/
public CompareConditionMatcher build() {
return new CompareConditionMatcher(this.left, this.right, this.op);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/matcher/condition/ConditionReferenceMatcher.java | src/main/java/org/spongepowered/despector/transform/matcher/condition/ConditionReferenceMatcher.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.matcher.condition;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.transform.matcher.ConditionMatcher;
import org.spongepowered.despector.transform.matcher.MatchContext;
import org.spongepowered.despector.util.AstUtil;
/**
* A condition matcher that matches any condition references a given local
* instance.
*/
public class ConditionReferenceMatcher implements ConditionMatcher<Condition> {
private final LocalInstance local;
private final String ctx_local;
public ConditionReferenceMatcher(LocalInstance local) {
this.local = local;
this.ctx_local = null;
}
public ConditionReferenceMatcher(String ctx) {
this.ctx_local = ctx;
this.local = null;
}
@Override
public Condition match(MatchContext ctx, Condition cond) {
LocalInstance loc = this.local;
if (loc == null) {
loc = ctx.getLocal(this.ctx_local);
if (loc == null) {
return null;
}
}
if (AstUtil.references(cond, loc)) {
return cond;
}
return null;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/verify/package-info.java | src/main/java/org/spongepowered/despector/transform/verify/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.transform.verify;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/verify/VerificationFailedException.java | src/main/java/org/spongepowered/despector/transform/verify/VerificationFailedException.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.verify;
public class VerificationFailedException extends RuntimeException {
private static final long serialVersionUID = 1L;
public VerificationFailedException() {
super();
}
public VerificationFailedException(String msg) {
super(msg);
}
public VerificationFailedException(Throwable cause) {
super(cause);
}
public VerificationFailedException(String msg, Throwable cause) {
super(msg, cause);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/verify/VerifyVisitor.java | src/main/java/org/spongepowered/despector/transform/verify/VerifyVisitor.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.verify;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.ast.insn.cst.DoubleConstant;
import org.spongepowered.despector.ast.insn.cst.FloatConstant;
import org.spongepowered.despector.ast.insn.cst.IntConstant;
import org.spongepowered.despector.ast.insn.cst.LongConstant;
import org.spongepowered.despector.ast.insn.cst.NullConstant;
import org.spongepowered.despector.ast.insn.cst.StringConstant;
import org.spongepowered.despector.ast.insn.cst.TypeConstant;
import org.spongepowered.despector.ast.insn.misc.Cast;
import org.spongepowered.despector.ast.insn.misc.InstanceOf;
import org.spongepowered.despector.ast.insn.misc.MultiNewArray;
import org.spongepowered.despector.ast.insn.misc.NewArray;
import org.spongepowered.despector.ast.insn.misc.NumberCompare;
import org.spongepowered.despector.ast.insn.misc.Ternary;
import org.spongepowered.despector.ast.insn.op.NegativeOperator;
import org.spongepowered.despector.ast.insn.op.Operator;
import org.spongepowered.despector.ast.insn.var.ArrayAccess;
import org.spongepowered.despector.ast.insn.var.InstanceFieldAccess;
import org.spongepowered.despector.ast.insn.var.LocalAccess;
import org.spongepowered.despector.ast.insn.var.StaticFieldAccess;
import org.spongepowered.despector.ast.stmt.StatementVisitor;
import org.spongepowered.despector.ast.stmt.assign.ArrayAssignment;
import org.spongepowered.despector.ast.stmt.assign.InstanceFieldAssignment;
import org.spongepowered.despector.ast.stmt.assign.LocalAssignment;
import org.spongepowered.despector.ast.stmt.assign.StaticFieldAssignment;
import org.spongepowered.despector.ast.stmt.branch.Break;
import org.spongepowered.despector.ast.stmt.branch.DoWhile;
import org.spongepowered.despector.ast.stmt.branch.For;
import org.spongepowered.despector.ast.stmt.branch.ForEach;
import org.spongepowered.despector.ast.stmt.branch.If;
import org.spongepowered.despector.ast.stmt.branch.If.Elif;
import org.spongepowered.despector.ast.stmt.branch.If.Else;
import org.spongepowered.despector.ast.stmt.branch.Switch;
import org.spongepowered.despector.ast.stmt.branch.Switch.Case;
import org.spongepowered.despector.ast.stmt.branch.TryCatch;
import org.spongepowered.despector.ast.stmt.branch.TryCatch.CatchBlock;
import org.spongepowered.despector.ast.stmt.branch.While;
import org.spongepowered.despector.ast.stmt.invoke.Lambda;
import org.spongepowered.despector.ast.stmt.invoke.MethodReference;
import org.spongepowered.despector.ast.stmt.invoke.InstanceMethodInvoke;
import org.spongepowered.despector.ast.stmt.invoke.InvokeStatement;
import org.spongepowered.despector.ast.stmt.invoke.New;
import org.spongepowered.despector.ast.stmt.invoke.StaticMethodInvoke;
import org.spongepowered.despector.ast.stmt.misc.Comment;
import org.spongepowered.despector.ast.stmt.misc.Increment;
import org.spongepowered.despector.ast.stmt.misc.Return;
import org.spongepowered.despector.ast.stmt.misc.Throw;
import org.spongepowered.despector.ast.type.AnnotationEntry;
import org.spongepowered.despector.ast.type.ClassEntry;
import org.spongepowered.despector.ast.type.EnumEntry;
import org.spongepowered.despector.ast.type.FieldEntry;
import org.spongepowered.despector.ast.type.InterfaceEntry;
import org.spongepowered.despector.ast.type.MethodEntry;
import org.spongepowered.despector.ast.type.TypeEntry;
import org.spongepowered.despector.ast.type.TypeVisitor;
import java.util.HashSet;
import java.util.Set;
public class VerifyVisitor implements TypeVisitor, StatementVisitor, InstructionVisitor {
private static boolean isNumber(TypeSignature sig) {
return sig == ClassTypeSignature.INT || sig == ClassTypeSignature.LONG || sig == ClassTypeSignature.FLOAT || sig == ClassTypeSignature.DOUBLE
|| sig == ClassTypeSignature.BYTE || sig == ClassTypeSignature.SHORT;
}
private TypeEntry type;
private MethodEntry mth;
private int line;
private Set<LocalInstance> defined_locals = new HashSet<>();
private void check(boolean state, String msg) {
if (!state) {
String header = "Verification in " + this.type.getName();
if (this.mth != null) {
header += "#" + this.mth.getName() + this.mth.getDescription();
header += " (line: " + this.line + ")";
}
header += ": ";
throw new VerificationFailedException(header + msg);
}
}
@Override
public void visitArrayAccess(ArrayAccess insn) {
check(insn.getIndex().inferType().equals(ClassTypeSignature.INT),
"Array index must be an integer found: " + insn.getIndex().inferType().toString());
}
@Override
public void visitCast(Cast insn) {
// TODO warn if types seem incompatible
}
@Override
public void visitDoubleConstant(DoubleConstant insn) {
}
@Override
public void visitDynamicInvoke(Lambda insn) {
// TODO check handle is valid
}
@Override
public void visitFloatConstant(FloatConstant insn) {
}
@Override
public void visitInstanceFieldAccess(InstanceFieldAccess insn) {
// TODO check field exists
}
@Override
public void visitInstanceMethodInvoke(InstanceMethodInvoke insn) {
// TODO check methode exists
}
@Override
public void visitInstanceOf(InstanceOf insn) {
// TODO warn if types seem incompatible
}
@Override
public void visitIntConstant(IntConstant insn) {
}
@Override
public void visitLocalAccess(LocalAccess insn) {
check(this.defined_locals.contains(insn.getLocal()), "Access local not yet definde");
}
@Override
public void visitLocalInstance(LocalInstance local) {
}
@Override
public void visitLongConstant(LongConstant insn) {
}
@Override
public void visitNegativeOperator(NegativeOperator insn) {
check(isNumber(insn.getOperand().inferType()), "Can only negate number types found: " + insn.getOperand().inferType().toString());
}
@Override
public void visitNew(New insn) {
// TODO check type is valid
// TODO check params matches inferred type
// TODO check return type matches inferred type
}
@Override
public void visitNewArray(NewArray insn) {
check(insn.getSize().inferType().equals(ClassTypeSignature.INT),
"Array size must be an integer found: " + insn.getSize().inferType().toString());
}
@Override
public void visitNullConstant(NullConstant insn) {
}
@Override
public void visitNumberCompare(NumberCompare insn) {
check(isNumber(insn.getLeftOperand().inferType()), "Can only compare number types found: " + insn.getLeftOperand().inferType().toString());
check(isNumber(insn.getRightOperand().inferType()), "Can only compare number types found: " + insn.getRightOperand().inferType().toString());
}
@Override
public void visitOperator(Operator insn) {
check(isNumber(insn.getLeftOperand().inferType()),
"Can only use operator on number types found: " + insn.getLeftOperand().inferType().toString());
check(isNumber(insn.getRightOperand().inferType()),
"Can only use operator on number types found: " + insn.getRightOperand().inferType().toString());
}
@Override
public void visitStaticFieldAccess(StaticFieldAccess insn) {
// TODO check field exists
}
@Override
public void visitStaticMethodInvoke(StaticMethodInvoke insn) {
// TODO check method exists
}
@Override
public void visitStringConstant(StringConstant insn) {
}
@Override
public void visitTernary(Ternary insn) {
// TODO check type of each side is equivalent
}
@Override
public void visitTypeConstant(TypeConstant insn) {
// TODO check type is valid
}
@Override
public void visitArrayAssignment(ArrayAssignment stmt) {
check(stmt.getIndex().inferType().equals(ClassTypeSignature.INT),
"Array index must be an integer found: " + stmt.getIndex().inferType().toString());
}
@Override
public void visitBreak(Break breakStatement) {
}
@Override
public void visitCatchBlock(CatchBlock stmt) {
}
@Override
public void visitComment(Comment comment) {
}
@Override
public void visitDoWhile(DoWhile doWhileLoop) {
}
@Override
public void visitElif(Elif elseBlock) {
}
@Override
public void visitElse(Else elseBlock) {
}
@Override
public void visitFor(For forLoop) {
}
@Override
public void visitForEach(ForEach forLoop) {
}
@Override
public void visitIf(If ifBlock) {
}
@Override
public void visitIncrement(Increment stmt) {
check(isNumber(stmt.getLocal().getType()), "Can only increment local containing a number found: " + stmt.getLocal().getType().toString());
}
@Override
public void visitInstanceFieldAssignment(InstanceFieldAssignment stmt) {
// TODO check field exists
}
@Override
public void visitInvoke(InvokeStatement stmt) {
}
@Override
public void visitLocalAssignment(LocalAssignment stmt) {
this.defined_locals.add(stmt.getLocal());
// TODO check value matches local type
}
@Override
public void visitReturn(Return returnValue) {
// TODO check value matches return type
}
@Override
public void visitStaticFieldAssignment(StaticFieldAssignment staticFieldAssign) {
// TODO check field exists
}
@Override
public void visitSwitch(Switch tableSwitch) {
check(tableSwitch.getSwitchVar().inferType().equals(ClassTypeSignature.INT),
"Array size must be an integer found: " + tableSwitch.getSwitchVar().inferType().toString());
}
@Override
public void visitSwitchCase(Case case1) {
}
@Override
public void visitThrow(Throw throwException) {
}
@Override
public void visitTryCatch(TryCatch tryBlock) {
}
@Override
public void visitWhile(While whileLoop) {
}
@Override
public void visitClassEntry(ClassEntry type) {
this.type = type;
check(type.getSuperclass() != null, "Class supertype cannot be null");
}
@Override
public void visitEnumEntry(EnumEntry type) {
this.type = type;
}
@Override
public void visitInterfaceEntry(InterfaceEntry type) {
this.type = type;
}
@Override
public void visitAnnotation(Annotation annotation) {
}
@Override
public void visitMethod(MethodEntry mth) {
this.mth = mth;
}
@Override
public void visitField(FieldEntry fld) {
}
@Override
public void visitMethodEnd() {
this.mth = null;
}
@Override
public void visitTypeEnd() {
this.type = null;
}
@Override
public void visitAnnotationEntry(AnnotationEntry type) {
}
@Override
public void visitMultiNewArray(MultiNewArray insn) {
}
@Override
public void visitMethodReference(MethodReference methodReference) {
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/MethodBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/MethodBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
import org.spongepowered.despector.ast.Locals;
import org.spongepowered.despector.ast.Locals.Local;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.StatementBlock;
import org.spongepowered.despector.ast.stmt.misc.Return;
import org.spongepowered.despector.ast.stmt.misc.Throw;
import org.spongepowered.despector.ast.type.MethodEntry;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class MethodBuilder {
private Consumer<MethodEntry> callback;
private String name;
private String desc;
private boolean is_static;
private boolean is_abstract;
private final List<Statement> statements = new ArrayList<>();
private Locals locals;
private int next_local;
public MethodBuilder() {
reset();
}
MethodBuilder(Consumer<MethodEntry> callback) {
this();
this.callback = callback;
}
public LocalInstance createLocal(String name, TypeSignature type) {
if (this.locals == null) {
MethodEntry dummy = new MethodEntry(new SourceSet());
dummy.setStatic(this.is_static);
dummy.setDescription(this.desc);
this.locals = new Locals(dummy);
}
Local local = this.locals.getLocal(this.next_local++);
LocalInstance instance = new LocalInstance(local, name, type, -1, -1);
if (type.getDescriptor().equals("D") || type.getDescriptor().equals("J")) {
this.next_local++;
}
local.addInstance(instance);
return instance;
}
public MethodBuilder name(String name) {
this.name = name;
return this;
}
public MethodBuilder desc(String desc) {
this.desc = desc;
return this;
}
public MethodBuilder setStatic(boolean state) {
this.is_static = state;
return this;
}
public MethodBuilder setAbstract(boolean state) {
this.is_abstract = state;
return this;
}
public MethodBuilder statement(Statement stmt) {
this.statements.add(stmt);
return this;
}
public MethodBuilder reset() {
this.name = null;
this.is_static = false;
this.is_abstract = false;
this.statements.clear();
this.desc = null;
this.locals = null;
this.next_local = 1;
return this;
}
public MethodEntry build(SourceSet set) {
MethodEntry mth = new MethodEntry(set);
mth.setName(this.name);
mth.setStatic(this.is_static);
mth.setAbstract(this.is_abstract);
mth.setDescription(this.desc);
mth.setLocals(this.locals);
if (!this.is_abstract) {
StatementBlock block = new StatementBlock(StatementBlock.Type.METHOD);
for (Statement stmt : this.statements) {
block.append(stmt);
}
mth.setInstructions(block);
if (this.statements.isEmpty() || !(this.statements.get(this.statements.size() - 1) instanceof Return)
&& !(this.statements.get(this.statements.size() - 1) instanceof Throw)) {
if (this.desc.endsWith("V")) {
block.append(new Return());
} else {
throw new IllegalStateException("Last statement must be return or throw");
}
}
}
if (this.callback != null) {
this.callback.accept(mth);
}
return mth;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/TypeBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/TypeBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
import org.spongepowered.despector.ast.AccessModifier;
import org.spongepowered.despector.ast.type.FieldEntry;
import org.spongepowered.despector.ast.type.MethodEntry;
import org.spongepowered.despector.ast.type.TypeEntry;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("unchecked")
public abstract class TypeBuilder<B extends TypeBuilder<B>> {
protected final String name;
private AccessModifier access;
private final List<String> interfaces = new ArrayList<>();
private final List<FieldEntry> fields = new ArrayList<>();
private final List<MethodEntry> methods = new ArrayList<>();
public TypeBuilder(String n) {
this.name = n;
}
public B implement(String inter) {
this.interfaces.add(inter);
return (B) this;
}
public B access(AccessModifier acc) {
this.access = acc;
return (B) this;
}
public MethodBuilder method() {
return new MethodBuilder((m) -> {
this.methods.add(m);
m.setOwner(this.name);
});
}
public FieldBuilder field() {
return new FieldBuilder((m) -> {
this.fields.add(m);
m.setOwner(this.name);
});
}
public B reset() {
this.interfaces.clear();
this.methods.clear();
return (B) this;
}
protected void apply(TypeEntry type) {
type.setAccessModifier(this.access);
type.getInterfaces().addAll(this.interfaces);
for (MethodEntry m : this.methods) {
type.addMethod(m);
}
for (FieldEntry f : this.fields) {
type.addField(f);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/AnnotationTypeBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/AnnotationTypeBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
public class AnnotationTypeBuilder extends TypeBuilder<AnnotationTypeBuilder> {
public AnnotationTypeBuilder(String name) {
super(name);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/EnumTypeBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/EnumTypeBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
public class EnumTypeBuilder extends TypeBuilder<EnumTypeBuilder> {
public EnumTypeBuilder(String name) {
super(name);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/Builders.java | src/main/java/org/spongepowered/despector/transform/builder/Builders.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.cst.IntConstant;
import org.spongepowered.despector.ast.stmt.assign.LocalAssignment;
import org.spongepowered.despector.ast.stmt.misc.Return;
public final class Builders {
public static ClassTypeBuilder createClass(String name) {
return new ClassTypeBuilder(name);
}
public static IntConstant integer(int val) {
return new IntConstant(val);
}
public static LocalAssignment localAssign(LocalInstance i, Instruction val) {
return new LocalAssignment(i, val);
}
public static Return returnVoid() {
return new Return();
}
private Builders() {
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/InterfaceTypeBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/InterfaceTypeBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
public class InterfaceTypeBuilder extends TypeBuilder<InterfaceTypeBuilder> {
public InterfaceTypeBuilder(String name) {
super(name);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/FieldBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/FieldBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.ast.type.FieldEntry;
import java.util.function.Consumer;
public class FieldBuilder {
private Consumer<FieldEntry> callback;
private String name;
public FieldBuilder() {
reset();
}
FieldBuilder(Consumer<FieldEntry> callback) {
this();
this.callback = callback;
}
public FieldBuilder name(String name) {
this.name = name;
return this;
}
public FieldBuilder reset() {
return this;
}
public FieldEntry build(SourceSet set) {
FieldEntry fld = new FieldEntry(set);
fld.setName(this.name);
if (this.callback != null) {
this.callback.accept(fld);
}
return fld;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/builder/ClassTypeBuilder.java | src/main/java/org/spongepowered/despector/transform/builder/ClassTypeBuilder.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.builder;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.ast.type.ClassEntry;
public class ClassTypeBuilder extends TypeBuilder<ClassTypeBuilder> {
private String supertype;
public ClassTypeBuilder(String n) {
super(n);
reset();
}
public ClassTypeBuilder supertype(String spr) {
this.supertype = spr;
return this;
}
@Override
public ClassTypeBuilder reset() {
super.reset();
this.supertype = "Ljava/lang/Object;";
return this;
}
public ClassEntry build(SourceSet set) {
ClassEntry entry = new ClassEntry(set, Language.JAVA, this.name);
entry.setSuperclass(this.supertype);
apply(entry);
return entry;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/cleanup/package-info.java | src/main/java/org/spongepowered/despector/transform/cleanup/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.transform.cleanup;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/cleanup/CleanupOperations.java | src/main/java/org/spongepowered/despector/transform/cleanup/CleanupOperations.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.cleanup;
import com.google.common.collect.Maps;
import org.spongepowered.despector.transform.TypeTransformer;
import java.util.Map;
/**
* Operations which may be applied to an AST to perform refactoring operations.
*/
public class CleanupOperations {
private static final Map<String, TypeTransformer> operations = Maps.newHashMap();
static {
operations.put("private_final_utility_classes", new UtilityClassNoInstance());
operations.put("convert_large_constants_to_hex", new HexConstantsTransformer());
}
/**
* Gets the operation corresponding to the given id, or null if not defined.
*/
public static TypeTransformer getOperation(String id) {
return operations.get(id);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/cleanup/UtilityClassNoInstance.java | src/main/java/org/spongepowered/despector/transform/cleanup/UtilityClassNoInstance.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.cleanup;
import org.spongepowered.despector.ast.AccessModifier;
import org.spongepowered.despector.ast.type.ClassEntry;
import org.spongepowered.despector.ast.type.MethodEntry;
import org.spongepowered.despector.ast.type.TypeEntry;
import org.spongepowered.despector.transform.TypeTransformer;
/**
* Ensures utility classes (no instance fields or methods) are declared as final
* with a private constructor.
*/
public class UtilityClassNoInstance implements TypeTransformer {
@Override
public void transform(TypeEntry type) {
if (!(type instanceof ClassEntry)) {
return;
}
if (type.getFieldCount() != 0) {
return;
}
if (type.getMethodCount() != 1) {
return;
}
MethodEntry ctor = type.getMethod("<init>");
if (!ctor.getParamTypes().isEmpty() || ctor.getInstructions().getStatements().size() != 2) {
return;
}
ctor.setAccessModifier(AccessModifier.PRIVATE);
type.setFinal(true);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/transform/cleanup/HexConstantsTransformer.java | src/main/java/org/spongepowered/despector/transform/cleanup/HexConstantsTransformer.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.transform.cleanup;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.ast.insn.cst.DoubleConstant;
import org.spongepowered.despector.ast.insn.cst.FloatConstant;
import org.spongepowered.despector.ast.insn.cst.IntConstant;
import org.spongepowered.despector.ast.insn.cst.IntConstant.IntFormat;
import org.spongepowered.despector.ast.insn.cst.LongConstant;
import org.spongepowered.despector.ast.insn.cst.NullConstant;
import org.spongepowered.despector.ast.insn.cst.StringConstant;
import org.spongepowered.despector.ast.insn.cst.TypeConstant;
import org.spongepowered.despector.ast.insn.misc.Cast;
import org.spongepowered.despector.ast.insn.misc.InstanceOf;
import org.spongepowered.despector.ast.insn.misc.MultiNewArray;
import org.spongepowered.despector.ast.insn.misc.NewArray;
import org.spongepowered.despector.ast.insn.misc.NumberCompare;
import org.spongepowered.despector.ast.insn.misc.Ternary;
import org.spongepowered.despector.ast.insn.op.NegativeOperator;
import org.spongepowered.despector.ast.insn.op.Operator;
import org.spongepowered.despector.ast.insn.var.ArrayAccess;
import org.spongepowered.despector.ast.insn.var.InstanceFieldAccess;
import org.spongepowered.despector.ast.insn.var.LocalAccess;
import org.spongepowered.despector.ast.insn.var.StaticFieldAccess;
import org.spongepowered.despector.ast.stmt.invoke.Lambda;
import org.spongepowered.despector.ast.stmt.invoke.MethodReference;
import org.spongepowered.despector.ast.stmt.invoke.InstanceMethodInvoke;
import org.spongepowered.despector.ast.stmt.invoke.New;
import org.spongepowered.despector.ast.stmt.invoke.StaticMethodInvoke;
import org.spongepowered.despector.ast.type.MethodEntry;
import org.spongepowered.despector.ast.type.TypeEntry;
import org.spongepowered.despector.transform.TypeTransformer;
/**
* A cleanup transformer than converts messy large decimals to hexadecimal.
*/
public class HexConstantsTransformer implements TypeTransformer {
@Override
public void transform(TypeEntry type) {
Walker walker = new Walker();
for (MethodEntry mth : type.getMethods()) {
mth.getInstructions().accept(walker);
}
for (MethodEntry mth : type.getStaticMethods()) {
mth.getInstructions().accept(walker);
}
}
/**
* A visitor to replace messy integer constants.
*/
private static class Walker implements InstructionVisitor {
private static final int MIN_CONSTANT = 10000;
public Walker() {
}
@Override
public void visitIntConstant(IntConstant arg) {
if (arg.getConstant() > MIN_CONSTANT && !String.valueOf(arg.getConstant()).endsWith("000")) {
arg.setFormat(IntFormat.HEXADECIMAL);
}
}
@Override
public void visitArrayAccess(ArrayAccess insn) {
}
@Override
public void visitCast(Cast insn) {
}
@Override
public void visitDoubleConstant(DoubleConstant insn) {
}
@Override
public void visitDynamicInvoke(Lambda insn) {
}
@Override
public void visitFloatConstant(FloatConstant insn) {
}
@Override
public void visitInstanceFieldAccess(InstanceFieldAccess insn) {
}
@Override
public void visitInstanceMethodInvoke(InstanceMethodInvoke insn) {
}
@Override
public void visitInstanceOf(InstanceOf insn) {
}
@Override
public void visitLocalAccess(LocalAccess insn) {
}
@Override
public void visitLocalInstance(LocalInstance local) {
}
@Override
public void visitLongConstant(LongConstant insn) {
}
@Override
public void visitNegativeOperator(NegativeOperator insn) {
}
@Override
public void visitNew(New insn) {
}
@Override
public void visitNewArray(NewArray insn) {
}
@Override
public void visitNullConstant(NullConstant insn) {
}
@Override
public void visitNumberCompare(NumberCompare insn) {
}
@Override
public void visitOperator(Operator insn) {
}
@Override
public void visitStaticFieldAccess(StaticFieldAccess insn) {
}
@Override
public void visitStaticMethodInvoke(StaticMethodInvoke insn) {
}
@Override
public void visitStringConstant(StringConstant insn) {
}
@Override
public void visitTernary(Ternary insn) {
}
@Override
public void visitTypeConstant(TypeConstant insn) {
}
@Override
public void visitMultiNewArray(MultiNewArray insn) {
}
@Override
public void visitMethodReference(MethodReference methodReference) {
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/parallel/Scheduler.java | src/main/java/org/spongepowered/despector/parallel/Scheduler.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.parallel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class Scheduler<T extends Runnable> {
private static final int PARALLEL_THRESHOLD = 100;
private final Worker<T>[] workers;
private final List<T> tasks = new ArrayList<>();
private ReentrantLock lock = new ReentrantLock();
private Condition finished = this.lock.newCondition();
private int finished_count;
@SuppressWarnings("unchecked")
public Scheduler(int workers) {
if (workers <= 0) {
workers = 1;
}
this.workers = new Worker[workers];
}
public void add(T task) {
this.tasks.add(task);
}
public List<T> getTasks() {
return this.tasks;
}
public void execute() {
if (this.tasks.size() < PARALLEL_THRESHOLD) {
for (T task : this.tasks) {
task.run();
}
return;
}
for (int i = 0; i < this.workers.length; i++) {
this.workers[i] = new Worker<>();
}
int i = 0;
for (T task : this.tasks) {
this.workers[i % this.workers.length].add(task);
i++;
}
this.finished_count = 0;
for (Worker<T> worker : this.workers) {
worker.start();
}
try {
this.lock.lock();
this.finished.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
this.lock.unlock();
}
for (int j = 0; j < this.workers.length; j++) {
this.workers[j] = null;
}
}
public void reset() {
this.tasks.clear();
}
void markWorkerDone() {
try {
this.lock.lock();
this.finished_count++;
if (this.finished_count == this.workers.length) {
this.finished.signalAll();
}
} finally {
this.lock.unlock();
}
}
private class Worker<R> extends Thread {
private final List<T> tasks = new ArrayList<>();
Worker() {
}
public void add(T task) {
this.tasks.add(task);
}
@Override
public void run() {
for (T task : this.tasks) {
task.run();
}
Scheduler.this.markWorkerDone();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/parallel/Timing.java | src/main/java/org/spongepowered/despector/parallel/Timing.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.parallel;
public class Timing {
public static long time_decompiling = 0;
public static long time_decompiling_methods = 0;
public static long time_loading_classes = 0;
public static long time_emitting = 0;
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/parallel/MethodDecompileTask.java | src/main/java/org/spongepowered/despector/parallel/MethodDecompileTask.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.parallel;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.Locals.Local;
import org.spongepowered.despector.ast.generic.MethodSignature;
import org.spongepowered.despector.ast.insn.cst.StringConstant;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.StatementBlock;
import org.spongepowered.despector.ast.stmt.assign.StaticFieldAssignment;
import org.spongepowered.despector.ast.stmt.invoke.New;
import org.spongepowered.despector.ast.stmt.misc.Comment;
import org.spongepowered.despector.ast.type.EnumEntry;
import org.spongepowered.despector.ast.type.MethodEntry;
import org.spongepowered.despector.ast.type.TypeEntry;
import org.spongepowered.despector.config.ConfigManager;
import org.spongepowered.despector.config.LibraryConfiguration;
import org.spongepowered.despector.decompiler.BaseDecompiler;
import org.spongepowered.despector.decompiler.Decompilers;
import org.spongepowered.despector.decompiler.BaseDecompiler.BootstrapMethod;
import org.spongepowered.despector.decompiler.BaseDecompiler.UnfinishedMethod;
import org.spongepowered.despector.decompiler.ir.Insn;
import org.spongepowered.despector.decompiler.loader.BytecodeTranslator;
import org.spongepowered.despector.decompiler.loader.ClassConstantPool;
import org.spongepowered.despector.decompiler.method.MethodDecompiler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class MethodDecompileTask implements Runnable {
private final TypeEntry entry;
private final ClassConstantPool pool;
private final List<UnfinishedMethod> unfinished_methods;
private final BytecodeTranslator bytecode;
private final List<BootstrapMethod> bootstrap_methods;
public MethodDecompileTask(TypeEntry entry, ClassConstantPool pool, List<UnfinishedMethod> unfinished_methods, BytecodeTranslator bytecode,
List<BootstrapMethod> bootstrap_methods) {
this.entry = entry;
this.pool = pool;
this.unfinished_methods = unfinished_methods;
this.bytecode = bytecode;
this.bootstrap_methods = bootstrap_methods;
}
public TypeEntry getEntry() {
return this.entry;
}
@Override
public void run() {
for (UnfinishedMethod unfinished : this.unfinished_methods) {
if (unfinished.code == null) {
continue;
}
LibraryConfiguration.total_method_count++;
MethodEntry mth = unfinished.mth;
try {
mth.setIR(this.bytecode.createIR(mth.getMethodSignature(), unfinished.code, mth.getLocals(), unfinished.catch_regions, this.pool,
this.bootstrap_methods));
if (unfinished.parameter_annotations != null) {
for (Map.Entry<Integer, List<Annotation>> e : unfinished.parameter_annotations.entrySet()) {
Local loc = mth.getLocals().getLocal(e.getKey());
loc.getInstance(0).getAnnotations().addAll(e.getValue());
}
}
if (BaseDecompiler.DUMP_IR_ON_LOAD) {
System.out.println("Instructions of " + mth.getName() + " " + mth.getDescription());
System.out.println(mth.getIR());
}
MethodDecompiler mth_decomp = Decompilers.JAVA_METHOD;
if (this.entry.getLanguage() == Language.KOTLIN) {
mth_decomp = Decompilers.KOTLIN_METHOD;
}
StatementBlock block = mth_decomp.decompile(mth);
mth.setInstructions(block);
if (this.entry instanceof EnumEntry && mth.getName().equals("<clinit>")) {
EnumEntry e = (EnumEntry) this.entry;
Set<String> names = new HashSet<>(e.getEnumConstants());
e.getEnumConstants().clear();
for (Statement stmt : block) {
if (names.isEmpty() || !(stmt instanceof StaticFieldAssignment)) {
break;
}
StaticFieldAssignment assign = (StaticFieldAssignment) stmt;
if (!names.remove(assign.getFieldName())) {
break;
}
New val = (New) assign.getValue();
StringConstant cst = (StringConstant) val.getParameters()[0];
e.addEnumConstant(cst.getConstant());
}
if (!names.isEmpty()) {
System.err.println("Warning: Failed to find names for all enum constants in " + this.entry.getName());
}
}
} catch (Exception ex) {
if (!LibraryConfiguration.quiet) {
System.err.println("Error decompiling method body for " + this.entry.getName() + " " + mth.toString());
ex.printStackTrace();
}
LibraryConfiguration.failed_method_count++;
StatementBlock insns = new StatementBlock(StatementBlock.Type.METHOD);
if (ConfigManager.getConfig().print_opcodes_on_error) {
List<String> text = new ArrayList<>();
text.add("Error decompiling block");
if (mth.getIR() != null) {
for (Insn next : mth.getIR()) {
text.add(next.toString());
}
} else {
mth.getLocals().bakeInstances(new MethodSignature(), Collections.emptyList());
}
insns.append(new Comment(text));
} else {
insns.append(new Comment("Error decompiling block"));
}
mth.setInstructions(insns);
}
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/config/package-info.java | src/main/java/org/spongepowered/despector/config/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.config;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/config/LibraryConfiguration.java | src/main/java/org/spongepowered/despector/config/LibraryConfiguration.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.config;
/**
* Static config designed to be set when despector is being used as a library.
*/
public class LibraryConfiguration {
public static boolean quiet = false;
public static boolean parallel = true;
public static boolean print_times = false;
public static boolean force_lang = false;
// Viewer control fields
public static boolean emit_block_debug = false;
public static int failed_method_count = 0;
public static int total_method_count = 0;
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/config/ConfigBase.java | src/main/java/org/spongepowered/despector/config/ConfigBase.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.config;
import com.google.common.collect.Lists;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import org.spongepowered.despector.emitter.format.EmitterFormat.BracePosition;
import org.spongepowered.despector.emitter.format.EmitterFormat.WrappingStyle;
import java.util.ArrayList;
import java.util.List;
/**
* The global configuration.
*/
public class ConfigBase {
@Setting(comment = "Emitter configuration")
public EmitterConfig emitter = new EmitterConfig();
@Setting(comment = "Cleanup configuration")
public CleanupConfig cleanup = new CleanupConfig();
@Setting(comment = "Kotlin specific configuration")
public KotlinConfig kotlin = new KotlinConfig();
@Setting(comment = "Formatting configuration, a defined formatter config from the command line will override these settings.")
public FormatterConfig formatter = new FormatterConfig();
@Setting(comment = "Targeted cleanup operations")
public List<CleanupConfigSection> cleanup_sections = new ArrayList<>();
@Setting(value = "print-opcodes-on-error", comment = "Prints out opcodes of a method when it fails to decompile.")
public boolean print_opcodes_on_error = Boolean.valueOf(System.getProperty("despector.debug.printerrors", "false"));
/**
* Configuration for the emitter settings.
*/
@ConfigSerializable
public static class EmitterConfig {
@Setting(value = "formatting-path", comment = "The path of the formatter configuration")
public String formatting_path = "eclipse_formatter.xml";
@Setting(value = "import-order-path", comment = "The path of the import order configuration")
public String imports_path = "eclipse.importorder";
@Setting(value = "formatting-type", comment = "One of: eclipse,intellij")
public String formatting_type = "eclipse";
@Setting(value = "emit-synthetics", comment = "Whether to emit synthetic members")
public boolean emit_synthetics = false;
public boolean emit_this_for_fields = true;
public boolean emit_this_for_methods = false;
}
/**
* Configuration for the cleanup operations.
*/
@ConfigSerializable
public static class CleanupConfig {
@Setting(value = "operations", comment = "Cleanup operations to apply before emitting")
public List<String> operations = new ArrayList<>();
}
/**
* Configuration for a targeted cleanup operation.
*/
@ConfigSerializable
public static class CleanupConfigSection {
@Setting(value = "operations", comment = "Cleanup operations to apply before emitting")
public List<String> operations = new ArrayList<>();
@Setting(value = "targets", comment = "Class targets to apply this cleanup to")
public List<String> targets = new ArrayList<>();
}
/**
* Configuration specific to kotlin decompilation.
*/
@ConfigSerializable
public static class KotlinConfig {
@Setting(value = "replace-multiline-strings", comment = "Whether to replace strings containing new lines with raw strings")
public boolean replace_mulit_line_strings = true;
}
/**
* Configuration for the output formatting.
*/
@ConfigSerializable
public static class FormatterConfig {
public General general = new General();
public Imports imports = new Imports();
public Classes classes = new Classes();
public Enums enums = new Enums();
public Fields fields = new Fields();
public Methods methods = new Methods();
public Misc misc = new Misc();
public Arrays arrays = new Arrays();
public Switches switches = new Switches();
public Loops loops = new Loops();
public Ifs ifs = new Ifs();
public TryCatches trycatches = new TryCatches();
public Annotations annotations = new Annotations();
/**
* Configuration for general formatting.
*/
@ConfigSerializable
public static class General {
public int line_split = 999;
public int indentation_size = 4;
public int continuation_indentation = 2;
public boolean indent_with_spaces = true;
public boolean indent_empty_lines = false;
public boolean insert_new_line_at_end_of_file_if_missing = true;
}
/**
* Configuration for import formating.
*/
@ConfigSerializable
public static class Imports {
public List<String> import_order = Lists.newArrayList("/#", "", "java", "javax");
public int blank_lines_before_package = 0;
public int blank_lines_after_package = 1;
public int blank_lines_before_imports = 1;
public int blank_lines_after_imports = 1;
public int blank_lines_between_import_groups = 1;
}
/**
* Configuration for class formatting.
*/
@ConfigSerializable
public static class Classes {
public boolean insert_space_before_comma_in_superinterfaces = false;
public boolean insert_space_after_comma_in_superinterfaces = true;
public int blank_lines_before_first_class_body_declaration = 1;
public BracePosition brace_position_for_type_declaration = BracePosition.SAME_LINE;
public WrappingStyle alignment_for_superclass_in_type_declaration = WrappingStyle.DO_NOT_WRAP;
public WrappingStyle alignment_for_superinterfaces_in_type_declaration = WrappingStyle.WRAP_WHEN_NEEDED;
}
/**
* Configuration for enum formatting.
*/
@ConfigSerializable
public static class Enums {
public boolean insert_space_before_opening_brace_in_enum_declaration = true;
public boolean insert_space_before_comma_in_enum_constant_arguments = false;
public boolean insert_space_after_comma_in_enum_constant_arguments = true;
public boolean insert_space_before_comma_in_enum_declarations = false;
public boolean insert_space_after_comma_in_enum_declarations = true;
public boolean insert_space_before_opening_paren_in_enum_constant = false;
public boolean insert_space_after_opening_paren_in_enum_constant = false;
public boolean insert_space_before_closing_paren_in_enum_constant = false;
public boolean indent_body_declarations_compare_to_enum_declaration_header = true;
public BracePosition brace_position_for_enum_declaration = BracePosition.SAME_LINE;
public WrappingStyle alignment_for_superinterfaces_in_enum_declaration = WrappingStyle.WRAP_WHEN_NEEDED;
public WrappingStyle alignment_for_enum_constants = WrappingStyle.WRAP_ALL;
}
/**
* Configuration for field formatting.
*/
@ConfigSerializable
public static class Fields {
public boolean align_type_members_on_columns = false;
}
/**
* Configuration for method formatting.
*/
@ConfigSerializable
public static class Methods {
public boolean insert_space_between_empty_parens_in_method_declaration = false;
public boolean insert_space_before_comma_in_method_invocation_arguments = false;
public boolean insert_space_after_comma_in_method_invocation_arguments = true;
public boolean insert_new_line_in_empty_method_body = false;
public boolean insert_space_before_comma_in_method_declaration_throws = false;
public boolean insert_space_after_comma_in_method_declaration_throws = true;
public boolean insert_space_before_comma_in_method_declaration_parameters = false;
public boolean insert_space_after_comma_in_method_declaration_parameters = true;
public boolean insert_space_before_opening_paren_in_method_declaration = false;
public boolean insert_space_before_closing_paren_in_method_declaration = false;
public boolean insert_space_before_opening_brace_in_method_declaration = true;
public BracePosition brace_position_for_method_declaration = BracePosition.SAME_LINE;
public WrappingStyle alignment_for_parameters_in_method_declaration = WrappingStyle.WRAP_WHEN_NEEDED;
}
/**
* Configuration for general statement formatting.
*/
@ConfigSerializable
public static class Misc {
public boolean new_lines_at_block_boundaries = true;
public boolean insert_space_after_unary_operator = false;
public boolean insert_space_before_binary_operator = true;
public boolean insert_space_after_binary_operator = true;
public boolean insert_space_after_lambda_arrow = true;
}
/**
* Configuration for array formatting.
*/
@ConfigSerializable
public static class Arrays {
public boolean insert_space_between_brackets_in_array_type_reference = false;
public boolean insert_space_after_opening_brace_in_array_initializer = false;
public boolean insert_new_line_before_closing_brace_in_array_initializer = false;
public WrappingStyle alignment_for_expressions_in_array_initializer = WrappingStyle.WRAP_WHEN_NEEDED;
public BracePosition brace_position_for_array_initializer = BracePosition.SAME_LINE;
public boolean insert_space_after_opening_bracket_in_array_allocation_expression = false;
public boolean insert_space_before_closing_bracket_in_array_allocation_expression = false;
public boolean insert_space_before_comma_in_array_initializer = false;
public boolean insert_space_after_comma_in_array_initializer = true;
public boolean insert_space_before_opening_bracket_in_array_type_reference = false;
public boolean insert_space_before_opening_bracket_in_array_reference = false;
public boolean insert_space_before_closing_bracket_in_array_reference = false;
}
/**
* Configuration for switch formatting.
*/
@ConfigSerializable
public static class Switches {
public boolean insert_space_after_opening_paren_in_switch = false;
public boolean insert_space_before_closing_paren_in_switch = false;
public boolean insert_space_before_colon_in_case = false;
public boolean insert_space_after_colon_in_case = false;
public boolean insert_space_before_opening_brace_in_switch = true;
public boolean indent_breaks_compare_to_cases = true;
public boolean indent_switchstatements_compare_to_switch = false;
public boolean indent_switchstatements_compare_to_cases = true;
public BracePosition brace_position_for_switch = BracePosition.SAME_LINE;
}
/**
* Configuration for loop formatting.
*/
@ConfigSerializable
public static class Loops {
public boolean insert_space_before_opening_paren_in_for = true;
public boolean insert_space_after_opening_paren_in_for = false;
public boolean insert_space_before_colon_in_for = true;
public boolean insert_space_after_colon_in_for = true;
public boolean insert_space_before_opening_paren_in_while = true;
public boolean insert_space_after_opening_paren_in_while = false;
public boolean insert_space_before_closing_paren_in_while = false;
}
/**
* Configuration for if formatting.
*/
@ConfigSerializable
public static class Ifs {
public boolean insert_space_before_opening_paren_in_if = true;
public boolean insert_space_after_opening_paren_in_if = false;
public boolean insert_space_before_closing_paren_in_if = false;
public boolean insert_new_line_before_else_in_if_statement = false;
}
/**
* Configuration for try catch formatting.
*/
@ConfigSerializable
public static class TryCatches {
public boolean insert_new_line_before_catch_in_try_statement = false;
}
/**
* Configuration for annotation formatting.
*/
@ConfigSerializable
public static class Annotations {
public boolean insert_space_before_closing_paren_in_annotation = false;
public boolean insert_new_line_after_annotation_on_type = true;
public boolean insert_new_line_after_annotation_on_parameter = false;
public boolean insert_new_line_after_annotation_on_package = true;
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/config/ConfigManager.java | src/main/java/org/spongepowered/despector/config/ConfigManager.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.config;
import ninja.leaping.configurate.ConfigurationOptions;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMapper;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* The manager for all configuration.
*/
public class ConfigManager {
private static final String HEADER = "Despector decompiler configuration:";
private static HoconConfigurationLoader loader;
private static CommentedConfigurationNode node;
private static ObjectMapper<ConfigBase>.BoundInstance configMapper;
private static ConfigBase config = null;
/**
* Gets the global configuration object.
*/
public static ConfigBase getConfig() {
if (config == null) {
config = new ConfigBase();
}
return config;
}
/**
* Loads the given configuration file.
*/
public static void load(Path path) {
System.out.println("Loading config from " + path.toString());
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
loader = HoconConfigurationLoader.builder().setPath(path).build();
configMapper = ObjectMapper.forClass(ConfigBase.class).bindToNew();
node = loader.load(ConfigurationOptions.defaults().setHeader(HEADER));
config = configMapper.populate(node);
configMapper.serialize(node);
loader.save(node);
} catch (Exception e) {
System.err.println("Error loading configuration:");
e.printStackTrace();
}
}
/**
* Saves the config back to disk to persist and changes made.
*/
public static void update() {
try {
configMapper.serialize(node);
loader.save(node);
} catch (Exception e) {
System.err.println("Error saving configuration:");
e.printStackTrace();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/Locals.java | src/main/java/org/spongepowered/despector/ast/Locals.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import com.google.common.collect.Lists;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.generic.MethodSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.type.MethodEntry;
import org.spongepowered.despector.util.SignatureParser;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A tracker of local variables.
*/
public class Locals {
private MethodEntry method;
private Local[] locals;
public Locals(MethodEntry method) {
this.locals = new Local[0];
this.method = method;
}
/**
* Creates a new {@link Locals} instance using the same locals as the given
* object.
*/
public Locals(Locals other) {
this.locals = new Local[other.locals.length];
for (int i = 0; i < other.locals.length; i++) {
this.locals[i] = other.locals[i];
}
this.method = other.method;
}
public int getLocalCount() {
return this.locals.length;
}
/**
* Gets the local variable at the given index.
*/
public Local getLocal(int i) {
if (i >= this.locals.length) {
int old = this.locals.length;
this.locals = Arrays.copyOf(this.locals, i + 1);
for (int o = old; o <= i; o++) {
this.locals[o] = new Local(this, o, this.method.isStatic());
}
}
return this.locals[i];
}
/**
* Bakes the local instances using the given label indices.
*
* @param methodSignature
*/
public void bakeInstances(MethodSignature methodSignature, List<Integer> label_indices) {
for (Local local : this.locals) {
local.bakeInstances(label_indices);
}
}
/**
* Gets a name for the variable that does not conflict with any other names.
*/
public String getNonConflictingName(String name, int index) {
int i = 1;
while (true) {
boolean conflict = false;
for (Local local : this.locals) {
LocalInstance insn = local.getInstance(index);
if (insn != null && insn.getName().equals(name)) {
conflict = true;
break;
}
}
if (!conflict) {
break;
}
name = name + (i++);
}
return name;
}
/**
* Fines a local from the given start point with the given type.
*/
public LocalInstance findLocal(int start, String type) {
for (Local local : this.locals) {
LocalInstance i = local.find(start, type);
if (i != null) {
return i;
}
}
return null;
}
public List<LocalInstance> getAllInstances() {
List<LocalInstance> res = new ArrayList<>();
for (Local loc : this.locals) {
res.addAll(loc.getInstances());
if (loc.getParameterInstance() != null) {
res.add(loc.getParameterInstance());
}
}
return res;
}
/**
* Writes this locals set to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startArray(this.locals.length);
for (Local loc : this.locals) {
pack.startMap(2);
pack.writeString("index").writeInt(loc.getIndex());
int sz = loc.getInstances().size();
if (loc.isParameter()) {
sz++;
}
pack.writeString("instances").startArray(sz);
for (LocalInstance insn : loc.getInstances()) {
insn.writeTo(pack);
}
if (loc.isParameter()) {
loc.getParameterInstance().writeTo(pack);
}
pack.endArray();
pack.endMap();
}
pack.endArray();
}
/**
* A helper object for a specific local.
*/
public static class Local {
private final Locals locals;
private final boolean is_static;
private final int index;
private LocalInstance parameter_instance = null;
private final List<LVT> lvt = Lists.newArrayList();
private final List<LocalInstance> instances = Lists.newArrayList();
public Local(Locals locals, int i, boolean is_static) {
this.locals = locals;
this.index = i;
this.is_static = is_static;
}
public int getIndex() {
return this.index;
}
public boolean isParameter() {
return this.parameter_instance != null;
}
public int getLVTCount() {
return this.lvt.size();
}
public LVT getLVTByIndex(int index) {
return this.lvt.get(index);
}
public void addLVT(int s, int l, String n, String d) {
this.lvt.add(new LVT(s, l, n, d));
}
public LVT getLVT(int s) {
for (LVT l : this.lvt) {
if (l.start_pc == s) {
return l;
}
}
throw new IllegalStateException();
}
/**
* Bakes the instances of this local.
*/
public void bakeInstances(List<Integer> label_indices) {
for (LVT l : this.lvt) {
int start = label_indices.indexOf(l.start_pc);
if (start == -1) {
start = 0;
}
int end = label_indices.indexOf(l.start_pc + l.length);
if (end == -1 && !label_indices.isEmpty()) {
end = label_indices.get(label_indices.size() - 1);
}
TypeSignature sig = null;
if (l.signature == null) {
sig = ClassTypeSignature.of(l.desc);
} else {
try {
sig = SignatureParser.parseFieldTypeSignature(l.signature);
} catch (Exception e) {
sig = ClassTypeSignature.of(l.desc);
}
}
LocalInstance insn = new LocalInstance(this, l.name, sig, start - 1, end);
if (this.index < this.locals.method.getParamTypes().size() + (this.is_static ? 0 : 1)) {
this.parameter_instance = insn;
} else {
this.instances.add(insn);
}
}
}
/**
* Gets the local instance for the given index.
*/
public LocalInstance getInstance(int index) {
for (LocalInstance insn : this.instances) {
if (index >= insn.getStart() - 1 && index <= insn.getEnd()) {
return insn;
}
}
if (this.parameter_instance != null) {
return this.parameter_instance;
}
// No LVT entry for this local!
String n = "param" + this.index;
if (!this.is_static && this.index == 0) {
n = "this";
}
if (index < this.locals.method.getParamTypes().size() + (this.is_static ? 0 : 1)) {
this.parameter_instance = new LocalInstance(this, n, null, -1, -1);
return this.parameter_instance;
}
LocalInstance insn = new LocalInstance(this, n, null, -1, Integer.MAX_VALUE);
this.instances.add(insn);
return insn;
}
/**
* Adds the given instance to this local.
*/
public void addInstance(LocalInstance insn) {
if (insn.getStart() == -1) {
this.parameter_instance = insn;
} else {
this.instances.add(insn);
}
}
public LocalInstance getParameterInstance() {
return this.parameter_instance;
}
public void setParameterInstance(LocalInstance insn) {
this.parameter_instance = insn;
}
/**
* Finds an instance for the given label and type.
*/
public LocalInstance find(int start, String type) {
if (start == -1 && this.parameter_instance != null) {
return this.parameter_instance;
}
for (LocalInstance local : this.instances) {
if (local.getStart() == start) {
if (local.getType() == null || (local.getType().getDescriptor().equals(type))) {
return local;
}
}
}
return null;
}
public List<LocalInstance> getInstances() {
return this.instances;
}
@Override
public String toString() {
return "Local" + this.index;
}
}
/**
* An instance of a local.
*/
public static class LocalInstance {
private final Local local;
private String name;
private TypeSignature type;
private int start;
private int end;
private boolean effectively_final = false;
private final List<Annotation> annotations = new ArrayList<>();
public LocalInstance(Local l, String n, TypeSignature t, int start, int end) {
this.local = l;
this.name = n;
this.type = t;
this.start = start;
this.end = end;
}
public Local getLocal() {
return this.local;
}
/**
* Gets the local index of this instance.
*/
public int getIndex() {
return this.local.getIndex();
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public TypeSignature getType() {
return this.type;
}
public String getTypeName() {
return this.type.getName();
}
public void setType(TypeSignature type) {
this.type = type;
}
public int getStart() {
return this.start;
}
public int getEnd() {
return this.end;
}
public boolean isEffectivelyFinal() {
return this.effectively_final;
}
public void setEffectivelyFinal(boolean state) {
this.effectively_final = state;
}
public List<Annotation> getAnnotations() {
return this.annotations;
}
/**
* Writes the simple form of this instance.
*/
public void writeToSimple(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("local").writeInt(this.local.getIndex());
pack.writeString("start").writeInt(this.start);
pack.writeString("type");
if (this.type != null) {
pack.writeString(this.type.getDescriptor());
} else {
pack.writeNil();
}
pack.endMap();
}
/**
* Writes the complete form of this instance.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(6);
pack.writeString("name").writeString(this.name);
pack.writeString("type");
if (this.type != null) {
this.type.writeTo(pack);
} else {
pack.writeNil();
}
pack.writeString("start").writeInt(this.start);
pack.writeString("end").writeInt(this.end);
pack.writeString("final").writeBool(this.effectively_final);
pack.writeString("annotations").startArray(this.annotations.size());
for (Annotation anno : this.annotations) {
anno.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
@Override
public String toString() {
return this.name != null ? this.name : this.local.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof LocalInstance)) {
return false;
}
LocalInstance l = (LocalInstance) o;
if (this.type != null && !this.type.equals(l.type)) {
return false;
}
return this.name.equals(l.name) && this.start == l.start && this.end == l.end;
}
}
public static class LVT {
public int start_pc;
public int length;
public String name;
public String desc;
public String signature;
public LVT(int s, int l, String n, String d) {
this.start_pc = s;
this.length = l;
this.name = n;
this.desc = d;
}
public void setSignature(String sig) {
this.signature = sig;
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/ClasspathSourceSet.java | src/main/java/org/spongepowered/despector/ast/ClasspathSourceSet.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import org.spongepowered.despector.ast.type.TypeEntry;
/**
* A sourceset for types which are part of libraries or core java types.
*/
public final class ClasspathSourceSet /* implements SourceSet */ {
// public static final SourceSet classpath = new ClasspathSourceSet();
/**
* The void type.
*/
public static final TypeEntry void_t = createPrimative("void");
/**
* The object type java/lang/Object.
*/
public static final TypeEntry object_t = createPrimative("java/lang/Object");
/**
* The primitive boolean type.
*/
public static final TypeEntry boolean_t = createPrimative("boolean");
/**
* The primitive byte type.
*/
public static final TypeEntry byte_t = createPrimative("byte");
/**
* The primitive char type.
*/
public static final TypeEntry char_t = createPrimative("char");
/**
* The primitive short type.
*/
public static final TypeEntry short_t = createPrimative("short");
/**
* The primitive int type.
*/
public static final TypeEntry int_t = createPrimative("int");
/**
* The primitive long type.
*/
public static final TypeEntry long_t = createPrimative("long");
/**
* The primitive float type.
*/
public static final TypeEntry float_t = createPrimative("float");
/**
* The primitive double type.
*/
public static final TypeEntry double_t = createPrimative("double");
/**
* The string type java/lang/String.
*/
public static final TypeEntry String = createPrimative("java/lang/String");
private static TypeEntry createPrimative(String name) {
return null;
}
// private final Set<String> failed_cache = Sets.newHashSet();
// private final Map<String, TypeEntry> cache = Maps.newHashMap();
// private final Map<String, ArrayTypeEntry> array_cache = Maps.newHashMap();
// private ClasspathSourceSet() {
//
// }
//
// private boolean checkFailed(String name) {
// if (name.endsWith("[]")) {
// return checkFailed(name.substring(0, name.length() - 2));
// }
// return this.failed_cache.contains(name);
// }
//
// private TypeEntry find(String name) {
// if (name.endsWith("[]")) {
// ArrayTypeEntry array = this.array_cache.get(name);
// if (array == null) {
// TypeEntry comp = find(name.substring(0, name.length() - 2));
// array = new ArrayTypeEntry(this, comp);
// this.array_cache.put(name, array);
// }
// return array;
// }
// TypeEntry entry = this.cache.get(name);
// if (entry != null) {
// return entry;
// }
// Class<?> type = TypeHelper.classForTypeName(name);
// if (Enum.class.isAssignableFrom(type)) {
// entry = new EnumEntry(this, type);
// } else if (type.isInterface()) {
// entry = new InterfaceEntry(this, type);
// } else {
// entry = new ClassEntry(this, type);
// }
// this.cache.put(name, entry);
// return entry;
// }
//
// @Override
// public TypeEntry get(String name) {
// if (checkFailed(name)) {
// throw new IllegalArgumentException("Unknown classpath type: " + name);
// }
// return find(name);
// }
//
// @Override
// public TypeEntry getIfExists(String name) {
// return get(name);
// }
//
// @Override
// public EnumEntry getEnum(String name) {
// TypeEntry entry = get(name);
// if (!(entry instanceof EnumEntry)) {
// throw new IllegalArgumentException("Type: " + name + " is not an enum type");
// }
// return (EnumEntry) entry;
// }
//
// @Override
// public InterfaceEntry getInterface(String name) {
// TypeEntry entry = get(name);
// if (!(entry instanceof InterfaceEntry)) {
// throw new IllegalArgumentException("Type: " + name + " is not an interface type");
// }
// return (InterfaceEntry) entry;
// }
//
// @Override
// public MappingsSet getMappings() {
// throw new UnsupportedOperationException("Classpath source set has no mappings");
// }
//
// @Override
// public MappingsSet getValidationMappings() {
// throw new UnsupportedOperationException("Classpath source set has no mappings");
// }
//
// @Override
// public boolean hasValidationMappings() {
// throw new UnsupportedOperationException("Classpath source set has no mappings");
// }
//
// @Override
// public ConflictHandler getConflictHandler() {
// // classpath entries shouldn't conflict by definition so we'll just
// // throw an error for the bad case that they do
// return ConflictHandler.ERROR;
// }
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/AstVisitor.java | src/main/java/org/spongepowered/despector/ast/AstVisitor.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
public interface AstVisitor {
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/package-info.java | src/main/java/org/spongepowered/despector/ast/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/SourceSet.java | src/main/java/org/spongepowered/despector/ast/SourceSet.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.type.EnumEntry;
import org.spongepowered.despector.ast.type.InterfaceEntry;
import org.spongepowered.despector.ast.type.TypeEntry;
import org.spongepowered.despector.decompiler.Decompilers;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* A source set for types which are part of the obfuscated source being mapped.
*/
public class SourceSet {
private Loader loader;
private final Set<String> load_failed_cache = new HashSet<>();
private final Map<String, TypeEntry> classes = new HashMap<>();
private final Map<String, EnumEntry> enums = new HashMap<>();
private final Map<String, InterfaceEntry> interfaces = new HashMap<>();
private final Map<String, AnnotationType> annotations = new HashMap<>();
public SourceSet() {
}
public Loader getLoader() {
return this.loader;
}
public void setLoader(Loader loader) {
this.loader = loader;
}
/**
* Inserts the given type into this source set.
*/
public void add(TypeEntry e) {
checkNotNull(e);
if (e instanceof EnumEntry) {
this.enums.put(e.getName(), (EnumEntry) e);
} else if (e instanceof InterfaceEntry) {
this.interfaces.put(e.getName(), (InterfaceEntry) e);
}
this.classes.put(e.getName(), e);
}
/**
* Gets the type with the given internal name.
*/
public TypeEntry get(String name) {
checkNotNull(name);
if (name.endsWith(";") || name.startsWith("[") || (name.length() == 1 && "BSIJFDCZ".indexOf(name.charAt(0)) != -1)) {
throw new IllegalStateException(name + " is a descriptor not a type name");
}
if (name.endsWith("[]")) {
return get(name.substring(0, name.length() - 2));
}
TypeEntry entry = this.classes.get(name);
if (entry == null && this.loader != null && !this.load_failed_cache.contains(name)) {
InputStream data = this.loader.find(name);
if (data == null) {
this.load_failed_cache.add(name);
return null;
}
try {
entry = Decompilers.get(Language.ANY).decompile(data, this);
} catch (IOException e) {
e.printStackTrace();
this.load_failed_cache.add(name);
return null;
}
add(entry);
}
return entry;
}
public EnumEntry getEnum(String name) {
EnumEntry entry = this.enums.get(name);
return entry;
}
public InterfaceEntry getInterface(String name) {
InterfaceEntry entry = this.interfaces.get(name);
return entry;
}
/**
* Gets all classes in the source set. This also includes all interfaces and
* enums.
*/
public Collection<TypeEntry> getAllClasses() {
return this.classes.values();
}
/**
* Gets all enum types in the source set.
*/
public Collection<EnumEntry> getAllEnums() {
return this.enums.values();
}
/**
* Gets all interface types in the source set.
*/
public Collection<InterfaceEntry> getAllInterfaces() {
return this.interfaces.values();
}
public void addAnnotation(AnnotationType anno) {
this.annotations.put(anno.getName(), anno);
}
/**
* Gets the annotation type with the given internal name.
*/
public AnnotationType getAnnotationType(String name) {
AnnotationType anno = this.annotations.get(name);
if (anno == null) {
anno = new AnnotationType(name);
this.annotations.put(name, anno);
}
return anno;
}
public Collection<AnnotationType> getAllAnnotations() {
return this.annotations.values();
}
public void accept(AstVisitor visitor) {
for (TypeEntry type : this.classes.values()) {
type.accept(visitor);
}
}
/**
* Writes this source set to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(2);
pack.writeString("version").writeInt(AstSerializer.VERSION);
pack.writeString("classes");
pack.startArray(this.classes.size());
for (TypeEntry type : this.classes.values()) {
type.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
/**
* A loader which from which new types can be requested on demand.
*/
public static interface Loader {
InputStream find(String name);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/Annotation.java | src/main/java/org/spongepowered/despector/ast/Annotation.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.type.TypeVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* An instance of an annotation on a member.
*/
public class Annotation {
private static final Set<Class<?>> VALID_TYPES = new HashSet<>();
static {
VALID_TYPES.add(String.class);
VALID_TYPES.add(ClassTypeSignature.class);
VALID_TYPES.add(ArrayList.class);
VALID_TYPES.add(Annotation.class);
VALID_TYPES.add(EnumConstant.class);
VALID_TYPES.add(Boolean.class);
VALID_TYPES.add(Byte.class);
VALID_TYPES.add(Short.class);
VALID_TYPES.add(Integer.class);
VALID_TYPES.add(Long.class);
VALID_TYPES.add(Float.class);
VALID_TYPES.add(Double.class);
VALID_TYPES.add(Character.class);
}
/**
* Gets if the given class is a valid annotation value type.
*/
public static boolean isValidValue(Class<?> type) {
if (type.isPrimitive() || VALID_TYPES.contains(type)) {
return true;
}
if (type.isArray()) {
return isValidValue(type.getComponentType());
}
return false;
}
private final AnnotationType type;
private final Map<String, Object> values = new LinkedHashMap<>();
public Annotation(AnnotationType type) {
this.type = checkNotNull(type, "type");
}
/**
* Gets the type of this annotation.
*/
public AnnotationType getType() {
return this.type;
}
/**
* Sets the given key value pair in this annotation.
*/
public void setValue(String key, Object value) {
Class<?> expected = this.type.getType(key);
if (this.type.isComplete()) {
checkNotNull(expected, "No matching type for key " + key);
checkArgument(expected.isInstance(value), "Annotation value was not of proper type, expected " + expected.getName());
} else if (expected != null) {
checkArgument(expected.isInstance(value), "Annotation value was not of proper type, expected " + expected.getName());
} else {
this.type.setType(key, value.getClass());
}
this.values.put(key, value);
}
/**
* Gets the value of the given field.
*/
@SuppressWarnings("unchecked")
public <T> T getValue(String key) {
return (T) this.values.get(key);
}
public Map<String, Object> getValues() {
return this.values;
}
/**
* Gets all valid fields in this annotation.
*/
public Set<String> getKeys() {
return this.values.keySet();
}
private void writeObj(Object o, MessagePacker pack) throws IOException {
pack.startMap(2);
pack.writeString("typename").writeString(o.getClass().getName());
pack.writeString("value");
if (o instanceof Integer) {
pack.writeInt(((Integer) o).intValue());
} else if (o instanceof Byte) {
pack.writeInt(((Byte) o).byteValue());
} else if (o instanceof Short) {
pack.writeInt(((Short) o).shortValue());
} else if (o instanceof Character) {
pack.writeUnsignedInt((char) o);
} else if (o instanceof Long) {
pack.writeInt(((Long) o).longValue());
} else if (o instanceof Float) {
pack.writeFloat(((Float) o).floatValue());
} else if (o instanceof Double) {
pack.writeDouble(((Double) o).doubleValue());
} else if (o instanceof String) {
pack.writeString(((String) o));
} else if (o instanceof ArrayList) {
List<?> lst = (List<?>) o;
pack.startArray(lst.size());
for (Object obj : lst) {
writeObj(obj, pack);
}
pack.endArray();
} else if (o instanceof ClassTypeSignature) {
((ClassTypeSignature) o).writeTo(pack);
} else if (o instanceof Annotation) {
((Annotation) o).writeTo(pack);
} else if (o instanceof EnumConstant) {
pack.startMap(2);
EnumConstant e = (EnumConstant) o;
pack.writeString("enumtype").writeString(e.getEnumType());
pack.writeString("constant").writeString(e.getConstantName());
pack.endMap();
} else {
throw new IllegalStateException("Cannot pack " + o.getClass().getSimpleName());
}
pack.endMap();
}
/**
* Writes this annotation to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.ENTRY_ID_ANNOTATION);
pack.writeString("typename").writeString(this.type.getName());
pack.writeString("runtime").writeBool(this.type.isRuntimeVisible());
pack.writeString("values").startArray(this.values.size());
for (String key : this.values.keySet()) {
pack.startMap(4);
pack.writeString("name").writeString(key);
pack.writeString("type").writeString(this.type.getType(key).getName());
pack.writeString("default");
writeObj(this.type.getDefaultValue(key), pack);
pack.writeString("value");
writeObj(this.values.get(key), pack);
pack.endMap();
}
pack.endArray();
pack.endMap();
}
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitAnnotation(this);
}
}
public static class EnumConstant {
private final String type_name;
private final String constant;
public EnumConstant(String type, String cst) {
this.type_name = type;
this.constant = cst;
}
public String getEnumType() {
return this.type_name;
}
public String getConstantName() {
return this.constant;
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/AstEntry.java | src/main/java/org/spongepowered/despector/ast/AstEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* The base of any element in the AST.
*/
public abstract class AstEntry {
protected final SourceSet source;
protected AstEntry(SourceSet source) {
this.source = source;
}
/**
* Gets the source set that this ast entry belongs to.
*/
public SourceSet getSource() {
return this.source;
}
/**
* Writes this ast element to the given {@link MessagePacker}.
*/
public abstract void writeTo(MessagePacker pack) throws IOException;
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/AnnotationType.java | src/main/java/org/spongepowered/despector/ast/AnnotationType.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.HashMap;
import java.util.Map;
/**
* An anotation type.
*/
public class AnnotationType {
private final String name;
private final Map<String, Class<?>> types = new HashMap<>();
private final Map<String, Object> defaults = new HashMap<>();
private boolean runtime;
private boolean complete;
public AnnotationType(String name) {
this.name = checkNotNull(name, "name");
}
/**
* Gets the type descriptor.
*/
public String getName() {
return this.name;
}
/**
* Gets the type of the given annotation field.
*/
public Class<?> getType(String key) {
return this.types.get(key);
}
/**
* Sets the type of the given annotation field.
*/
public void setType(String key, Class<?> type) {
checkArgument(Annotation.isValidValue(type), "Type " + type.getName() + " is not a valid annotation value type");
checkState(!this.complete);
this.types.put(key, type);
}
/**
* Gets the default value of the given field.
*/
public Object getDefaultValue(String key) {
return this.defaults.get(key);
}
/**
* Sets the default value of the given field.
*/
public void setDefault(String key, Object value) {
checkNotNull(this.types.get(key), "Cannot set default value before type");
checkArgument(this.types.get(key).isInstance(value), "Value does not match type for annotation key");
this.defaults.put(key, value);
}
/**
* Gets if this annotation type is complete.
*/
public boolean isComplete() {
return this.complete;
}
/**
* Marks if this annotation type is complete.
*/
public void markComplete() {
this.complete = true;
}
/**
* Gets if this annotation is visible at runtime.
*/
public boolean isRuntimeVisible() {
return this.runtime;
}
/**
* Sets if this annotation is visible at runtime.
*/
public void setRuntimeVisible(boolean state) {
this.runtime = state;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof AnnotationType)) {
return false;
}
AnnotationType c = (AnnotationType) o;
return this.runtime == c.runtime && this.name.equals(c.name) && this.defaults.equals(c.defaults) && this.types.equals(c.types);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/AccessModifier.java | src/main/java/org/spongepowered/despector/ast/AccessModifier.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast;
import org.objectweb.asm.Opcodes;
import org.spongepowered.despector.decompiler.BaseDecompiler;
/**
* Represents the access modifier of a class member.
*/
public enum AccessModifier {
PUBLIC("public"),
PROTECTED("protected"),
PACKAGE_PRIVATE(""),
PRIVATE("private");
private final String ident;
AccessModifier(String ident) {
this.ident = ident;
}
/**
* Gets the string representation of this access modifier.
*/
public String asString() {
return this.ident;
}
/**
* Gets the access modifier from the given flags. See
* {@link Opcodes#ACC_PUBLIC}, {@link Opcodes#ACC_PROTECTED},
* {@link Opcodes#ACC_PRIVATE}. A flag with none of these set will be marked
* as {@link #PACKAGE_PRIVATE}.
*/
public static AccessModifier fromModifiers(int access) {
if ((access & BaseDecompiler.ACC_PUBLIC) != 0) {
return PUBLIC;
} else if ((access & BaseDecompiler.ACC_PROTECTED) != 0) {
return PROTECTED;
} else if ((access & BaseDecompiler.ACC_PRIVATE) != 0) {
return PRIVATE;
}
return PACKAGE_PRIVATE;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/TypeVisitor.java | src/main/java/org/spongepowered/despector/ast/type/TypeVisitor.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AstVisitor;
public interface TypeVisitor extends AstVisitor {
void visitClassEntry(ClassEntry type);
void visitEnumEntry(EnumEntry type);
void visitInterfaceEntry(InterfaceEntry type);
void visitAnnotationEntry(AnnotationEntry type);
void visitAnnotation(Annotation annotation);
void visitMethod(MethodEntry mth);
void visitMethodEnd();
void visitField(FieldEntry fld);
void visitTypeEnd();
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/InterfaceEntry.java | src/main/java/org/spongepowered/despector/ast/type/InterfaceEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* Represents an interface type.
*/
public class InterfaceEntry extends TypeEntry {
public InterfaceEntry(SourceSet src, Language lang, String name) {
super(src, lang, name);
}
@Override
public String toString() {
return "Interface " + this.name;
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
super.writeTo(pack, 0, AstSerializer.ENTRY_ID_INTERFACE);
pack.endMap();
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitInterfaceEntry(this);
}
for (FieldEntry field : this.fields.values()) {
field.accept(visitor);
}
for (FieldEntry field : this.static_fields.values()) {
field.accept(visitor);
}
for (MethodEntry method : this.methods.values()) {
method.accept(visitor);
}
for (MethodEntry method : this.static_methods.values()) {
method.accept(visitor);
}
for (Annotation anno : this.annotations.values()) {
anno.accept(visitor);
}
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitTypeEnd();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/MethodEntry.java | src/main/java/org/spongepowered/despector/ast/type/MethodEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AccessModifier;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AnnotationType;
import org.spongepowered.despector.ast.AstEntry;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.Locals;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.ast.generic.MethodSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.StatementBlock;
import org.spongepowered.despector.decompiler.ir.InsnBlock;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a method declaration in a type.
*
* <p>Only methods which actually have method bodies are present in a type, not
* inherited types from super classes or super interfaces.</p>
*
* <p>The exceptions is obviously interfaces which will contain methods which
* are declared as well as default methods. But still no inherited methods.</p>
*/
public class MethodEntry extends AstEntry {
protected AccessModifier access = AccessModifier.PACKAGE_PRIVATE;
protected String owner;
protected String name;
protected String desc;
protected boolean is_abstract;
protected boolean is_final;
protected boolean is_static;
protected boolean is_synthetic;
protected boolean is_bridge;
protected boolean is_synchronized;
protected boolean is_native;
protected boolean is_varargs;
protected boolean is_strictfp;
protected boolean is_deprecated;
protected InsnBlock ir;
public String[] block_debug = new String[3];
protected Locals locals;
protected StatementBlock instructions = null;
protected MethodSignature sig;
protected Object annotation_value = null;
protected final Map<AnnotationType, Annotation> annotations = new LinkedHashMap<>();
public MethodEntry(SourceSet source) {
super(source);
}
public AccessModifier getAccessModifier() {
return this.access;
}
public void setAccessModifier(AccessModifier access) {
this.access = checkNotNull(access, "AccessModifier");
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
/**
* Gets the type containing this method.
*/
public String getOwnerName() {
return this.owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getDescription() {
return this.desc;
}
public void setDescription(String desc) {
this.desc = checkNotNull(desc, "desc");
}
public boolean isAbstract() {
return this.is_abstract;
}
public void setAbstract(boolean state) {
this.is_abstract = state;
}
public boolean isFinal() {
return this.is_final;
}
public void setFinal(boolean state) {
this.is_final = state;
}
/**
* Gets if this method is static.
*/
public boolean isStatic() {
return this.is_static;
}
public void setStatic(boolean state) {
this.is_static = state;
}
public boolean isSynthetic() {
return this.is_synthetic;
}
public void setSynthetic(boolean state) {
this.is_synthetic = state;
}
public boolean isBridge() {
return this.is_bridge;
}
public void setBridge(boolean state) {
this.is_bridge = state;
}
public boolean isSynchronized() {
return this.is_synchronized;
}
public void setSynchronized(boolean state) {
this.is_synchronized = state;
}
public boolean isNative() {
return this.is_native;
}
public void setNative(boolean state) {
this.is_native = state;
}
public boolean isVarargs() {
return this.is_varargs;
}
public void setVarargs(boolean state) {
this.is_varargs = state;
}
public boolean isStrictFp() {
return this.is_strictfp;
}
public void setStrictFp(boolean state) {
this.is_strictfp = state;
}
public boolean isDeprecated() {
return this.is_deprecated;
}
public void setDeprecated(boolean state) {
this.is_deprecated = state;
}
/**
* Gets the return type of this method. Will never be null but may represent
* void.
*/
public TypeSignature getReturnType() {
return this.sig.getReturnType();
}
public String getReturnTypeName() {
return this.sig.getReturnType().getName();
}
/**
* Gets the type entries of this methods parameters.
*/
public List<TypeSignature> getParamTypes() {
return this.sig.getParameters();
}
public MethodSignature getMethodSignature() {
return this.sig;
}
public void setMethodSignature(MethodSignature sig) {
this.sig = sig;
}
public Locals getLocals() {
return this.locals;
}
public void setLocals(Locals locals) {
this.locals = locals;
}
/**
* Gets the statements of this method.
*/
public StatementBlock getInstructions() {
if (this.is_abstract) {
return null;
}
return this.instructions;
}
/**
* Sets the statements of this method.
*/
public void setInstructions(StatementBlock block) {
this.instructions = block;
}
public InsnBlock getIR() {
return this.ir;
}
public void setIR(InsnBlock block) {
this.ir = block;
}
public Annotation getAnnotation(AnnotationType type) {
return this.annotations.get(type);
}
public Collection<Annotation> getAnnotations() {
return this.annotations.values();
}
public void addAnnotation(Annotation anno) {
this.annotations.put(anno.getType(), anno);
}
public Object getAnnotationValue() {
return this.annotation_value;
}
public void setAnnotationValue(Object val) {
this.annotation_value = val;
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(18);
pack.writeString("id").writeInt(AstSerializer.ENTRY_ID_METHOD);
pack.writeString("access").writeInt(this.access.ordinal());
pack.writeString("owner").writeString(this.owner);
pack.writeString("name").writeString(this.name);
pack.writeString("description").writeString(this.desc);
pack.writeString("abstract").writeBool(this.is_abstract);
pack.writeString("final").writeBool(this.is_final);
pack.writeString("static").writeBool(this.is_static);
pack.writeString("synthetic").writeBool(this.is_synthetic);
pack.writeString("bridge").writeBool(this.is_bridge);
pack.writeString("varargs").writeBool(this.is_varargs);
pack.writeString("strictfp").writeBool(this.is_strictfp);
pack.writeString("synchronized").writeBool(this.is_synchronized);
pack.writeString("native").writeBool(this.is_native);
pack.writeString("methodsignature");
this.sig.writeTo(pack);
pack.writeString("locals");
this.locals.writeTo(pack);
pack.writeString("instructions");
if (this.instructions != null) {
pack.startArray(this.instructions.getStatementCount());
for (Statement stmt : this.instructions.getStatements()) {
stmt.writeTo(pack);
}
pack.endArray();
} else {
pack.writeNil();
}
pack.writeString("annotations").startArray(this.annotations.size());
for (Annotation anno : this.annotations.values()) {
anno.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitMethod(this);
}
if (this.instructions != null) {
this.instructions.accept(visitor);
}
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitMethodEnd();
}
}
@Override
public String toString() {
return "Method: " + this.name + " " + this.sig;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/package-info.java | src/main/java/org/spongepowered/despector/ast/type/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.type;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/ClassEntry.java | src/main/java/org/spongepowered/despector/ast/type/ClassEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.util.TypeHelper;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* Represents a class type.
*/
public class ClassEntry extends TypeEntry {
protected String superclass = null;
public ClassEntry(SourceSet src, Language lang, String name) {
super(src, lang, name);
}
/**
* Gets the super class of this type.
*/
public String getSuperclass() {
return this.superclass;
}
/**
* Gets the name of the superclass of this type.
*/
public String getSuperclassName() {
return TypeHelper.descToType(this.superclass);
}
/**
* Sets the super class of this entry.
*/
public void setSuperclass(String c) {
this.superclass = c;
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
super.writeTo(pack, 1, AstSerializer.ENTRY_ID_CLASS);
pack.writeString("supername").writeString(this.superclass);
pack.endMap();
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitClassEntry(this);
}
for (FieldEntry field : this.fields.values()) {
field.accept(visitor);
}
for (FieldEntry field : this.static_fields.values()) {
field.accept(visitor);
}
for (MethodEntry method : this.methods.values()) {
method.accept(visitor);
}
for (MethodEntry method : this.static_methods.values()) {
method.accept(visitor);
}
for (Annotation anno : this.annotations.values()) {
anno.accept(visitor);
}
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitTypeEnd();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/TypeEntry.java | src/main/java/org/spongepowered/despector/ast/type/TypeEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.AccessModifier;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AnnotationType;
import org.spongepowered.despector.ast.AstEntry;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.ast.generic.ClassSignature;
import org.spongepowered.despector.decompiler.BaseDecompiler;
import org.spongepowered.despector.util.TypeHelper;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a type, may be a class, interface, or enum.
*/
public abstract class TypeEntry extends AstEntry {
protected Language lang;
protected AccessModifier access;
protected boolean is_synthetic;
protected boolean is_final;
protected boolean is_abstract;
protected boolean is_deprecated;
protected boolean is_inner_class;
protected final String name;
protected final List<String> interfaces = new ArrayList<>();
protected final Map<String, FieldEntry> static_fields = new LinkedHashMap<>();
protected final Multimap<String, MethodEntry> static_methods = LinkedHashMultimap.create();
protected final Map<String, FieldEntry> fields = new LinkedHashMap<>();
protected final Multimap<String, MethodEntry> methods = LinkedHashMultimap.create();
protected final Map<AnnotationType, Annotation> annotations = new LinkedHashMap<>();
protected final Map<String, InnerClassInfo> inner_classes = new LinkedHashMap<>();
protected ClassSignature signature;
public TypeEntry(SourceSet source, Language lang, String name) {
super(source);
this.name = checkNotNull(name, "name");
checkArgument(lang != Language.ANY, "Type language cannot be set to any");
this.lang = lang;
this.is_inner_class = name.contains("$");
}
public Language getLanguage() {
return this.lang;
}
public void setLanguage(Language lang) {
this.lang = lang;
}
public AccessModifier getAccessModifier() {
return this.access;
}
public void setAccessModifier(AccessModifier access) {
this.access = checkNotNull(access, "AccessModifier");
}
public boolean isFinal() {
return this.is_final;
}
public void setFinal(boolean state) {
this.is_final = state;
}
/**
* Gets if this type is synthetic.
*/
public boolean isSynthetic() {
return this.is_synthetic;
}
/**
* Sets if this type is synthetic.
*/
public void setSynthetic(boolean state) {
this.is_synthetic = state;
}
public boolean isAbstract() {
return this.is_abstract;
}
public void setAbstract(boolean state) {
this.is_abstract = state;
}
public boolean isDeprecated() {
return this.is_deprecated;
}
public void setDeprecated(boolean state) {
this.is_deprecated = state;
}
/**
* Gets if this type is an inner class of another type.
*/
public boolean isInnerClass() {
return this.is_inner_class;
}
/**
* Gets the type internal name.
*/
public String getName() {
return this.name;
}
/**
* Gets the type descriptor.
*/
public String getDescriptor() {
return "L" + this.name + ";";
}
public ClassSignature getSignature() {
return this.signature;
}
public void setSignature(ClassSignature signature) {
this.signature = checkNotNull(signature, "signature");
}
/**
* Gets if this is an anonymous type.
*/
public boolean isAnonType() {
return TypeHelper.isAnonClass(this.name);
}
/**
* Gets all interfaces that this type implements.
*/
public List<String> getInterfaces() {
return this.interfaces;
}
/**
* Adds an interface for this type. Can only be used pre lock.
*/
public void addInterface(String inter) {
checkNotNull(inter);
this.interfaces.add(inter);
}
protected MethodEntry findMethod(String name, Multimap<String, MethodEntry> map) {
MethodEntry ret = null;
for (MethodEntry m : map.values()) {
if (m.getName().equals(name)) {
if (ret != null) {
throw new IllegalStateException("Tried to get ambiguous method " + name);
}
ret = m;
}
}
return ret;
}
protected MethodEntry findMethod(String name, String sig, Multimap<String, MethodEntry> map) {
for (MethodEntry m : map.values()) {
if (m.getName().equals(name) && m.getDescription().equals(sig)) {
return m;
}
}
return null;
}
/**
* Gets a static method with the given obfuscated name. If there are
* multiple methods defined with the same name then an exception may be
* thrown.
*/
public MethodEntry getStaticMethod(String name) {
checkNotNull(name);
return findMethod(name, this.static_methods);
}
/**
* Gets a static method with the given obfuscated name and signature.
*/
public MethodEntry getStaticMethod(String name, String sig) {
checkNotNull(name);
return findMethod(name, sig, this.static_methods);
}
/**
* Gets an instance method with the given name. If there are multiple
* instance methods with the same name then an exception may be thrown.
*/
public MethodEntry getMethod(String name) {
checkNotNull(name);
return findMethod(name, this.methods);
}
/**
* Gets the method with the given name and signature from this type, or null
* if not found.
*/
public MethodEntry getMethod(String name, String sig) {
checkNotNull(name);
checkNotNull(sig);
return findMethod(name, sig, this.methods);
}
/**
* Adds the given method to this type.
*/
public void addMethod(MethodEntry m) {
checkNotNull(m);
if (m.isStatic()) {
MethodEntry existing = getStaticMethod(m.getName(), m.getDescription());
if (existing != null) {
throw new IllegalArgumentException("Duplicate method " + existing);
}
this.static_methods.put(m.getName(), m);
} else {
MethodEntry existing = getMethod(m.getName(), m.getDescription());
if (existing != null) {
throw new IllegalArgumentException("Duplicate method " + existing);
}
this.methods.put(m.getName(), m);
}
}
public int getMethodCount() {
return this.methods.size();
}
public int getStaticMethodCount() {
return this.static_methods.size();
}
public Collection<MethodEntry> getMethods() {
return this.methods.values();
}
public Collection<MethodEntry> getStaticMethods() {
return this.static_methods.values();
}
/**
* Gets the static field with the given obfuscated name. If the field is not
* found then an {@link IllegalStateException} is thrown.
*/
public FieldEntry getStaticField(String name) {
checkNotNull(name);
return this.static_fields.get(name);
}
/**
* Gets the field with the given obfuscated name. If the field is not found
* then an {@link IllegalStateException} is thrown.
*/
public FieldEntry getField(String name) {
checkNotNull(name);
return this.fields.get(name);
}
/**
* Adds the given field entry to this type.
*/
public void addField(FieldEntry f) {
checkNotNull(f);
if (f.isStatic()) {
FieldEntry existing = this.static_fields.get(f.getName());
if (existing != null) {
throw new IllegalArgumentException("Duplicate static field " + f.getName());
}
this.static_fields.put(f.getName(), f);
} else {
FieldEntry existing = this.fields.get(f.getName());
if (existing != null) {
throw new IllegalArgumentException("Duplicate field " + f.getName());
}
this.fields.put(f.getName(), f);
}
}
public int getFieldCount() {
return this.fields.size();
}
public int getStaticFieldCount() {
return this.static_fields.size();
}
public Collection<FieldEntry> getFields() {
return this.fields.values();
}
public Collection<FieldEntry> getStaticFields() {
return this.static_fields.values();
}
public Annotation getAnnotation(AnnotationType type) {
return this.annotations.get(type);
}
public Collection<Annotation> getAnnotations() {
return this.annotations.values();
}
public void addAnnotation(Annotation anno) {
this.annotations.put(anno.getType(), anno);
}
public InnerClassInfo getInnerClassInfo(String name) {
return this.inner_classes.get(name);
}
public Collection<InnerClassInfo> getInnerClasses() {
return this.inner_classes.values();
}
public void addInnerClass(String name, String simple, String outer, int acc) {
this.inner_classes.put(name, new InnerClassInfo(name, simple, outer, acc));
}
public abstract void accept(AstVisitor visitor);
@Override
public String toString() {
return "Class " + this.name;
}
/**
* Writes this type to the givem {@link MessagePacker}. Takes an argument
* for how much extra space in the map to reserve for the subtypes values.
*/
public void writeTo(MessagePacker pack, int extra, int id) throws IOException {
pack.startMap(14 + extra);
pack.writeString("id").writeInt(id);
pack.writeString("language").writeInt(this.lang.ordinal());
pack.writeString("name").writeString(this.name);
pack.writeString("access").writeInt(this.access.ordinal());
pack.writeString("synthetic").writeBool(this.is_synthetic);
pack.writeString("final").writeBool(this.is_final);
pack.writeString("interfaces").startArray(this.interfaces.size());
for (String inter : this.interfaces) {
pack.writeString(inter);
}
pack.endArray();
pack.writeString("staticfields").startArray(this.static_fields.size());
for (FieldEntry fld : this.static_fields.values()) {
fld.writeTo(pack);
}
pack.endArray();
pack.writeString("fields").startArray(this.fields.size());
for (FieldEntry fld : this.fields.values()) {
fld.writeTo(pack);
}
pack.endArray();
pack.writeString("staticmethods").startArray(this.static_methods.size());
for (MethodEntry mth : this.static_methods.values()) {
mth.writeTo(pack);
}
pack.endArray();
pack.writeString("methods").startArray(this.methods.size());
for (MethodEntry mth : this.methods.values()) {
mth.writeTo(pack);
}
pack.endArray();
pack.writeString("signature");
this.signature.writeTo(pack);
pack.writeString("annotations").startArray(this.annotations.size());
for (Annotation anno : this.annotations.values()) {
anno.writeTo(pack);
}
pack.endArray();
pack.writeString("inner_classes").startArray(this.inner_classes.size());
for (InnerClassInfo info : this.inner_classes.values()) {
info.writeTo(pack);
}
pack.endArray();
}
/**
* Info for all inner classes of this type.
*/
public static class InnerClassInfo {
private String name;
private String simple_name;
private String outer_name;
private boolean is_static;
private AccessModifier access;
private boolean is_final;
private boolean is_abstract;
private boolean is_synthetic;
public InnerClassInfo(String name, String simple, String outer, int acc) {
this.name = checkNotNull(name, "name");
this.simple_name = simple;
this.outer_name = outer;
this.is_static = (acc & BaseDecompiler.ACC_STATIC) != 0;
this.is_final = (acc & BaseDecompiler.ACC_FINAL) != 0;
this.is_abstract = (acc & BaseDecompiler.ACC_ABSTRACT) != 0;
this.is_synthetic = (acc & BaseDecompiler.ACC_SYNTHETIC) != 0;
this.access = AccessModifier.fromModifiers(acc);
}
/**
* Writes this inner class info to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(8);
pack.writeString("name").writeString(this.name);
pack.writeString("simple_name");
if (this.simple_name == null) {
pack.writeNil();
} else {
pack.writeString(this.simple_name);
}
pack.writeString("outer_name");
if (this.outer_name == null) {
pack.writeNil();
} else {
pack.writeString(this.outer_name);
}
pack.writeString("static").writeBool(this.is_static);
pack.writeString("final").writeBool(this.is_final);
pack.writeString("abstract").writeBool(this.is_abstract);
pack.writeString("synthetic").writeBool(this.is_synthetic);
pack.writeString("access").writeInt(this.access.ordinal());
pack.endMap();
}
public String getName() {
return this.name;
}
public String getSimpleName() {
return this.simple_name;
}
public String getOuterName() {
return this.outer_name;
}
public AccessModifier getAccessModifier() {
return this.access;
}
public boolean isStatic() {
return this.is_static;
}
public boolean isFinal() {
return this.is_final;
}
public boolean isAbstract() {
return this.is_abstract;
}
public boolean isSynthetic() {
return this.is_synthetic;
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.name.hashCode();
h = h * 37 + this.simple_name.hashCode();
h = h * 37 + this.outer_name.hashCode();
h = h * 37 + this.access.ordinal();
h = h * 37 + (this.is_abstract ? 1 : 0);
h = h * 37 + (this.is_final ? 1 : 0);
h = h * 37 + (this.is_static ? 1 : 0);
h = h * 37 + (this.is_synthetic ? 1 : 0);
return h;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof InnerClassInfo)) {
return false;
}
InnerClassInfo i = (InnerClassInfo) o;
return this.name.equals(i.name) && this.simple_name.equals(i.simple_name) && this.outer_name.equals(i.outer_name)
&& this.is_abstract == i.is_abstract && this.is_final == i.is_final && this.is_static == i.is_static
&& this.is_synthetic == i.is_synthetic && this.access == i.access;
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/EnumEntry.java | src/main/java/org/spongepowered/despector/ast/type/EnumEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Lists;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.List;
/**
* Represents an enum type.
*/
public class EnumEntry extends TypeEntry {
protected final List<String> enum_constants = Lists.newArrayList();
public EnumEntry(SourceSet src, Language lang, String name) {
super(src, lang, name);
}
/**
* Gets a list of enum constants present in this enum.
*/
public List<String> getEnumConstants() {
return this.enum_constants;
}
/**
* Adds an enum constant to this enum.
*/
public void addEnumConstant(String cst) {
this.enum_constants.add(checkNotNull(cst));
}
@Override
public String toString() {
return "Enum " + this.name;
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
super.writeTo(pack, 1, AstSerializer.ENTRY_ID_ENUM);
pack.writeString("enumconstants").startArray(this.enum_constants.size());
for (String cst : this.enum_constants) {
pack.writeString(cst);
}
pack.endArray();
pack.endMap();
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitEnumEntry(this);
}
for (FieldEntry field : this.fields.values()) {
field.accept(visitor);
}
for (FieldEntry field : this.static_fields.values()) {
field.accept(visitor);
}
for (MethodEntry method : this.methods.values()) {
method.accept(visitor);
}
for (MethodEntry method : this.static_methods.values()) {
method.accept(visitor);
}
for (Annotation anno : this.annotations.values()) {
anno.accept(visitor);
}
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitTypeEnd();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/AnnotationEntry.java | src/main/java/org/spongepowered/despector/ast/type/AnnotationEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import org.spongepowered.despector.Language;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* Represents an interface type.
*/
public class AnnotationEntry extends TypeEntry {
public AnnotationEntry(SourceSet src, Language lang, String name) {
super(src, lang, name);
}
@Override
public String toString() {
return "Interface " + this.name;
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
super.writeTo(pack, 0, AstSerializer.ENTRY_ID_ANNOTATIONTYPE);
pack.endMap();
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitAnnotationEntry(this);
}
for (FieldEntry field : this.fields.values()) {
field.accept(visitor);
}
for (FieldEntry field : this.static_fields.values()) {
field.accept(visitor);
}
for (MethodEntry method : this.methods.values()) {
method.accept(visitor);
}
for (MethodEntry method : this.static_methods.values()) {
method.accept(visitor);
}
for (Annotation anno : this.annotations.values()) {
anno.accept(visitor);
}
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitTypeEnd();
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/type/FieldEntry.java | src/main/java/org/spongepowered/despector/ast/type/FieldEntry.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.type;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AccessModifier;
import org.spongepowered.despector.ast.Annotation;
import org.spongepowered.despector.ast.AnnotationType;
import org.spongepowered.despector.ast.AstEntry;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.SourceSet;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nullable;
/**
* An ast entry for fields.
*/
public class FieldEntry extends AstEntry {
protected AccessModifier access = AccessModifier.PACKAGE_PRIVATE;
protected String owner;
protected TypeSignature type;
protected String name;
protected boolean is_final;
protected boolean is_static;
protected boolean is_synthetic;
protected boolean is_volatile;
protected boolean is_transient;
protected boolean is_deprecated;
protected final Map<AnnotationType, Annotation> annotations = new LinkedHashMap<>();
public FieldEntry(SourceSet source) {
super(source);
}
/**
* Gets the access modifier of this field.
*/
public AccessModifier getAccessModifier() {
return this.access;
}
/**
* Sets the access modifier of this field.
*/
public void setAccessModifier(AccessModifier mod) {
this.access = checkNotNull(mod, "AccessModififer");
}
/**
* Gets the name of this field.
*/
public String getName() {
return this.name;
}
/**
* Sets the name of this field.
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets if this field is final.
*/
public boolean isFinal() {
return this.is_final;
}
/**
* Sets if this field is final.
*/
public void setFinal(boolean state) {
this.is_final = state;
}
/**
* Gets if this field is static.
*/
public boolean isStatic() {
return this.is_static;
}
/**
* Sets if this field is static.
*/
public void setStatic(boolean state) {
this.is_static = state;
}
/**
* Gets if this field is synthetic.
*/
public boolean isSynthetic() {
return this.is_synthetic;
}
/**
* Sets if this field is synthetic.
*/
public void setSynthetic(boolean state) {
this.is_synthetic = state;
}
public boolean isVolatile() {
return this.is_volatile;
}
public void setVolatile(boolean state) {
this.is_volatile = state;
}
public boolean isTransient() {
return this.is_transient;
}
public void setTransient(boolean state) {
this.is_transient = state;
}
public boolean isDeprecated() {
return this.is_deprecated;
}
public void setDeprecated(boolean state) {
this.is_deprecated = state;
}
/**
* Gets the type description of the owner of this field.
*/
public String getOwnerName() {
return this.owner;
}
/**
* Sets the type description of the owner of this field.
*/
public void setOwner(String owner) {
this.owner = owner;
}
/**
* Gets the type description of this field.
*/
public TypeSignature getType() {
return this.type;
}
/**
* Gets the internal name of the type of this field.
*/
public String getTypeName() {
return this.type.getName();
}
/**
* Sets the type of this field.
*/
public void setType(TypeSignature type) {
this.type = checkNotNull(type, "type");
}
/**
* Gets the annotation present on this field of the given type, if present.
*/
@Nullable
public Annotation getAnnotation(AnnotationType type) {
return this.annotations.get(type);
}
/**
* Gets all annotations on this field.
*/
public Collection<Annotation> getAnnotations() {
return this.annotations.values();
}
/**
* Adds the given annotation onto this field.
*/
public void addAnnotation(Annotation anno) {
this.annotations.put(anno.getType(), anno);
}
@Override
public String toString() {
return (this.is_static ? "Static " : "") + "Field " + this.type + " " + this.name;
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(12);
pack.writeString("id").writeInt(AstSerializer.ENTRY_ID_FIELD);
pack.writeString("access").writeInt(this.access.ordinal());
pack.writeString("name").writeString(this.name);
pack.writeString("owner").writeString(this.owner);
pack.writeString("type");
this.type.writeTo(pack);
pack.writeString("final").writeBool(this.is_final);
pack.writeString("static").writeBool(this.is_static);
pack.writeString("synthetic").writeBool(this.is_synthetic);
pack.writeString("volatile").writeBool(this.is_volatile);
pack.writeString("deprecated").writeBool(this.is_deprecated);
pack.writeString("transient").writeBool(this.is_transient);
pack.writeString("annotations").startArray(this.annotations.size());
for (Annotation anno : this.annotations.values()) {
anno.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
public void accept(AstVisitor visitor) {
if (visitor instanceof TypeVisitor) {
((TypeVisitor) visitor).visitField(this);
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/TypeParameter.java | src/main/java/org/spongepowered/despector/ast/generic/TypeParameter.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
/**
* A generic type parameter.
*/
public class TypeParameter {
private String identifier;
@Nullable
private TypeSignature class_bound;
private List<TypeSignature> interface_bounds = new ArrayList<>();
public TypeParameter(String ident, @Nullable TypeSignature cl) {
this.identifier = checkNotNull(ident, "identifier");
this.class_bound = cl;
}
/**
* Gets the identifier of the parameter.
*/
public String getIdentifier() {
return this.identifier;
}
/**
* Sets the identifier of the parameter.
*/
public void setIdentifier(String ident) {
this.identifier = checkNotNull(ident, "identifier");
}
/**
* Gets the class bound of the type parameter, if present.
*/
@Nullable
public TypeSignature getClassBound() {
return this.class_bound;
}
/**
* Sets the class bound of the type parameter, may be null.
*/
public void setClassBound(@Nullable TypeSignature sig) {
this.class_bound = sig;
}
/**
* Gets the interface bounds of the type parameter.
*/
public List<TypeSignature> getInterfaceBounds() {
return this.interface_bounds;
}
/**
* Writes this type parameter to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_PARAM);
pack.writeString("identifier").writeString(this.identifier);
pack.writeString("classbound");
if (this.class_bound != null) {
this.class_bound.writeTo(pack);
} else {
pack.writeNil();
}
pack.writeString("interfacebounds").startArray(this.interface_bounds.size());
for (TypeSignature sig : this.interface_bounds) {
sig.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append(this.identifier).append(":");
if (this.class_bound != null) {
str.append(this.class_bound);
}
if (this.interface_bounds.isEmpty()) {
str.append(":");
} else {
for (TypeSignature sig : this.interface_bounds) {
str.append(":");
str.append(sig);
}
}
return str.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof TypeParameter)) {
return false;
}
TypeParameter c = (TypeParameter) o;
return this.class_bound.equals(c.class_bound) && this.identifier.equals(c.identifier) && this.interface_bounds.equals(c.interface_bounds);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/package-info.java | src/main/java/org/spongepowered/despector/ast/generic/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.generic;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/VoidTypeSignature.java | src/main/java/org/spongepowered/despector/ast/generic/VoidTypeSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* The void type signature.
*/
public final class VoidTypeSignature extends TypeSignature {
public static final VoidTypeSignature VOID = new VoidTypeSignature();
private VoidTypeSignature() {
}
@Override
public boolean hasArguments() {
return false;
}
@Override
public String getName() {
return "void";
}
@Override
public String getDescriptor() {
return "V";
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(1);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_TYPEVOID);
pack.endMap();
}
@Override
public String toString() {
return "void";
}
@Override
public boolean equals(Object o) {
return o == VOID;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/ClassSignature.java | src/main/java/org/spongepowered/despector/ast/generic/ClassSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
/**
* A class signature containing information of generic types on the class and
* the direct supertype and superinterfaces.
*/
public class ClassSignature {
private final List<TypeParameter> parameters = new ArrayList<>();
@Nullable
private GenericClassTypeSignature superclass;
private final List<GenericClassTypeSignature> interfaces = new ArrayList<>();
public ClassSignature() {
}
/**
* Gets the type paramters of this class. The returned collection is
* mutable.
*/
public List<TypeParameter> getParameters() {
return this.parameters;
}
/**
* Gets the type signature of the direct superclass.
*/
@Nullable
public GenericClassTypeSignature getSuperclassSignature() {
return this.superclass;
}
/**
* Sets the type signature of the direct superclass.
*/
public void setSuperclassSignature(@Nullable GenericClassTypeSignature sig) {
this.superclass = sig;
}
/**
* Gets the type signatures of the direct superinterfaces. The returned
* collection is mutable.
*/
public List<GenericClassTypeSignature> getInterfaceSignatures() {
return this.interfaces;
}
/**
* Writes this signature to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_CLASS);
pack.writeString("parameters").startArray(this.parameters.size());
for (TypeParameter param : this.parameters) {
param.writeTo(pack);
}
pack.endArray();
pack.writeString("superclass");
if (this.superclass != null) {
this.superclass.writeTo(pack);
} else {
pack.writeNil();
}
pack.writeString("interfaces").startArray(this.interfaces.size());
for (GenericClassTypeSignature sig : this.interfaces) {
sig.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
if (!this.parameters.isEmpty()) {
str.append("<");
for (TypeParameter param : this.parameters) {
str.append(param);
}
str.append(">");
}
str.append(this.superclass);
for (GenericClassTypeSignature inter : this.interfaces) {
str.append(inter);
}
return str.toString();
}
@Override
public int hashCode() {
int h = 1;
for (int i = 0; i < this.parameters.size(); i++) {
h = h * 37 + this.parameters.get(i).hashCode();
}
h = h * 37 + (this.superclass == null ? 0 : this.superclass.hashCode());
for (int i = 0; i < this.interfaces.size(); i++) {
h = h * 37 + this.interfaces.get(i).hashCode();
}
return h;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof ClassSignature)) {
return false;
}
ClassSignature sig = (ClassSignature) o;
if (this.superclass == null) {
if (sig.superclass != null) {
return false;
}
} else if (!this.superclass.equals(sig.superclass)) {
return false;
}
if (this.parameters.size() != sig.parameters.size()) {
return false;
}
for (int i = 0; i < this.parameters.size(); i++) {
if (!this.parameters.get(i).equals(sig.parameters.get(i))) {
return false;
}
}
if (this.interfaces.size() != sig.interfaces.size()) {
return false;
}
for (int i = 0; i < this.interfaces.size(); i++) {
if (!this.interfaces.get(i).equals(sig.interfaces.get(i))) {
return false;
}
}
return true;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/TypeSignature.java | src/main/java/org/spongepowered/despector/ast/generic/TypeSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* A type signature which can be either a type variable or a concrete class or
* void.
*/
public abstract class TypeSignature {
/**
* Gets if this signature has any type arguments.
*/
public abstract boolean hasArguments();
public abstract String getName();
public abstract String getDescriptor();
public boolean isArray() {
return false;
}
public abstract void writeTo(MessagePacker pack) throws IOException;
/**
* Gets a {@link TypeSignature} which is an array of the given type.
*/
public static TypeSignature arrayOf(TypeSignature type) {
if (type instanceof GenericClassTypeSignature) {
GenericClassTypeSignature sig = (GenericClassTypeSignature) type;
GenericClassTypeSignature array = new GenericClassTypeSignature("[" + sig.getType());
array.getArguments().addAll(sig.getArguments());
return array;
} else if (type instanceof ClassTypeSignature) {
ClassTypeSignature sig = (ClassTypeSignature) type;
ClassTypeSignature array = ClassTypeSignature.of("[" + sig.getType());
return array;
} else if (type instanceof TypeVariableSignature) {
TypeVariableSignature sig = (TypeVariableSignature) type;
TypeVariableSignature array = new TypeVariableSignature("[" + sig.getIdentifier());
return array;
}
throw new IllegalStateException();
}
/**
* Gets the component {@link TypeSignature} of the given array type.
*/
public static TypeSignature getArrayComponent(TypeSignature type) {
if (type instanceof GenericClassTypeSignature) {
GenericClassTypeSignature sig = (GenericClassTypeSignature) type;
GenericClassTypeSignature array = new GenericClassTypeSignature(sig.getType().substring(1));
array.getArguments().addAll(sig.getArguments());
return array;
} else if (type instanceof ClassTypeSignature) {
ClassTypeSignature sig = (ClassTypeSignature) type;
ClassTypeSignature array = ClassTypeSignature.of(sig.getType().substring(1), true);
return array;
} else if (type instanceof TypeVariableSignature) {
TypeVariableSignature sig = (TypeVariableSignature) type;
TypeVariableSignature array = new TypeVariableSignature(sig.getIdentifier().substring(1));
return array;
}
throw new IllegalStateException();
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/GenericClassTypeSignature.java | src/main/java/org/spongepowered/despector/ast/generic/GenericClassTypeSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.util.TypeHelper;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* A type signature of a class with generic arguments.
*/
public class GenericClassTypeSignature extends TypeSignature {
protected String type_name;
private List<TypeArgument> args = new ArrayList<>();
private GenericClassTypeSignature parent;
public GenericClassTypeSignature(String type) {
this.type_name = checkNotNull(type, "type");
this.parent = null;
}
public GenericClassTypeSignature(GenericClassTypeSignature parent, String type) {
this.type_name = checkNotNull(type, "type");
this.parent = parent;
}
public GenericClassTypeSignature getParent() {
return this.parent;
}
public boolean hasParent() {
return this.parent != null;
}
/**
* Gets the type descriptor.
*/
public String getType() {
return this.type_name;
}
/**
* Sets the type descriptor.
*/
public void setType(String type) {
this.type_name = checkNotNull(type, "type");
}
/**
* Gets the type arguments.
*/
public List<TypeArgument> getArguments() {
return this.args;
}
@Override
public boolean hasArguments() {
return !this.args.isEmpty();
}
@Override
public String getName() {
return TypeHelper.descToType(this.type_name);
}
@Override
public String getDescriptor() {
return this.type_name;
}
@Override
public boolean isArray() {
return this.type_name.startsWith("[");
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_TYPEGENERIC);
pack.writeString("type").writeString(this.type_name);
pack.writeString("args").startArray(this.args.size());
for (TypeArgument arg : this.args) {
arg.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append(this.type_name);
if (!this.args.isEmpty()) {
str.append("<");
for (TypeArgument arg : this.args) {
str.append(arg);
}
str.append(">");
}
return str.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof GenericClassTypeSignature)) {
if (o instanceof ClassTypeSignature) {
ClassTypeSignature g = (ClassTypeSignature) o;
return !this.hasArguments() && this.type_name.equals(g.getType());
}
return false;
}
GenericClassTypeSignature c = (GenericClassTypeSignature) o;
if (c.args.size() != this.args.size()) {
return false;
}
for (int i = 0; i < this.args.size(); i++) {
if (!this.args.get(i).equals(c.args.get(i))) {
return false;
}
}
return c.type_name.equals(this.type_name);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/MethodSignature.java | src/main/java/org/spongepowered/despector/ast/generic/MethodSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* A method signature containing generic type information on any type
* parameters, parameters, exceptions, and the return type.
*/
public class MethodSignature {
private final List<TypeParameter> type_parameters = new ArrayList<>();
private final List<TypeSignature> parameters = new ArrayList<>();
private final List<TypeSignature> exceptions = new ArrayList<>();
private TypeSignature return_type;
public MethodSignature() {
this.return_type = VoidTypeSignature.VOID;
}
public MethodSignature(TypeSignature sig) {
this.return_type = checkNotNull(sig, "sig");
}
/**
* Gets the method type parameters.
*/
public List<TypeParameter> getTypeParameters() {
return this.type_parameters;
}
/**
* Gets the signatures of the method's parameters.
*/
public List<TypeSignature> getParameters() {
return this.parameters;
}
/**
* Gets the signature of the return type.
*/
public TypeSignature getReturnType() {
return this.return_type;
}
/**
* Sets the signature of the return type.
*/
public void setReturnType(TypeSignature sig) {
this.return_type = checkNotNull(sig, "sig");
}
/**
* Gets the signatures of any declared thrown exceptions.
*/
public List<TypeSignature> getThrowsSignature() {
return this.exceptions;
}
/**
* Writes this method signature to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(5);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_METHOD);
pack.writeString("type_parameters").startArray(this.type_parameters.size());
for (TypeParameter param : this.type_parameters) {
param.writeTo(pack);
}
pack.endArray();
pack.writeString("parameters").startArray(this.parameters.size());
for (TypeSignature sig : this.parameters) {
sig.writeTo(pack);
}
pack.endArray();
pack.writeString("exceptions").startArray(this.exceptions.size());
for (TypeSignature sig : this.exceptions) {
sig.writeTo(pack);
}
pack.endArray();
pack.writeString("returntype");
this.return_type.writeTo(pack);
pack.endMap();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
if (!this.type_parameters.isEmpty()) {
boolean first = true;
str.append("<");
for (TypeParameter param : this.type_parameters) {
if (!first) {
str.append(", ");
} else {
first = false;
}
str.append(param);
}
str.append(">");
}
str.append("(");
boolean first = true;
for (TypeSignature param : this.parameters) {
if (!first) {
str.append(", ");
} else {
first = false;
}
str.append(param);
}
str.append(")");
str.append(this.return_type);
return str.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof MethodSignature)) {
return false;
}
MethodSignature c = (MethodSignature) o;
return this.return_type.equals(c.return_type) && this.exceptions.equals(c.exceptions) && this.parameters.equals(c.parameters)
&& this.type_parameters.equals(c.type_parameters);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/TypeVariableSignature.java | src/main/java/org/spongepowered/despector/ast/generic/TypeVariableSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* A type signature referencing a type variable.
*/
public class TypeVariableSignature extends TypeSignature {
private String identifier;
public TypeVariableSignature(String ident) {
this.identifier = checkNotNull(ident, "identifier");
}
/**
* Gets the identifier of the type variable.
*/
public String getIdentifier() {
return this.identifier;
}
/**
* Sets the identifier of the type variable.
*/
public void setIdentifier(String ident) {
this.identifier = checkNotNull(ident, "identifier");
}
public String getIdentifierName() {
return this.identifier.substring(1, this.identifier.length() - 1);
}
@Override
public boolean hasArguments() {
return false;
}
@Override
public String getName() {
return getIdentifierName();
}
@Override
public String getDescriptor() {
return this.identifier;
}
@Override
public boolean isArray() {
return this.identifier.startsWith("[");
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(2);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_TYPEVAR);
pack.writeString("identifier").writeString(this.identifier);
pack.endMap();
}
@Override
public String toString() {
return this.identifier;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof TypeVariableSignature)) {
return false;
}
TypeVariableSignature c = (TypeVariableSignature) o;
return this.identifier.equals(c.identifier);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/TypeArgument.java | src/main/java/org/spongepowered/despector/ast/generic/TypeArgument.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import javax.annotation.Nullable;
/**
* A type argument is a generic type specified as a type parameter of a type.
*/
public class TypeArgument {
private WildcardType wildcard;
@Nullable
private TypeSignature sig;
public TypeArgument(WildcardType wildcard, @Nullable TypeSignature sig) {
this.wildcard = checkNotNull(wildcard, "wildcard");
this.sig = sig;
}
/**
* Gets the wildcard type of this argument.
*/
public WildcardType getWildcard() {
return this.wildcard;
}
/**
* Sets the wildcard type of this argument.
*/
public void setWildcard(WildcardType wild) {
this.wildcard = checkNotNull(wild, "wildcard");
}
/**
* Gets the signature of the argument.
*/
@Nullable
public TypeSignature getSignature() {
return this.sig;
}
/**
* Sets the signature of the argument.
*/
public void setSignature(@Nullable TypeSignature sig) {
this.sig = sig;
}
/**
* Writes this type argument to the given {@link MessagePacker}.
*/
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_ARG);
pack.writeString("wildcard").writeInt(this.wildcard.ordinal());
pack.writeString("signature");
if (this.sig != null) {
this.sig.writeTo(pack);
} else {
pack.writeNil();
}
pack.endMap();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append(this.wildcard.getRepresentation());
str.append(this.sig);
return str.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof TypeArgument)) {
return false;
}
TypeArgument c = (TypeArgument) o;
if (this.sig != null) {
if (!this.sig.equals(c.sig)) {
return false;
}
} else if (c.sig != null) {
return false;
}
return this.wildcard.equals(c.wildcard);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/ClassTypeSignature.java | src/main/java/org/spongepowered/despector/ast/generic/ClassTypeSignature.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.util.TypeHelper;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* A type signature of a class or primative type (but not void).
*/
public class ClassTypeSignature extends TypeSignature {
public static final ClassTypeSignature BOOLEAN = new ClassTypeSignature("Z");
public static final ClassTypeSignature BYTE = new ClassTypeSignature("B");
public static final ClassTypeSignature SHORT = new ClassTypeSignature("S");
public static final ClassTypeSignature INT = new ClassTypeSignature("I");
public static final ClassTypeSignature LONG = new ClassTypeSignature("J");
public static final ClassTypeSignature FLOAT = new ClassTypeSignature("F");
public static final ClassTypeSignature DOUBLE = new ClassTypeSignature("D");
public static final ClassTypeSignature CHAR = new ClassTypeSignature("C");
public static final ClassTypeSignature OBJECT = new ClassTypeSignature("Ljava/lang/Object;");
public static final ClassTypeSignature STRING = new ClassTypeSignature("Ljava/lang/String;");
public static final ClassTypeSignature BOOLEAN_OBJECT = new ClassTypeSignature("Ljava/lang/Boolean;");
public static final ClassTypeSignature BYTE_OBJECT = new ClassTypeSignature("Ljava/lang/Byte;");
public static final ClassTypeSignature SHORT_OBJECT = new ClassTypeSignature("Ljava/lang/Short;");
public static final ClassTypeSignature INTEGER_OBJECT = new ClassTypeSignature("Ljava/lang/Integer;");
public static final ClassTypeSignature LONG_OBJECT = new ClassTypeSignature("Ljava/lang/Long;");
public static final ClassTypeSignature FLOAT_OBJECT = new ClassTypeSignature("Ljava/lang/Float;");
public static final ClassTypeSignature DOUBLE_OBJECT = new ClassTypeSignature("Ljava/lang/Double;");
public static final ClassTypeSignature CHARACTER_OBJECT = new ClassTypeSignature("Ljava/lang/Character;");
private static final Map<String, ClassTypeSignature> SPECIAL = new HashMap<>();
static {
SPECIAL.put(BOOLEAN.getType(), BOOLEAN);
SPECIAL.put(BYTE.getType(), BYTE);
SPECIAL.put(SHORT.getType(), SHORT);
SPECIAL.put(INT.getType(), INT);
SPECIAL.put(LONG.getType(), LONG);
SPECIAL.put(FLOAT.getType(), FLOAT);
SPECIAL.put(DOUBLE.getType(), DOUBLE);
SPECIAL.put(CHAR.getType(), CHAR);
SPECIAL.put(STRING.getType(), STRING);
SPECIAL.put(OBJECT.getType(), OBJECT);
SPECIAL.put(BOOLEAN_OBJECT.getType(), BOOLEAN_OBJECT);
SPECIAL.put(BYTE_OBJECT.getType(), BYTE_OBJECT);
SPECIAL.put(SHORT_OBJECT.getType(), SHORT_OBJECT);
SPECIAL.put(INTEGER_OBJECT.getType(), INTEGER_OBJECT);
SPECIAL.put(LONG_OBJECT.getType(), LONG_OBJECT);
SPECIAL.put(FLOAT_OBJECT.getType(), FLOAT_OBJECT);
SPECIAL.put(DOUBLE_OBJECT.getType(), DOUBLE_OBJECT);
SPECIAL.put(CHARACTER_OBJECT.getType(), CHARACTER_OBJECT);
}
/**
* Gets the {@link ClassTypeSignature} for the given type descriptor. A new
* instance is created unless the type is a special type (primatives,
* primative wrappers, object, and string).
*/
public static ClassTypeSignature of(String type) {
return of(type, false);
}
/**
* Gets the {@link ClassTypeSignature} for the given type descriptor. A new
* instance is created unless the type is a special type (primatives,
* primative wrappers, object, and string) and the no_special flag is unset.
*/
public static ClassTypeSignature of(String type, boolean no_special) {
if(!TypeHelper.isDescriptor(type)) {
throw new IllegalStateException("'" + type + "' is not a type descriptor");
}
if (!no_special) {
ClassTypeSignature sig = SPECIAL.get(type);
if (sig != null) {
return sig;
}
}
return new ClassTypeSignature(type);
}
protected String type_name;
ClassTypeSignature(String type) {
this.type_name = checkNotNull(type, "type");
}
/**
* Gets the type descriptor.
*/
public String getType() {
return this.type_name;
}
/**
* Sets the type descriptor.
*/
public void setType(String type) {
this.type_name = checkNotNull(type, "type");
}
@Override
public boolean hasArguments() {
return false;
}
@Override
public String getName() {
return TypeHelper.descToType(this.type_name);
}
public String getClassName() {
return getName().replace('/', '.');
}
@Override
public String getDescriptor() {
return this.type_name;
}
@Override
public boolean isArray() {
return this.type_name.startsWith("[");
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(2);
pack.writeString("id").writeInt(AstSerializer.SIGNATURE_ID_TYPECLASS);
pack.writeString("type").writeString(this.type_name);
pack.endMap();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append(this.type_name);
return str.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof ClassTypeSignature)) {
if (o instanceof GenericClassTypeSignature) {
GenericClassTypeSignature g = (GenericClassTypeSignature) o;
return !g.hasArguments() && this.type_name.equals(g.getType());
}
return false;
}
ClassTypeSignature c = (ClassTypeSignature) o;
return c.type_name.equals(this.type_name);
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/generic/WildcardType.java | src/main/java/org/spongepowered/despector/ast/generic/WildcardType.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.generic;
/**
* Represents the various type of generic wildcards.
*/
public enum WildcardType {
NONE(""),
EXTENDS("+"),
SUPER("-"),
STAR("*");
private final String rep;
WildcardType(String t) {
this.rep = t;
}
/**
* Gets the representation of the wildcard in a type signature string.
*/
public String getRepresentation() {
return this.rep;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/kotlin/package-info.java | src/main/java/org/spongepowered/despector/ast/kotlin/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.kotlin;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/kotlin/Elvis.java | src/main/java/org/spongepowered/despector/ast/kotlin/Elvis.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.kotlin;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An elvis ?: instruction.
*/
public class Elvis implements Instruction {
private Instruction left;
private Instruction else_;
public Elvis(Instruction left, Instruction else_) {
this.left = checkNotNull(left, "left");
this.else_ = checkNotNull(else_, "else");
}
/**
* Gets the argument of the elvis statement.
*/
public Instruction getArg() {
return this.left;
}
/**
* Sets the argument of the elvis statement.
*/
public void setArg(Instruction insn) {
this.left = checkNotNull(insn, "left");
}
/**
* Gets the value if the arg is null or zero.
*/
public Instruction getElse() {
return this.else_;
}
/**
* Sets the value if the arg is null or zero.
*/
public void setElse(Instruction insn) {
this.else_ = checkNotNull(insn, "else");
}
@Override
public TypeSignature inferType() {
// TODO gather the most specific of each case
return this.left.inferType();
}
@Override
public void accept(AstVisitor visitor) {
// TODO how to handle visitors for kotlin specific instructions
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
//TODO
}
@Override
public String toString() {
return this.left.toString() + " ?: " + this.else_.toString();
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/kotlin/When.java | src/main/java/org/spongepowered/despector/ast/kotlin/When.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.kotlin;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.ast.stmt.Statement;
import org.spongepowered.despector.ast.stmt.StatementBlock;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
/**
* A kotlin when statement.
*/
public class When implements Instruction {
private LocalInstance local;
private Instruction var;
private final List<Case> cases = new ArrayList<>();
private Case else_body;
public When(LocalInstance local, Instruction var) {
this.local = checkNotNull(local, "local");
this.var = checkNotNull(var, "var");
this.else_body = new Case(null, null, null);
}
/**
* Gets the local used internally for each of the case checks.
*/
public LocalInstance getLocal() {
return this.local;
}
/**
* Sets the local used internally for each of the case checks.
*/
public void setLocal(LocalInstance local) {
this.local = checkNotNull(local, "local");
}
/**
* Gets the argument of the when statement.
*/
public Instruction getArg() {
return this.var;
}
/**
* Sets the argument of the when statement.
*/
public void setArg(Instruction insn) {
this.var = checkNotNull(insn, "var");
}
/**
* Gets the cases of the when statement.
*/
public List<Case> getCases() {
return this.cases;
}
/**
* Gets the body of the else case.
*/
@Nullable
public StatementBlock getElseBody() {
return this.else_body.getBody();
}
/**
* Gets the last instruction of the else case which becomes the final value.
*/
@Nullable
public Instruction getElseBodyLast() {
return this.else_body.getLast();
}
public void setElseBody(@Nullable StatementBlock body, @Nullable Instruction last) {
this.else_body.setBody(body);
this.else_body.setInstruction(last);
}
@Override
public TypeSignature inferType() {
// TODO gather the most specific type of all cases
return this.cases.get(0).getLast().inferType();
}
@Override
public void accept(AstVisitor visitor) {
// TODO
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
//TODO
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append("when (").append(this.var.toString()).append(") {\n");
for (Case cs : this.cases) {
str.append(" ").append(cs.getCondition().toString()).append(" -> ");
if (cs.getBody().getStatementCount() == 0) {
str.append(cs.getLast().toString()).append("\n");
} else {
str.append(" {\n");
for (Statement stmt : cs.getBody().getStatements()) {
str.append(" ").append(stmt.toString());
}
str.append(" ").append(cs.getLast().toString()).append("\n");
str.append(" }\n");
}
}
str.append("}");
return str.toString();
}
/**
* A case of the when statement.
*/
public static class Case {
@Nullable private Condition condition;
@Nullable private StatementBlock body;
@Nullable private Instruction last;
public Case(@Nullable Condition cond, StatementBlock body, Instruction last) {
this.condition = cond;
this.body = checkNotNull(body, "body");
this.last = checkNotNull(last, "last");
}
/**
* Gets the condition of this case, or null if this is the else case.
*/
@Nullable
public Condition getCondition() {
return this.condition;
}
/**
* Sets the condition of this case, may be null if this is the else
* case.
*/
public void setCondition(Condition cond) {
this.condition = cond;
}
/**
* Gets the body of this case, or null if this case is a single
* instruction.
*/
public StatementBlock getBody() {
return this.body;
}
/**
* Sets the body of this case, may be null if this case is a single
* instruction.
*/
public void setBody(StatementBlock body) {
this.body = body;
}
/**
* Gets the last instruction which becomes the value of the case. May be
* null if this when statement does not return any value.
*/
public Instruction getLast() {
return this.last;
}
/**
* Sets the last instruction which becomes the value of the case. May be
* null if this when statement does not return any value.
*/
public void setInstruction(Instruction insn) {
this.last = insn;
}
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/Instruction.java | src/main/java/org/spongepowered/despector/ast/insn/Instruction.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* The abstract instruction type.
*/
public interface Instruction {
/**
* Gets the inferred type description of this instruction.
*/
TypeSignature inferType();
/**
* Passes itself and any child nodes to the given visitor.
*/
void accept(AstVisitor visitor);
@Override
String toString();
@Override
boolean equals(Object obj);
void writeTo(MessagePacker pack) throws IOException;
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/package-info.java | src/main/java/org/spongepowered/despector/ast/insn/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.insn;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/InstructionVisitor.java | src/main/java/org/spongepowered/despector/ast/insn/InstructionVisitor.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.insn.cst.DoubleConstant;
import org.spongepowered.despector.ast.insn.cst.FloatConstant;
import org.spongepowered.despector.ast.insn.cst.IntConstant;
import org.spongepowered.despector.ast.insn.cst.LongConstant;
import org.spongepowered.despector.ast.insn.cst.NullConstant;
import org.spongepowered.despector.ast.insn.cst.StringConstant;
import org.spongepowered.despector.ast.insn.cst.TypeConstant;
import org.spongepowered.despector.ast.insn.misc.Cast;
import org.spongepowered.despector.ast.insn.misc.InstanceOf;
import org.spongepowered.despector.ast.insn.misc.MultiNewArray;
import org.spongepowered.despector.ast.insn.misc.NewArray;
import org.spongepowered.despector.ast.insn.misc.NumberCompare;
import org.spongepowered.despector.ast.insn.misc.Ternary;
import org.spongepowered.despector.ast.insn.op.NegativeOperator;
import org.spongepowered.despector.ast.insn.op.Operator;
import org.spongepowered.despector.ast.insn.var.ArrayAccess;
import org.spongepowered.despector.ast.insn.var.InstanceFieldAccess;
import org.spongepowered.despector.ast.insn.var.LocalAccess;
import org.spongepowered.despector.ast.insn.var.StaticFieldAccess;
import org.spongepowered.despector.ast.stmt.invoke.InstanceMethodInvoke;
import org.spongepowered.despector.ast.stmt.invoke.Lambda;
import org.spongepowered.despector.ast.stmt.invoke.MethodReference;
import org.spongepowered.despector.ast.stmt.invoke.New;
import org.spongepowered.despector.ast.stmt.invoke.StaticMethodInvoke;
/**
* A visitor which may be used to traverse the AST.
*/
public interface InstructionVisitor extends AstVisitor {
void visitArrayAccess(ArrayAccess insn);
void visitCast(Cast insn);
void visitDoubleConstant(DoubleConstant insn);
void visitDynamicInvoke(Lambda insn);
void visitFloatConstant(FloatConstant insn);
void visitInstanceFieldAccess(InstanceFieldAccess insn);
void visitInstanceMethodInvoke(InstanceMethodInvoke insn);
void visitInstanceOf(InstanceOf insn);
void visitIntConstant(IntConstant insn);
void visitLocalAccess(LocalAccess insn);
void visitLocalInstance(LocalInstance local);
void visitLongConstant(LongConstant insn);
void visitMultiNewArray(MultiNewArray insn);
void visitNegativeOperator(NegativeOperator insn);
void visitNew(New insn);
void visitNewArray(NewArray insn);
void visitNullConstant(NullConstant insn);
void visitNumberCompare(NumberCompare insn);
void visitOperator(Operator insn);
void visitStaticFieldAccess(StaticFieldAccess insn);
void visitStaticMethodInvoke(StaticMethodInvoke insn);
void visitStringConstant(StringConstant insn);
void visitTernary(Ternary insn);
void visitTypeConstant(TypeConstant insn);
void visitMethodReference(MethodReference methodReference);
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/Cast.java | src/main/java/org/spongepowered/despector/ast/insn/misc/Cast.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.misc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction which casts the inner value to a specific type.
*
* <p>Example: (type) (val)</p>
*/
public class Cast implements Instruction {
private TypeSignature type;
private Instruction val;
public Cast(TypeSignature type, Instruction val) {
this.type = checkNotNull(type, "type");
this.val = checkNotNull(val, "val");
}
/**
* Gets the type which the valye is casted to.
*/
public TypeSignature getType() {
return this.type;
}
/**
* Sets the type which the valye is casted to.
*/
public void setType(TypeSignature type) {
this.type = checkNotNull(type, "type");
}
/**
* Gets the instruction for the type being cast.
*/
public Instruction getValue() {
return this.val;
}
/**
* Sets the instruction for the type being cast.
*/
public void setValue(Instruction val) {
this.val = checkNotNull(val, "val");
}
@Override
public TypeSignature inferType() {
return this.type;
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitCast(this);
this.val.accept(visitor);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_CAST);
pack.writeString("value");
this.val.writeTo(pack);
pack.writeString("type");
this.type.writeTo(pack);
pack.endMap();
}
@Override
public String toString() {
return "((" + this.type.getName() + ") " + this.val + ")";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Cast)) {
return false;
}
Cast cast = (Cast) obj;
return this.type.equals(cast.type) && this.val.equals(cast.val);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.type.hashCode();
h = h * 37 + this.val.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/NumberCompare.java | src/main/java/org/spongepowered/despector/ast/insn/misc/NumberCompare.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.misc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction performing a comparison between two numerical values.
*/
public class NumberCompare implements Instruction {
protected Instruction left;
protected Instruction right;
public NumberCompare(Instruction left, Instruction right) {
this.left = checkNotNull(left, "left");
this.right = checkNotNull(right, "right");
}
/**
* Gets the left operand of the comparison.
*/
public Instruction getLeftOperand() {
return this.left;
}
/**
* Sets the left operand of the comparison.
*/
public void setLeftOperand(Instruction left) {
this.left = checkNotNull(left, "left");
}
/**
* Gets the right operand of the comparison.
*/
public Instruction getRightOperand() {
return this.right;
}
/**
* Sets the right operand of the comparison.
*/
public void setRightOperand(Instruction right) {
this.right = checkNotNull(right, "right");
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitNumberCompare(this);
this.left.accept(visitor);
this.right.accept(visitor);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_NUMBER_COMPARE);
pack.writeString("left");
this.left.writeTo(pack);
pack.writeString("right");
this.right.writeTo(pack);
pack.endMap();
}
@Override
public TypeSignature inferType() {
return this.left.inferType();
}
@Override
public String toString() {
return "Integer.signum(" + this.right + " - " + this.left + ");";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof NumberCompare)) {
return false;
}
NumberCompare insn = (NumberCompare) obj;
return this.left.equals(insn.left) && this.right.equals(insn.right);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.left.hashCode();
h = h * 37 + this.right.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/package-info.java | src/main/java/org/spongepowered/despector/ast/insn/misc/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.insn.misc;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/InstanceOf.java | src/main/java/org/spongepowered/despector/ast/insn/misc/InstanceOf.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.misc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction that checks if a value is of a certain instance.
*/
public class InstanceOf implements Instruction {
private Instruction check;
private ClassTypeSignature type;
public InstanceOf(Instruction check, ClassTypeSignature type) {
this.check = checkNotNull(check, "check");
this.type = checkNotNull(type, "type");
}
/**
* Gets the value being tested.
*/
public Instruction getCheckedValue() {
return this.check;
}
/**
* Sets the value being tested, must be an array or object.
*/
public void setCheckedValue(Instruction val) {
this.check = checkNotNull(val, "check");
}
/**
* Gets the type being tested for.
*/
public ClassTypeSignature getType() {
return this.type;
}
/**
* Sets the type being tested for, must be an array or object.
*/
public String getTypeName() {
return this.type.getClassName();
}
public void setType(ClassTypeSignature type) {
this.type = checkNotNull(type, "type");
}
@Override
public TypeSignature inferType() {
return ClassTypeSignature.BOOLEAN;
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitInstanceOf(this);
this.check.accept(visitor);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_INSTANCE_OF);
pack.writeString("val");
this.check.writeTo(pack);
pack.writeString("type").writeString(this.type.getDescriptor());
pack.endMap();
}
@Override
public String toString() {
return this.check + " instanceof " + getTypeName();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof InstanceOf)) {
return false;
}
InstanceOf insn = (InstanceOf) obj;
return this.check.equals(insn.check) && this.type.equals(insn.type);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.check.hashCode();
h = h * 37 + this.type.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/MultiNewArray.java | src/main/java/org/spongepowered/despector/ast/insn/misc/MultiNewArray.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.misc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import java.util.Arrays;
/**
* An instruction initializing a new array.
*/
public class MultiNewArray implements Instruction {
private ClassTypeSignature type;
private Instruction[] sizes;
public MultiNewArray(ClassTypeSignature type, Instruction[] sizes) {
this.type = checkNotNull(type, "type");
this.sizes = checkNotNull(sizes, "size");
}
/**
* Gets the component type of the new array.
*/
public ClassTypeSignature getType() {
return this.type;
}
/**
* Sets the component type of the new array.
*/
public void setType(ClassTypeSignature type) {
this.type = checkNotNull(type, "type");
}
/**
* Gets the size of the new array.
*/
public Instruction[] getSizes() {
return this.sizes;
}
/**
* Gets the size of the new array, must type check as an integer.
*/
public void setSizes(Instruction[] size) {
this.sizes = checkNotNull(size, "size");
}
@Override
public TypeSignature inferType() {
return ClassTypeSignature.of("[" + this.type);
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitMultiNewArray(this);
for (Instruction size : this.sizes) {
size.accept(visitor);
}
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_MULTI_NEW_ARRAY);
pack.writeString("type").writeString(this.type.getDescriptor());
pack.writeString("sizes");
pack.startArray(this.sizes.length);
for (Instruction size : this.sizes) {
size.writeTo(pack);
}
pack.endArray();
pack.endMap();
}
@Override
public String toString() {
String result = "new " + this.type.getClassName();
for (int i = 0; i < this.sizes.length; i++) {
result += "[";
result += this.sizes[i];
result += "]";
}
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof MultiNewArray)) {
return false;
}
MultiNewArray insn = (MultiNewArray) obj;
return Arrays.equals(this.sizes, insn.sizes) && this.type.equals(insn.type);
}
@Override
public int hashCode() {
int h = 1;
for (Instruction size : this.sizes) {
h = h * 37 + size.hashCode();
}
h = h * 37 + this.type.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/Ternary.java | src/main/java/org/spongepowered/despector/ast/insn/misc/Ternary.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.misc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.ast.insn.condition.Condition;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* A ternary instruction.
*/
public class Ternary implements Instruction {
private Condition condition;
private Instruction true_val;
private Instruction false_val;
public Ternary(Condition cond, Instruction true_val, Instruction false_val) {
this.condition = checkNotNull(cond, "condition");
this.true_val = checkNotNull(true_val, "true_val");
this.false_val = checkNotNull(false_val, "false_val");
}
/**
* Gets the condition of this ternary.
*/
public Condition getCondition() {
return this.condition;
}
/**
* Sets the condition of this ternary.
*/
public void setCondition(Condition condition) {
this.condition = checkNotNull(condition, "condition");
}
/**
* Gets the value if the condition is true.
*/
public Instruction getTrueValue() {
return this.true_val;
}
/**
* Sets the value if the condition is true.
*/
public void setTrueValue(Instruction val) {
this.true_val = checkNotNull(val, "true_val");
}
/**
* Gets the value if the condition is false.
*/
public Instruction getFalseValue() {
return this.false_val;
}
/**
* Sets the value if the condition is false.
*/
public void setFalseValue(Instruction val) {
this.false_val = checkNotNull(val, "false_val");
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitTernary(this);
}
this.condition.accept(visitor);
this.true_val.accept(visitor);
this.false_val.accept(visitor);
}
@Override
public TypeSignature inferType() {
return this.true_val.inferType();
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_TERNARY);
pack.writeString("condition");
this.condition.writeTo(pack);
pack.writeString("true");
this.true_val.writeTo(pack);
pack.writeString("false");
this.false_val.writeTo(pack);
pack.endMap();
}
@Override
public String toString() {
return this.condition + " ? " + this.true_val + " : " + this.false_val;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Ternary)) {
return false;
}
Ternary insn = (Ternary) obj;
return this.condition.equals(insn.condition) && this.true_val.equals(insn.true_val) && this.false_val.equals(insn.false_val);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.condition.hashCode();
h = h * 37 + this.true_val.hashCode();
h = h * 37 + this.false_val.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/misc/NewArray.java | src/main/java/org/spongepowered/despector/ast/insn/misc/NewArray.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.misc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
import javax.annotation.Nullable;
/**
* An instruction initializing a new array.
*/
public class NewArray implements Instruction {
private ClassTypeSignature type;
private Instruction size;
private Instruction[] values;
public NewArray(ClassTypeSignature type, Instruction size, @Nullable Instruction[] values) {
this.type = checkNotNull(type, "type");
this.size = checkNotNull(size, "size");
this.values = values;
}
/**
* Gets the component type of the new array.
*/
public ClassTypeSignature getType() {
return this.type;
}
/**
* Sets the component type of the new array.
*/
public void setType(ClassTypeSignature type) {
this.type = checkNotNull(type, "type");
}
/**
* Gets the size of the new array.
*/
public Instruction getSize() {
return this.size;
}
/**
* Gets the size of the new array, must type check as an integer.
*/
public void setSize(Instruction size) {
this.size = checkNotNull(size, "size");
}
/**
* Gets the initial values of the array, if specified.
*/
@Nullable
public Instruction[] getInitializer() {
return this.values;
}
/**
* Sets the initial values of the array, if specified.
*/
public void setInitialValues(@Nullable Instruction... values) {
this.values = values;
}
@Override
public TypeSignature inferType() {
return ClassTypeSignature.of("[" + this.type);
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitNewArray(this);
this.size.accept(visitor);
if (this.values != null) {
for (Instruction value : this.values) {
value.accept(visitor);
}
}
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_NEW_ARRAY);
pack.writeString("type").writeString(this.type.getDescriptor());
pack.writeString("size");
this.size.writeTo(pack);
pack.writeString("values");
if (this.values != null) {
pack.startArray(this.values.length);
for (Instruction insn : this.values) {
insn.writeTo(pack);
}
pack.endArray();
} else {
pack.writeNil();
}
pack.endMap();
}
@Override
public String toString() {
if (this.values == null) {
return "new " + this.type.getClassName() + "[" + this.size + "]";
}
String result = "new " + this.type.getClassName() + "[] {";
for (int i = 0; i < this.values.length; i++) {
result += this.values[i];
if (i < this.values.length - 1) {
result += ", ";
}
}
result += "}";
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof NewArray)) {
return false;
}
NewArray insn = (NewArray) obj;
if (this.values.length != insn.values.length) {
return false;
}
for (int i = 0; i < this.values.length; i++) {
if (!this.values[i].equals(insn.values[i])) {
return false;
}
}
return this.size.equals(insn.size) && this.type.equals(insn.type);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.size.hashCode();
h = h * 37 + this.type.hashCode();
for (Instruction insn : this.values) {
h = h * 37 + insn.hashCode();
}
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/var/ArrayAccess.java | src/main/java/org/spongepowered/despector/ast/insn/var/ArrayAccess.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.var;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* Loads an array value from a value.
*
* <p>Example: local[0]</p>
*/
public class ArrayAccess implements Instruction {
private Instruction array;
private Instruction index;
private TypeSignature component = null;
public ArrayAccess(Instruction array, Instruction index) {
this.array = checkNotNull(array, "array");
this.index = checkNotNull(index, "index");
}
/**
* Gets the instruction providing the array object.
*/
public Instruction getArrayVar() {
return this.array;
}
/**
* Sets the instruction providing the array object.
*/
public void setArrayVar(Instruction array) {
this.array = checkNotNull(array, "array");
this.component = null;
}
/**
* Gets the instruction providing the array index.
*/
public Instruction getIndex() {
return this.index;
}
/**
* Sets the instruction providing the array index.
*/
public void setIndex(Instruction index) {
this.index = checkNotNull(index, "index");
}
@Override
public TypeSignature inferType() {
if (this.component == null) {
this.component = TypeSignature.getArrayComponent(this.array.inferType());
}
return this.component;
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitArrayAccess(this);
this.array.accept(visitor);
this.index.accept(visitor);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(3);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_ARRAY_ACCESS);
pack.writeString("array");
this.array.writeTo(pack);
pack.writeString("index");
this.index.writeTo(pack);
pack.endMap();
}
@Override
public String toString() {
return this.array + "[" + this.index + "]";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ArrayAccess)) {
return false;
}
ArrayAccess insn = (ArrayAccess) obj;
return this.array.equals(insn.array) && this.index.equals(insn.index);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.array.hashCode();
h = h * 37 + this.index.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/var/package-info.java | src/main/java/org/spongepowered/despector/ast/insn/var/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.insn.var;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/var/LocalAccess.java | src/main/java/org/spongepowered/despector/ast/insn/var/LocalAccess.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.var;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.Locals.LocalInstance;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction for accessing a local.
*/
public class LocalAccess implements Instruction {
private LocalInstance local;
public LocalAccess(LocalInstance local) {
this.local = checkNotNull(local, "local");
}
/**
* Gets the {@link LocalInstance} accessed.
*/
public LocalInstance getLocal() {
return this.local;
}
/**
* Sets the {@link LocalInstance} accessed.
*/
public void setLocal(LocalInstance local) {
this.local = checkNotNull(local, "local");
}
@Override
public TypeSignature inferType() {
return this.local.getType();
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitLocalAccess(this);
((InstructionVisitor) visitor).visitLocalInstance(this.local);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(2);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_LOCAL_ACCESS);
pack.writeString("local");
this.local.writeToSimple(pack);
pack.endMap();
}
@Override
public String toString() {
return this.local.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof LocalAccess)) {
return false;
}
LocalAccess insn = (LocalAccess) obj;
return this.local.equals(insn.local);
}
@Override
public int hashCode() {
return this.local.hashCode();
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/var/InstanceFieldAccess.java | src/main/java/org/spongepowered/despector/ast/insn/var/InstanceFieldAccess.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.var;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction for accessing a field from an object.
*/
public class InstanceFieldAccess extends FieldAccess {
protected Instruction owner;
public InstanceFieldAccess(String name, TypeSignature desc, String owner_type, Instruction owner) {
super(name, desc, owner_type);
this.owner = checkNotNull(owner, "owner");
}
/**
* Gets the object the field is referenced from.
*/
public Instruction getFieldOwner() {
return this.owner;
}
/**
* Sets the object the field is referenced from.
*/
public void setFieldOwner(Instruction owner) {
this.owner = checkNotNull(owner, "owner");
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitInstanceFieldAccess(this);
this.owner.accept(visitor);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(5);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_INSTANCE_FIELD_ACCESS);
pack.writeString("name").writeString(this.field_name);
pack.writeString("desc");
this.field_desc.writeTo(pack);
pack.writeString("owner").writeString(this.owner_type);
pack.writeString("owner_val");
this.owner.writeTo(pack);
pack.endMap();
}
@Override
public String toString() {
return this.owner + "." + this.field_name;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof InstanceFieldAccess)) {
return false;
}
InstanceFieldAccess insn = (InstanceFieldAccess) obj;
return this.field_desc.equals(insn.field_desc) && this.field_name.equals(insn.field_name) && this.owner_type.equals(insn.owner_type)
&& this.owner.equals(insn.owner);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.field_desc.hashCode();
h = h * 37 + this.field_name.hashCode();
h = h * 37 + this.owner_type.hashCode();
h = h * 37 + this.owner.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/var/StaticFieldAccess.java | src/main/java/org/spongepowered/despector/ast/insn/var/StaticFieldAccess.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.var;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.TypeHelper;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction for accessing a static field.
*/
public class StaticFieldAccess extends FieldAccess {
public StaticFieldAccess(String name, TypeSignature desc, String owner) {
super(name, desc, owner);
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitStaticFieldAccess(this);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_STATIC_FIELD_ACCESS);
pack.writeString("name").writeString(this.field_name);
pack.writeString("desc");
this.field_desc.writeTo(pack);
pack.writeString("owner").writeString(this.owner_type);
pack.endMap();
}
@Override
public String toString() {
return TypeHelper.descToTypeName(this.owner_type) + "." + this.field_name;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof StaticFieldAccess)) {
return false;
}
StaticFieldAccess insn = (StaticFieldAccess) obj;
return this.field_desc.equals(insn.field_desc) && this.field_name.equals(insn.field_name) && this.owner_type.equals(insn.owner_type);
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.field_desc.hashCode();
h = h * 37 + this.field_name.hashCode();
h = h * 37 + this.owner_type.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/var/FieldAccess.java | src/main/java/org/spongepowered/despector/ast/insn/var/FieldAccess.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.var;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.util.TypeHelper;
/**
* An instruction which loads a value from a field.
*/
public abstract class FieldAccess implements Instruction {
protected String field_name;
protected TypeSignature field_desc;
protected String owner_type;
public FieldAccess(String name, TypeSignature desc, String owner) {
this.field_name = checkNotNull(name, "name");
this.field_desc = checkNotNull(desc, "desc");
this.owner_type = checkNotNull(owner, "owner");
}
/**
* Gets the accessed field name.
*/
public String getFieldName() {
return this.field_name;
}
/**
* Sets the accessed field name.
*/
public void setFieldName(String name) {
this.field_name = checkNotNull(name, "name");
}
/**
* Gets the accessed field descriptor.
*/
public TypeSignature getTypeDescriptor() {
return this.field_desc;
}
/**
* Sets the accessed field descriptor.
*/
public void setTypeDescriptor(TypeSignature desc) {
this.field_desc = checkNotNull(desc, "desc");
}
/**
* Gets the accessed field owner's type.
*/
public String getOwnerType() {
return this.owner_type;
}
/**
* Sets the accessed field owner's type.
*/
public void setOwnerType(String owner) {
this.owner_type = checkNotNull(owner, "owner");
}
/**
* Gets the accessed field owner's internal name.
*/
public String getOwnerName() {
return TypeHelper.descToType(this.owner_type);
}
@Override
public TypeSignature inferType() {
return this.field_desc;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/op/NegativeOperator.java | src/main/java/org/spongepowered/despector/ast/insn/op/NegativeOperator.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.op;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An instruction which negates the current value on the stack.
*/
public class NegativeOperator implements Instruction {
private Instruction val;
public NegativeOperator(Instruction val) {
this.val = checkNotNull(val, "val");
}
/**
* Gets the operand that this unary operator is operating on.
*/
public Instruction getOperand() {
return this.val;
}
/**
* Sets the operand that this unary operator is operating on.
*/
public void setOperand(Instruction insn) {
this.val = checkNotNull(insn, "val");
}
@Override
public TypeSignature inferType() {
return this.val.inferType();
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitNegativeOperator(this);
this.val.accept(visitor);
}
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(2);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_NEGATIVE_OPERATOR);
pack.writeString("val");
this.val.writeTo(pack);
pack.endMap();
}
@Override
public String toString() {
return "-(" + this.val.toString() + ")";
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/op/package-info.java | src/main/java/org/spongepowered/despector/ast/insn/op/package-info.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.spongepowered.despector.util.NonnullByDefault
package org.spongepowered.despector.ast.insn.op;
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/op/Operator.java | src/main/java/org/spongepowered/despector/ast/insn/op/Operator.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.op;
import static com.google.common.base.Preconditions.checkNotNull;
import org.spongepowered.despector.ast.AstVisitor;
import org.spongepowered.despector.ast.generic.ClassTypeSignature;
import org.spongepowered.despector.ast.generic.TypeSignature;
import org.spongepowered.despector.ast.insn.Instruction;
import org.spongepowered.despector.ast.insn.InstructionVisitor;
import org.spongepowered.despector.util.serialization.AstSerializer;
import org.spongepowered.despector.util.serialization.MessagePacker;
import java.io.IOException;
/**
* An abstract instruction arg for binary operator.
*/
public class Operator implements Instruction {
private static final String PRIMATIVE_ORDERING = "ZBCSIJFD";
protected OperatorType operator;
protected Instruction left;
protected Instruction right;
public Operator(OperatorType type, Instruction left, Instruction right) {
this.operator = checkNotNull(type, "operator");
this.left = checkNotNull(left, "left");
this.right = checkNotNull(right, "right");
}
public OperatorType getOperator() {
return this.operator;
}
public void setOperator(OperatorType type) {
this.operator = checkNotNull(type, "operator");
}
/**
* Gets the left operand.
*/
public Instruction getLeftOperand() {
return this.left;
}
/**
* Sets the left operand.
*/
public void setLeftOperand(Instruction left) {
this.left = checkNotNull(left, "left");
}
/**
* Gets the right operand.
*/
public Instruction getRightOperand() {
return this.right;
}
/**
* Sets the right operand.
*/
public void setRightOperand(Instruction right) {
this.right = checkNotNull(right, "right");
}
@Override
public void accept(AstVisitor visitor) {
if (visitor instanceof InstructionVisitor) {
((InstructionVisitor) visitor).visitOperator(this);
this.left.accept(visitor);
this.right.accept(visitor);
}
}
@Override
public TypeSignature inferType() {
int left_index = PRIMATIVE_ORDERING.indexOf(this.left.inferType().toString().charAt(0));
int right_index = PRIMATIVE_ORDERING.indexOf(this.right.inferType().toString().charAt(0));
return ClassTypeSignature.of(String.valueOf(PRIMATIVE_ORDERING.charAt(Math.max(left_index, right_index))));
}
@Override
public void writeTo(MessagePacker pack) throws IOException {
pack.startMap(4);
pack.writeString("id").writeInt(AstSerializer.STATEMENT_ID_OPERATOR);
pack.writeString("left");
this.left.writeTo(pack);
pack.writeString("right");
this.right.writeTo(pack);
pack.writeString("operator").writeInt(this.operator.ordinal());
pack.endMap();
}
@Override
public String toString() {
return this.left.toString() + " " + this.operator.getSymbol() + " " + this.right.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!getClass().equals(obj.getClass())) {
return false;
}
Operator insn = (Operator) obj;
return this.left.equals(insn.left) && this.right.equals(insn.right) && this.operator == insn.operator;
}
@Override
public int hashCode() {
int h = 1;
h = h * 37 + this.left.hashCode();
h = h * 37 + this.right.hashCode();
h = h * 37 + this.operator.hashCode();
return h;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Despector/Despector | https://github.com/Despector/Despector/blob/e60cfaaf7a0688bc83f8b00c392521d0b162afba/src/main/java/org/spongepowered/despector/ast/insn/op/OperatorType.java | src/main/java/org/spongepowered/despector/ast/insn/op/OperatorType.java | /*
* The MIT License (MIT)
*
* Copyright (c) Despector <https://despector.voxelgenesis.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.despector.ast.insn.op;
/**
* An enumeration of all operators.
*/
public enum OperatorType {
ADD(11, "+"),
SUBTRACT(11, "-"),
MULTIPLY(12, "*"),
DIVIDE(12, "/"),
REMAINDER(12, "%"),
SHIFT_LEFT(10, "<<"),
SHIFT_RIGHT(10, ">>"),
UNSIGNED_SHIFT_RIGHT(10, ">>>"),
AND(7, "&"),
OR(5, "|"),
XOR(6, "^");
private final String symbol;
private final int precedence;
OperatorType(int p, String s) {
this.precedence = p;
this.symbol = s;
}
public String getSymbol() {
return this.symbol;
}
public int getPrecedence() {
return this.precedence;
}
}
| java | MIT | e60cfaaf7a0688bc83f8b00c392521d0b162afba | 2026-01-05T02:42:07.381192Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.