use of php.runtime.common.Function in project jphp by jphp-compiler.
the class ClassStmtCompiler method writeCopiedMethod.
protected void writeCopiedMethod(ClassStmtToken.Alias alias, String methodName, ClassEntity trait) {
final MethodEntity methodEntity = fetchClassAndCheck(alias.getTrait()).findMethod(methodName.toLowerCase());
String name = alias.getName();
if (name == null)
name = methodName;
MethodEntity origin = entity.findMethod(name.toLowerCase());
if (origin != null) {
if (origin.getClazz() == entity) {
if (origin.getTrait() != null) {
compiler.getEnvironment().error(entity.getTrace(), Messages.ERR_TRAIT_METHOD_COLLISION.fetch(methodName, trait.getName(), origin.getTrait().getName(), entity.getName()));
}
return;
}
}
if (methodEntity == null) {
compiler.getEnvironment().error(entity.getTrace(), Messages.ERR_METHOD_NOT_FOUND.fetch(alias.getTrait(), methodName));
return;
}
MethodEntity dup = methodEntity.duplicateForInject();
dup.setClazz(entity);
dup.setTrait(trait);
if (alias.getName() != null)
dup.setName(alias.getName());
if (alias.getModifier() != null)
dup.setModifier(alias.getModifier());
MethodNodeImpl methodNode = MethodNodeImpl.duplicate(methodEntity.getAdditionalData("methodNode", MethodNode.class, new Function<MethodNode>() {
@Override
public MethodNode call() {
ClassNode classNode = methodEntity.getClazz().getAdditionalData("classNode", ClassNode.class, new Function<ClassNode>() {
@Override
public ClassNode call() {
ClassReader classReader;
if (methodEntity.getClazz().getData() != null)
classReader = new ClassReader(methodEntity.getClazz().getData());
else {
try {
classReader = new ClassReader(methodEntity.getClazz().getName());
} catch (IOException e) {
throw new CriticalException(e);
}
}
ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
return classNode;
}
});
for (Object m : classNode.methods) {
MethodNode method = (MethodNode) m;
if (method.name.equals(methodEntity.getInternalName())) {
return method;
}
}
throw new CriticalException("Cannot find MethodNode for method - " + methodEntity.getName() + "(" + methodEntity.getSignatureString(true) + ")");
}
}));
if (origin != null) {
dup.setPrototype(origin);
}
dup.setInternalName(dup.getName() + "$" + entity.nextMethodIndex());
methodNode.name = dup.getInternalName();
ClassEntity.SignatureResult result = entity.addMethod(dup, null);
result.check(compiler.getEnvironment());
node.methods.add(methodNode);
}
use of php.runtime.common.Function in project jphp by jphp-compiler.
the class JTreeXEventProvider method register.
@Override
public void register(final Environment env, final JTreeX component, final ComponentProperties properties) {
final ObjectMemory self = new ObjectMemory(new UITree(env, component));
component.getContent().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
trigger(env, properties, "selected", new Function<Memory[]>() {
@Override
public Memory[] call() {
Memory oldNode = Memory.NULL;
if (e.getOldLeadSelectionPath() != null) {
oldNode = new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) e.getOldLeadSelectionPath().getLastPathComponent()));
}
Memory node = Memory.NULL;
if (e.getNewLeadSelectionPath() != null) {
node = new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) e.getNewLeadSelectionPath().getLastPathComponent()));
}
return new Memory[] { self, node, oldNode, TrueMemory.valueOf(e.isAddedPath()) };
}
});
}
});
component.getContent().addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(final TreeExpansionEvent event) {
trigger(env, properties, "willExpand", new Function<Memory[]>() {
@Override
public Memory[] call() {
return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
}
});
}
@Override
public void treeWillCollapse(final TreeExpansionEvent event) {
trigger(env, properties, "willCollapse", new Function<Memory[]>() {
@Override
public Memory[] call() {
return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
}
});
}
});
component.getContent().addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(final TreeExpansionEvent event) {
trigger(env, properties, "expanded", new Function<Memory[]>() {
@Override
public Memory[] call() {
return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
}
});
}
@Override
public void treeCollapsed(final TreeExpansionEvent event) {
trigger(env, properties, "collapsed", new Function<Memory[]>() {
@Override
public Memory[] call() {
return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
}
});
}
});
}
Aggregations