Skip to content

Commit

Permalink
GH-532 Rename public visibility to open (Resolve #532)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Jul 7, 2020
1 parent 0b9ae3b commit 3d1f1c4
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/package_manager/panda.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ scripts: {
}

dependencies: [
github:dzikoysk/[email protected].3
github:dzikoysk/[email protected].4
]

6 changes: 3 additions & 3 deletions examples/tests/current_test.panda
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ internal class Entity {
// random Test class
internal class Test {

// public static field INDEX with assigned value
public static Int INDEX = 1
// open static field INDEX with assigned value
open static Int INDEX = 1

// shared between submodules field
shared Test testField
Expand All @@ -245,7 +245,7 @@ internal class Test {
}

// static field that creates instance of the current class
public static Test TEST = new Test('Static initialization of class instance')
open static Test TEST = new Test('Static initialization of class instance')

shared echo (Object message3) {
log message3
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/test-local-module/app.panda
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module test-local-module

public class LocalModuleClass {
open type LocalModuleClass {

public static hello() {
open static hello() {
log 'Local Module Class'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum Visibility {
/**
* May be accessed anywhere
*/
PUBLIC(0),
OPEN(0),
/**
* May be accessed from the associated module and its submodules
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public abstract static class PandaParametrizedExecutableBuilder<E extends Execut
protected Type type;
protected Location location;
protected TypeExecutableCallback<E, Object> callback;
protected Visibility visibility = Visibility.PUBLIC;
protected Visibility visibility = Visibility.OPEN;
protected PropertyParameter[] parameters = ParameterUtils.PARAMETERLESS;
protected boolean isNative;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PandaTypeMetadata<BUILDER extends PandaTypeMetadata<BUILDER, ?>, TY
protected Class<?> javaType;
protected String model = TypeModels.CLASS;
protected State state = State.DEFAULT;
protected Visibility visibility = Visibility.PUBLIC;
protected Visibility visibility = Visibility.OPEN;
protected boolean isNative;

protected PandaTypeMetadata() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Type of(Module module, String name, Class<?> javaType) {
.name(name)
.module(module)
.javaType(javaType)
.visibility(Visibility.PUBLIC)
.visibility(Visibility.OPEN)
.state(State.DEFAULT)
.model(javaType.isInterface() ? TypeModels.INTERFACE : TypeModels.CLASS)
.location(new PandaClassSource(javaType).toLocation())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ArrayType(Module module, String name, Class<?> associated, Type type) {
.javaType(associated)
.model(type.getModel())
.state(type.getState())
.visibility(Visibility.PUBLIC)
.visibility(Visibility.OPEN)
);

this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected Type generate(Module module, String name, Class<?> javaType) {
.location(new PandaClassSource(javaType).toLocation())
.model(TypeModels.of(javaType))
.state(State.of(javaType))
.visibility(Visibility.PUBLIC)
.visibility(Visibility.OPEN)
.build();

type.addInitializer((typeLoader, initializedType) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Option<String> canAccess(Property requested, Context context) {
}

public static Option<String> canAccess(Property requested, Module currentModule, @Nullable Source currentSource) {
if (requested.getVisibility() == Visibility.PUBLIC) {
if (requested.getVisibility() == Visibility.OPEN) {
return Option.none();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public final class Keywords {

public static final Keyword NIL = add(VALUES, new Keyword("nil"));

public static final Keyword OPEN = add(VALUES, new Keyword("open"));

public static final Keyword OVERRIDE = add(VALUES, new Keyword("override"));

public static final Keyword PUBLIC = add(VALUES, new Keyword("public"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FunctionalPatternTest {
@Test
void method() {
FunctionalPattern functionalPattern = FunctionalPattern.of(
VariantElement.create("visibility").content("public", "shared", "internal"),
VariantElement.create("visibility").content("open", "shared", "internal"),
UnitElement.create("isStatic").content("static").optional(),
TypeElement.create("type").optional().verify(new NextTokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)),
WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)),
Expand Down Expand Up @@ -76,7 +76,7 @@ void field() {
fakeContext.withComponent(Components.EXPRESSION, new PandaExpressionParser(Collections::emptyList));

FunctionalPattern pattern = FunctionalPattern.of(
VariantElement.create("visibility").content(Keywords.PUBLIC.getValue(), Keywords.SHARED.getValue(), Keywords.INTERNAL.getValue()),
VariantElement.create("visibility").content(Keywords.OPEN.getValue(), Keywords.SHARED.getValue(), Keywords.INTERNAL.getValue()),
KeywordElement.create(Keywords.STATIC).optional(),
KeywordElement.create(Keywords.MUT).optional(),
KeywordElement.create(Keywords.NIL).optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class FieldParser extends ParserBootstrap<Void> {
@Override
protected BootstrapInitializer<Void> initialize(Context context, BootstrapInitializer<Void> initializer) {
return initializer.functional(builder -> builder
.variant("visibility").consume(variant -> variant.content(Keywords.PUBLIC, Keywords.SHARED, Keywords.INTERNAL))
.variant("visibility").consume(variant -> variant.content(Keywords.OPEN, Keywords.SHARED, Keywords.INTERNAL))
.keyword(Keywords.STATIC).optional()
.keyword(Keywords.MUT).optional()
.keyword(Keywords.NIL).optional()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public final class MethodParser extends ParserBootstrap<Void> {
protected BootstrapInitializer<Void> initialize(Context context, BootstrapInitializer<Void> initializer) {
return initializer.functional(pattern -> pattern
.keyword(Keywords.OVERRIDE).optional()
.variant("visibility").optional().consume(variant -> variant.content("public", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase())))
.variant("visibility").optional().consume(variant -> variant.content("open", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase())))
.keyword(Keywords.STATIC).optional()
.wildcard("name").verifyType(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)
.section("parameters", Separators.PARENTHESIS_LEFT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected BootstrapInitializer<Void> initialize(Context context, BootstrapInitia
.handler(new FunctionalPatternHandler())
.initializer(new FunctionalPatternInitializer())
.pattern(FunctionalPattern.of(
VariantElement.create("visibility").content(Keywords.PUBLIC, Keywords.SHARED, Keywords.INTERNAL).optional(),
VariantElement.create("visibility").content(Keywords.OPEN, Keywords.SHARED, Keywords.INTERNAL).optional(),
VariantElement.create("model").content(Keywords.CLASS, Keywords.TYPE, Keywords.INTERFACE),
WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN)),
SubPatternElement.create("extended").optional().of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import org.panda_lang.panda.bootstrap.PandaApplicationBootstrap;
import org.panda_lang.panda.util.PandaUtils;
import org.panda_lang.utilities.commons.TimeUtils;
import org.panda_lang.utilities.commons.function.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.panda_lang.utilities.commons.function.Option;

public final class ExamplesLauncher {

public static void launch(String directory, String file) {
Expand Down Expand Up @@ -57,14 +56,18 @@ public static void launch(Application application) {
}

public static Application interpret(String directory, String file) {
return interpret("../examples/", directory, file);
}

public static Application interpret(String prefix, String directory, String file) {
Logger logger = LoggerFactory.getLogger(ExamplesLauncher.class);
PandaUtils.printJVMUptime(() -> logger);

PandaFactory factory = new PandaFactory();
Panda panda = factory.createPanda(logger);

Option<Application> application = PandaApplicationBootstrap.create(panda)
.workingDirectory("../examples/" + directory)
.workingDirectory(prefix + directory)
.script(file)
.createApplication();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020 Dzikoysk
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.panda_lang.panda.examples.performance;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.RunnerException;
import org.panda_lang.framework.design.architecture.Application;
import org.panda_lang.panda.examples.ExamplesLauncher;
import org.panda_lang.panda.util.BenchmarkUtils;

import java.util.concurrent.TimeUnit;

/**
* Just a preview of approximate performance to check some basic behaviours
*
* Bootstrap :: Reflection based injector
* CurrentTestBenchmark.currentTest thrpt 2 0,019 ops/ms
*
* Bootstrap :: Generated method injector
* CurrentTestBenchmark.currentTest thrpt 2 0,025 ops/ms
*
*/
@Fork(value = 1)
@Warmup(iterations = 1)
@Measurement(iterations = 2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class CurrentTestBenchmark {

@Benchmark
public Object currentTest() {
Application application = ExamplesLauncher.interpret("examples/", "tests", "current_test.panda");
return application.launch();
}

public static void main(String[] args) throws RunnerException {
BenchmarkUtils.run(CurrentTestBenchmark.class);
}

}

0 comments on commit 3d1f1c4

Please sign in to comment.