Skip to content

Commit

Permalink
GH-615 Add author name to package qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Feb 6, 2021
1 parent 87a677d commit 8c6dda7
Show file tree
Hide file tree
Showing 53 changed files with 149 additions and 118 deletions.
3 changes: 1 addition & 2 deletions examples/current-test/panda.cdn
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: current-test
version: 1.0.0
owner: dzikoysk

author: dzikoysk
sources: src
9 changes: 4 additions & 5 deletions examples/package-manager/panda-module-dependency/app.panda
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// require panda-dependency defined in the panda.cdn
require 'panda-dependency'
// require panda-dependency implementations defined in the panda.cdn
require 'dzikoysk/panda-dependency'
require 'piotrpiatyszek/panda-dependency'

main {
// print panda-dependency message
// use implementations
log PandaDependency.getMessage()

// print subdependency (defined in panda-dependency/panda.cdn) message
log LDDependency.getMessage()
}
8 changes: 2 additions & 6 deletions examples/package-manager/panda-module-dependency/panda.cdn
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
name: panda-module-dependency
version: 1.0.0
owner: dzikoysk

scripts: {
main: app.panda
}
author: dzikoysk

dependencies: [
github:dzikoysk/panda-dependency@1.0.5
github:dzikoysk/panda-dependency@master
]

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: panda-with-java-library-dependency
version: 1.0.0
owner: dzikoysk
author: dzikoysk

