Search in sources :

Example 1 with ArrayList

use of dyvil.collection.mutable.ArrayList in project Dyvil by Dyvil.

the class FileUtils method readLines.

@DyvilModifiers(Modifiers.INFIX)
@NonNull
public static List<@NonNull String> readLines(@NonNull File file) throws IOException {
    try (BufferedReader reader = Files.newBufferedReader(file.toPath())) {
        final List<String> result = new ArrayList<>();
        for (; ; ) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            result.add(line);
        }
        return result;
    }
}
Also used : BufferedReader(java.io.BufferedReader) ArrayList(dyvil.collection.mutable.ArrayList) NonNull(dyvil.annotation.internal.NonNull) DyvilModifiers(dyvil.annotation.internal.DyvilModifiers)

Example 2 with ArrayList

use of dyvil.collection.mutable.ArrayList in project Dyvil by Dyvil.

the class TestThread method getCommand.

public String[] getCommand() {
    final List<Library> libraries = this.compiler.config.libraries;
    StringBuilder classpath = new StringBuilder();
    classpath.append(this.compiler.config.getOutputDir());
    for (Library library : libraries) {
        classpath.append(':').append(library.getFile());
    }
    final List<String> command = new ArrayList<>();
    command.add("java");
    command.add("-cp");
    command.add(classpath.toString());
    command.add(this.compiler.config.getMainType());
    command.addAll(this.compiler.config.getMainArgs());
    return command.toArray(String.class);
}
Also used : ArrayList(dyvil.collection.mutable.ArrayList) Library(dyvilx.tools.compiler.library.Library)

Example 3 with ArrayList

use of dyvil.collection.mutable.ArrayList in project Dyvil by Dyvil.

the class CodeMethod method checkDuplicates.

private void checkDuplicates(MarkerList markers) {
    final Collection<IMethod> candidates = new ArrayList<>();
    this.enclosingClass.addMethods(candidates);
    if (candidates.isEmpty()) {
        return;
    }
    final String internalName = this.getInternalName();
    final String descriptor = this.getDescriptor();
    final int parameterCount = this.parameters.size();
    for (IMethod method : candidates) {
        if (// exclude this method
        method != this && // optimization
        method.getParameters().size() == parameterCount && method.getInternalName().equals(internalName) && method.getDescriptor().equals(descriptor)) {
            final Marker marker = Markers.semanticError(this.position, "method.duplicate", this.name, this.internalName, descriptor);
            markers.add(marker);
        }
    }
}
Also used : ArrayList(dyvil.collection.mutable.ArrayList) Marker(dyvilx.tools.parsing.marker.Marker)

Example 4 with ArrayList

use of dyvil.collection.mutable.ArrayList in project Dyvil by Dyvil.

the class FieldReflection method getObjects.

@NonNull
public static <T> T[] getObjects(@NonNull Class clazz, Object instance, @NonNull Class<T> fieldType, boolean subtypes) {
    List list = new ArrayList();
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        try {
            Class c = field.getType();
            Object o = field.get(instance);
            if (c == fieldType || subtypes && fieldType.isAssignableFrom(c)) {
                list.add(o);
            }
        } catch (Exception ex) {
        }
    }
    return (T[]) list.toArray();
}
Also used : Field(java.lang.reflect.Field) ArrayList(dyvil.collection.mutable.ArrayList) ArrayList(dyvil.collection.mutable.ArrayList) List(dyvil.collection.List) NonNull(dyvil.annotation.internal.NonNull)

Aggregations

ArrayList (dyvil.collection.mutable.ArrayList)4 NonNull (dyvil.annotation.internal.NonNull)2 DyvilModifiers (dyvil.annotation.internal.DyvilModifiers)1 List (dyvil.collection.List)1 Library (dyvilx.tools.compiler.library.Library)1 Marker (dyvilx.tools.parsing.marker.Marker)1 BufferedReader (java.io.BufferedReader)1 Field (java.lang.reflect.Field)1