Skip to content

Commit

Permalink
Doc Plugin for jppm, imrpove parser ext, improve module class, fix bu…
Browse files Browse the repository at this point in the history
…g in jphp runtime.
  • Loading branch information
dim-s committed Apr 25, 2018
1 parent 5592cb2 commit 24fa2ad
Show file tree
Hide file tree
Showing 25 changed files with 1,055 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void onRegister(CompileScope scope) {
registerClass(scope, MethodRecord.class);
registerClass(scope, NamespaceRecord.class);
registerClass(scope, ModuleRecord.class);
registerClass(scope, PropertyRecord.class);
registerClass(scope, UseImportRecord.class);

registerClass(scope, SourceWriter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void setNamespace(String namespace) {

@Getter
public String getNamespace() {
if (getName() == null) return null;

String[] tmp = StringUtils.split(getName(), Information.NAMESPACE_SEP_CHAR);

if (tmp.length > 1) {
Expand All @@ -90,6 +92,8 @@ public void setShortName(String name) {

@Getter
public String getShortName() {
if (getName() == null) return null;

String[] tmp = StringUtils.split(getName(), Information.NAMESPACE_SEP_CHAR);

if (tmp.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.develnext.jphp.parser.classes;

import java.util.LinkedHashMap;
import org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken;
import org.develnext.jphp.parser.ParserExtension;
import php.runtime.annotation.Reflection.*;
Expand All @@ -18,8 +19,9 @@ public enum Type { CLASS, INTERFACE, TRAIT }
protected ClassRecord parent;
protected boolean shortParentName = false;

protected Map<String, ClassRecord> interfaces;
protected Map<String, MethodRecord> methodRecords;
protected Map<String, ClassRecord> interfaces = new LinkedHashMap<>();
protected Map<String, MethodRecord> methodRecords = new LinkedHashMap<>();
protected Map<String, PropertyRecord> propertyRecords = new LinkedHashMap<>();

protected Type type = Type.CLASS;

Expand Down Expand Up @@ -109,16 +111,35 @@ public void addMethod(MethodRecord record) {
methodRecords.put(record.getName().toLowerCase(), record);
}

@Signature
@Name("addProperty")
public void addClassVar(PropertyRecord record) {
record.setClassRecord(this);
propertyRecords.put(record.getName(), record);
}

@Signature
public boolean hasMethod(String name) {
return methodRecords.containsKey(name.toLowerCase());
}

@Signature
@Name("hasProperty")
public boolean hasClassVar(String name) {
return methodRecords.containsKey(name.toLowerCase());
}

@Signature
public MethodRecord getMethod(String name) {
return methodRecords.get(name);
}

@Signature
@Name("getProperty")
public PropertyRecord getClassVar(String name) {
return propertyRecords.get(name);
}

@Signature
public void removeMethod(String name) {
MethodRecord record = methodRecords.remove(name.toLowerCase());
Expand All @@ -130,6 +151,12 @@ public Collection<MethodRecord> getMethods() {
return methodRecords.values();
}

@Signature
@Name("getProperties")
public Collection<PropertyRecord> getClassVars() {
return propertyRecords.values();
}

@Override
@Signature
public void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class MethodRecord extends AbstractSourceRecord<FunctionStmtToken> {
protected NamespaceRecord namespaceRecord;
protected ClassRecord classRecord;
protected BodyRecord body;
protected boolean isStatic;
protected boolean isFinal;
protected boolean isAbstract;

public MethodRecord(Environment env, ClassEntity clazz) {
super(env, clazz);
Expand Down Expand Up @@ -49,4 +52,34 @@ public NamespaceRecord getNamespaceRecord() {
public void setNamespaceRecord(NamespaceRecord namespaceRecord) {
this.namespaceRecord = namespaceRecord;
}

@Getter
public boolean isStatic() {
return isStatic;
}

@Setter
public void setStatic(boolean aStatic) {
isStatic = aStatic;
}

@Getter
public boolean isFinal() {
return isFinal;
}

@Setter
public void setFinal(boolean aFinal) {
isFinal = aFinal;
}

@Getter
public boolean isAbstract() {
return isAbstract;
}

@Setter
public void setAbstract(boolean anAbstract) {
isAbstract = anAbstract;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.develnext.jphp.core.tokenizer.Tokenizer;
import org.develnext.jphp.core.tokenizer.token.stmt.*;
import org.develnext.jphp.parser.ParserExtension;
import php.runtime.Memory;
import php.runtime.annotation.Reflection.Namespace;
import php.runtime.annotation.Reflection.Signature;
import php.runtime.env.Environment;
import php.runtime.memory.ArrayMemory;
import php.runtime.reflection.ClassEntity;

import java.util.Collection;
Expand All @@ -29,6 +31,36 @@ public Collection<NamespaceRecord> getNamespaces() {
return namespaces.values();
}

@Signature
public Memory getClasses() {
ArrayMemory result = ArrayMemory.createHashed();

for (NamespaceRecord record : namespaces.values()) {
Collection<ClassRecord> classes = record.getClasses();

for (ClassRecord aClass : classes) {
result.put(aClass.getName(), aClass);
}
}

return result.toConstant();
}

@Signature
public Memory getFunctions() {
ArrayMemory result = ArrayMemory.createHashed();

for (NamespaceRecord record : namespaces.values()) {
Collection<MethodRecord> functions = record.getFunctions();

for (MethodRecord function : functions) {
result.put(function.getName(), function);
}
}

return result.toConstant();
}

@Signature
public ClassRecord findClass(String name) {
for (NamespaceRecord record : namespaces.values()) {
Expand All @@ -42,6 +74,11 @@ public ClassRecord findClass(String name) {
return null;
}

@Signature
public MethodRecord findFunction(String name) {
return findMethod(name);
}

@Signature
public MethodRecord findMethod(String name) {
for (NamespaceRecord record : namespaces.values()) {
Expand Down Expand Up @@ -87,10 +124,20 @@ public ClassRecord synchronize(Environment env, ClassStmtToken token, Tokenizer
classRecord.setName(token.getFulledName());
classRecord.setIsAbstract(token.isAbstract());

if (token.getExtend() != null) {
ClassRecord parent = new ClassRecord(env);
parent.setName(token.getExtend().getName().getName());
classRecord.setParent(parent);
}

for (MethodStmtToken methodStmtToken : token.getMethods()) {
synchronize(env, methodStmtToken, classRecord, tokenizer);
}

for (ClassVarStmtToken varStmtToken : token.getProperties()) {
synchronize(env, varStmtToken, classRecord, tokenizer);
}

namespaceRecord.addClass(classRecord);

return classRecord;
Expand All @@ -112,6 +159,21 @@ public void synchronize(Environment env, FunctionStmtToken token, Tokenizer toke
namespace.addFunction(methodRecord);
}

public void synchronize(Environment env, ClassVarStmtToken varStmtToken, ClassRecord classRecord, Tokenizer tokenizer) {
PropertyRecord classVar = classRecord.getClassVar(varStmtToken.getVariable().getName());

if (classVar == null) {
classVar = new PropertyRecord(env);
classVar.setToken(varStmtToken);
}

classVar.setName(varStmtToken.getVariable().getName());
classVar.setComment(varStmtToken.getDocComment().getComment());
classVar.setStatic(varStmtToken.isStatic());

classRecord.addClassVar(classVar);
}

public void synchronize(Environment env, MethodStmtToken token, ClassRecord classRecord, Tokenizer tokenizer) {
MethodRecord methodRecord = classRecord.getMethod(token.getName().getName());

Expand All @@ -122,6 +184,9 @@ public void synchronize(Environment env, MethodStmtToken token, ClassRecord clas

methodRecord.setName(token.getName().getName());
methodRecord.setComment(token.getDocComment().getComment());
methodRecord.setStatic(token.isStatic());
methodRecord.setAbstract(token.isAbstract());
methodRecord.setFinal(token.isFinal());

classRecord.addMethod(methodRecord);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.develnext.jphp.parser.classes;

import org.develnext.jphp.parser.ParserExtension;
import php.runtime.Memory;
import php.runtime.annotation.Reflection.Getter;
import php.runtime.annotation.Reflection.Namespace;
import php.runtime.annotation.Reflection.Setter;
import php.runtime.env.Environment;
import php.runtime.lang.BaseObject;
import php.runtime.reflection.ClassEntity;

@Namespace(ParserExtension.NS)
public class PropertyRecord extends AbstractSourceRecord {
private String name;
protected ClassRecord classRecord;
protected boolean isStatic;

public PropertyRecord(Environment env) {
super(env);
}

public PropertyRecord(Environment env, ClassEntity clazz) {
super(env, clazz);
}

@Getter
public ClassRecord getClassRecord() {
return classRecord;
}

@Setter
public void setClassRecord(ClassRecord classRecord) {
this.classRecord = classRecord;
}

@Getter
public String getName() {
return name;
}

@Setter
public void setName(String name) {
this.name = name;
}

@Getter
public boolean isStatic() {
return isStatic;
}

@Setter
public void setStatic(boolean aStatic) {
isStatic = aStatic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ abstract class AbstractSourceRecord
*/
public $namespace;

/**
* @var string
*/
public $comment;

/**
* Remove all data.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class ClassRecord extends AbstractSourceRecord
*/
public $shortParentName = false;

/**
* @var bool
*/
public $abstract = false;

/**
* @param ClassRecord $record
*/
Expand All @@ -41,6 +46,13 @@ public function addMethod(MethodRecord $method)
{
}

/**
* @param PropertyRecord $property
*/
public function addProperty(PropertyRecord $property)
{
}

/**
* @param $name
* @return MethodRecord
Expand All @@ -49,6 +61,8 @@ public function getMethod($name)
{
}

public function getProperty(string $name): PropertyRecord {}

/**
* @param $name
*/
Expand All @@ -62,4 +76,11 @@ public function removeMethod($name)
public function getMethods()
{
}

/**
* @return PropertyRecord[]
*/
public function getProperties(): array
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ class MethodRecord extends AbstractSourceRecord
* @var NamespaceRecord
*/
public $classRecord;

/**
* @var bool
*/
public $static = false;

/**
* @var bool
*/
public $final = false;

/**
* @var bool
*/
public $abstract = false;
}
Loading

0 comments on commit 24fa2ad

Please sign in to comment.