scripts: {
main: app.panda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public String getAuthor() {
}

public String getName() {
return getAuthor() + "/" + getSimpleName();
}

public String getSimpleName() {
return name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Packages(SourceService sourceService) {
}

public Package registerPackage(Package pkg) {
packages.put(pkg.getSimpleName(), pkg);
packages.put(pkg.getName(), pkg);
return pkg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public final class ClassGenerator {
private final Map<Type, CtClass> generatedClasses = new HashMap<>();

public CtClass allocate(Type type) {
String javaName = type.getName().replace("::", "$").replace(":", "_") + "_" + ID.incrementAndGet();
String javaName = type.getName()
.replace("/", "$")
.replace("@", "$")
.replace("::", "$")
.replace(":", "_")
+ "_" + ID.incrementAndGet();

CtClass javaType = Kind.isInterface(type)
? CLASS_POOL.makeInterface(javaName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public Reference generate(Module module, String name, Class<?> javaType) {
}

if (!javaType.equals(Object.class) && type.getBases().isEmpty()) {
// type.addAutocast(typeLoader.requireType("panda@::Object"), (originalType, object, resultType) -> object);
type.addBase(typeLoader.requireType("panda@::Object").getSignature());
// type.addAutocast(typeLoader.requireType("panda/panda@::Object"), (originalType, object, resultType) -> object);
type.addBase(typeLoader.requireType("panda/panda@::Object").getSignature());
}

if (!Modifier.isPublic(javaType.getModifiers())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Option<Signature> getAlso() {
public Type toType() {
return getAny().map(Signature::toType)
.orElse(() -> getAlso().map(Signature::toType))
.orElseGet(() -> typeLoader.requireType("panda@::Object"));
.orElseGet(() -> typeLoader.requireType("panda/panda@::Object"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@
public @interface Mappings {

/**
* Get the name of represented module
* Get associated with the module package
*
* @return the name of module
* @return the name of package
*/
String module();
String pkg();

/**
* Get associated with the module package
* Get package author
*
* @return the name of package
* @return the name of author
*/
String pkg();
String author();

/**
* Get the name of represented module
*
* @return the name of module
*/
String module();

/**
* Get associated with the module package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import java.util.Collections;

@Mappings(pkg = "panda", module = Package.DEFAULT_MODULE, commonPackage= "java.lang", classes = {
@Mappings(pkg = "panda", author = "panda", module = Package.DEFAULT_MODULE, commonPackage= "java.lang", classes = {
"Iterable"
})
public final class JavaModule implements CustomInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

public class PandaStream<T> {

private static final PandaStream<?> EMPTY = new PandaStream<>(Stream.empty());

private Stream<T> stream;

private PandaStream(Stream<T> stream) {
Expand Down Expand Up @@ -162,9 +160,8 @@ public static <T> PandaStream<T> of(T... array) {
return of(Arrays.stream(array));
}

@SuppressWarnings("unchecked")
public static <T> PandaStream<T> empty() {
return (PandaStream<T>) EMPTY;
return new PandaStream<>(Stream.empty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.panda_lang.framework.architecture.type.generator.TypeGenerator;
import org.panda_lang.framework.resource.Mappings;
import org.panda_lang.framework.resource.Mappings.CustomInitializer;
import org.panda_lang.panda.PandaConstants;
import org.panda_lang.utilities.commons.ClassUtils;
import org.panda_lang.utilities.commons.StringUtils;

Expand All @@ -45,7 +46,7 @@ private void loadClass(Packages packages, TypeGenerator typeGenerator, TypeLoade
Mappings mappingsInfo = mappings.getClass().getAnnotation(Mappings.class);

Package packageInfo = packages.getPackage(mappingsInfo.pkg())
.orElseGet(() -> packages.registerPackage(new Package(mappingsInfo.pkg(), "", "", new File("std"))));
.orElseGet(() -> packages.registerPackage(new Package(mappingsInfo.pkg(), mappingsInfo.author(), PandaConstants.VERSION, new File("mappings"))));

Module module = packageInfo.getModuleSource(mappingsInfo.module())
.orElseGet(() -> packageInfo.createModule(mappingsInfo.module()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.panda_lang.framework.resource.Mappings;

@Mappings(pkg = "java", module = "collections", commonPackage = "java.util", classes = {
@Mappings(pkg = "java", author = "panda", module = "collections", commonPackage = "java.util", classes = {
"Collection",
"Comparator",
"Deque",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.panda_lang.framework.architecture.packages.Package;
import org.panda_lang.framework.resource.Mappings;

@Mappings(pkg = "java", module = Package.DEFAULT_MODULE, commonPackage = "java.lang", classes = {
@Mappings(pkg = "java",author = "panda", module = Package.DEFAULT_MODULE, commonPackage = "java.lang", classes = {
"Class",
"Exception",
"Runtime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.panda_lang.framework.architecture.packages.Package;
import org.panda_lang.framework.resource.Mappings;

@Mappings(pkg = "java", module = Package.DEFAULT_MODULE, commonPackage = "java.util", classes = {
@Mappings(pkg = "java", author = "panda", module = Package.DEFAULT_MODULE, commonPackage = "java.util", classes = {
"Arrays",
"Objects",
"Optional",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static final class IsWorker extends AbstractExpressionSubparserWorker {
private final Type boolType;

private IsWorker(Context<?> context) {
this.boolType = context.getTypeLoader().requireType("panda@::Bool");
this.boolType = context.getTypeLoader().requireType("panda/panda@::Bool");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static final class SequenceWorker extends AbstractExpressionSubparserWor
private final Signature boolType;

public SequenceWorker(Context<?> context) {
this.boolType = context.getTypeLoader().requireType("panda@::Bool").getSignature();
this.boolType = context.getTypeLoader().requireType("panda/panda@::Bool").getSignature();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class NegateLogicalExpression implements DynamicExpression {
private final Expression logicalExpression;

public NegateLogicalExpression(Expression logicalExpression) {
if (!logicalExpression.getKnownType().is("panda@::Bool")) {
if (!logicalExpression.getKnownType().is("panda/panda@::Bool")) {
throw new InvalidParameterException("Cannot reverse non logical value");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static final class SequenceWorker extends AbstractExpressionSubparserWor
private final Type stringType;

private SequenceWorker(Context<?> context) {
this.stringType = context.getTypeLoader().requireType("panda@::String");
this.stringType = context.getTypeLoader().requireType("panda/panda@::String");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static final class NegateWorker extends AbstractExpressionSubparserWorke

Expression expression = context.getParser().parse(context.toContext(), context.getSynchronizedSource(), SETTINGS);

if (!context.toContext().getTypeLoader().requireType("panda@::Number").isAssignableFrom(expression.getKnownType())) {
if (!context.toContext().getTypeLoader().requireType("panda/panda@::Number").isAssignableFrom(expression.getKnownType())) {
throw new InvalidParameterException("Cannot reverse non logical value");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static final class NegateWorker extends AbstractExpressionSubparserWorke

Expression expression = context.getParser().parse(context.toContext(), context.getSynchronizedSource(), SETTINGS);

if (!context.toContext().getTypeLoader().requireType("panda@::Number").isAssignableFrom(expression.getKnownType())) {
if (!context.toContext().getTypeLoader().requireType("panda/panda@::Number").isAssignableFrom(expression.getKnownType())) {
throw new InvalidParameterException("Cannot reverse non logical value");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ else if (number.length() < 16) {

switch (numberType) {
case BYTE:
return new PandaExpression(loader.requireType("panda@::Byte").getSignature(), Byte.parseByte(number, radix));
return new PandaExpression(loader.requireType("panda/panda@::Byte").getSignature(), Byte.parseByte(number, radix));
case SHORT:
return new PandaExpression(loader.requireType("panda@::Short").getSignature(), Short.parseShort(number, radix));
return new PandaExpression(loader.requireType("panda/panda@::Short").getSignature(), Short.parseShort(number, radix));
case INT:
return new PandaExpression(loader.requireType("panda@::Int").getSignature(), Integer.parseInt(number, radix));
return new PandaExpression(loader.requireType("panda/panda@::Int").getSignature(), Integer.parseInt(number, radix));
case LONG:
return new PandaExpression(loader.requireType("panda@::Long").getSignature(), Long.parseLong(number, radix));
return new PandaExpression(loader.requireType("panda/panda@::Long").getSignature(), Long.parseLong(number, radix));
case FLOAT:
return new PandaExpression(loader.requireType("panda@::Float").getSignature(), Float.parseFloat(number));
return new PandaExpression(loader.requireType("panda/panda@::Float").getSignature(), Float.parseFloat(number));
case DOUBLE:
return new PandaExpression(loader.requireType("panda@::Double").getSignature(), Double.parseDouble(number));
return new PandaExpression(loader.requireType("panda/panda@::Double").getSignature(), Double.parseDouble(number));
default:
throw new PandaParserException("Unknown number type: " + numberType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public class NumberPriorities {
public static final int DOUBLE = 60;

private static final Map<String, Integer> HIERARCHY = Maps.of(
"panda@::Byte", BYTE,
"panda@::Short", SHORT,
"panda@::Int", INT,
"panda@::Long", LONG,
"panda@::Float", FLOAT,
"panda@::Double", DOUBLE
"panda/panda@::Byte", BYTE,
"panda/panda@::Short", SHORT,
"panda/panda@::Int", INT,
"panda/panda@::Long", LONG,
"panda/panda@::Float", FLOAT,
"panda/panda@::Double", DOUBLE
);

public static int getHigherPriority(Type a, Type b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

public final class PandaNumbers {

public static final String BYTE = "panda@::Byte";
public static final String BYTE = "panda/panda@::Byte";

public static final String INT = "panda@::Int";
public static final String INT = "panda/panda@::Int";

public static final String SHORT = "panda@::Short";
public static final String SHORT = "panda/panda@::Short";

public static final String LONG = "panda@::Long";
public static final String LONG = "panda/panda@::Long";

public static final String FLOAT = "panda@::Float";
public static final String FLOAT = "panda/panda@::Float";

public static final String DOUBLE = "panda@::Double";
public static final String DOUBLE = "panda/panda@::Double";

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static boolean isNumeric(Operation operation) {
return verify(operation, null, element -> {
if (element.isExpression()) {
Type expressionType = element.getExpression().getKnownType();
return expressionType.getTypeLoader().get().requireType("panda@::Number").isAssignableFrom(expressionType);
return expressionType.getTypeLoader().get().requireType("panda/panda@::Number").isAssignableFrom(expressionType);
}

Operator operator = ObjectUtils.cast(Operator.class, element.getOperatorRepresentation().getToken());
Expand All @@ -60,7 +60,7 @@ static boolean isConcatenation(Operation operation) {
operator = Operators.ADDITION.equals(element.getOperator());
}
else if (!string && element.isExpression()) {
string = element.getExpression().getKnownType().is("panda@::String");
string = element.getExpression().getKnownType().is("panda/panda@::String");
}

if (operator && string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class ConcatenationOperatorSubparser implements OperationSubparser
return null;
}

Type stringType = context.getTypeLoader().requireType("panda@::String");
Type stringType = context.getTypeLoader().requireType("panda/panda@::String");
return new ConcatenationExpressionCallback(stringType, values).toExpression();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Type returnType(TypeLoader typeLoader, Type a, Type b) {

@Override
public Type requiredType(TypeLoader typeLoader) {
return typeLoader.requireType("panda@::Number");
return typeLoader.requireType("panda/panda@::Number");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public RPNOperationAction<Boolean> of(TypeLoader typeLoader, Expression a, Expre

@Override
public Type returnType(TypeLoader typeLoader, Type a, Type b) {
return typeLoader.requireType("panda@::Bool");
return typeLoader.requireType("panda/panda@::Bool");
}

@Override
public Type requiredType(TypeLoader typeLoader) {
return typeLoader.requireType("panda@::Number");
return typeLoader.requireType("panda/panda@::Number");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected ComparisonOperatorAction(Expression a, Expression b) {

@Override
public Signature returnType(TypeLoader typeLoader) {
return typeLoader.requireType("panda@::Bool").getSignature();
return typeLoader.requireType("panda/panda@::Bool").getSignature();
}

}
Loading

0 comments on commit 8c6dda7

Please sign in to comment.