Skip to content

Commit

Permalink
Completed inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed May 18, 2016
1 parent 47d21c8 commit 972dcf2
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 323 deletions.
7 changes: 0 additions & 7 deletions .idea/libraries/jgraphx.xml

This file was deleted.

503 changes: 228 additions & 275 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/com/devbaltasarq/pooi/core/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AppInfo {
public static final String Name = "Pooi";
public static final String Email = "jbgarcia@uvigo.es";
public static final String Author = "Baltasar García Perez-Schofield";
public static final String Version = "1.3 20160503";
public static final String Version = "1.4 2016018";

public static String getMsgVersion()
{
Expand Down
60 changes: 38 additions & 22 deletions src/com/devbaltasarq/pooi/core/ObjectBag.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.devbaltasarq.pooi.core;

import com.devbaltasarq.pooi.core.evaluables.Attribute;
import com.devbaltasarq.pooi.core.evaluables.Method;
import com.devbaltasarq.pooi.core.evaluables.ParentAttribute;
import com.devbaltasarq.pooi.core.evaluables.Reference;
import com.devbaltasarq.pooi.core.evaluables.*;
import com.devbaltasarq.pooi.core.exceps.AttributeNotFound;
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectRoot;
Expand Down Expand Up @@ -528,25 +525,28 @@ private void chkCyclesInParent(ObjectBag parent) throws InterpretError
public void set(String name, ObjectBag obj) throws InterpretError
{
final Runtime rt = Runtime.getRuntime();
Attribute atr;
Attribute atr = localLookUpAttribute( name );

// Prepare attribute along with the name
this.chkIdentifier( name );
if ( atr == null ) {
// Prepare attribute along with the name
this.chkIdentifier( name );

if ( name.equals( ParentAttribute.ParentAttributeName ) ) {
this.chkCyclesInParent( obj );
atr = new ParentAttribute( obj );
} else {
atr = new Attribute( name, obj );
}

if ( name.equals( ParentAttribute.ParentAttributeName ) ) {
this.chkCyclesInParent( obj );
atr = new ParentAttribute( obj );
// Insert the attribute
this.setAttribute( name, atr );
} else {
atr = new Attribute( name, obj );
atr.setReference( obj );
}

// Insert the attribute
this.setAttribute( name, atr );

// No longer a temporal object
if ( obj.getContainer() == rt.getLiteralsContainer() ) {
obj.setContainer( this );
obj.setName( name );
}

return;
Expand All @@ -563,19 +563,30 @@ public void set(String name, Method mth) throws InterpretError
this.setMethod( name, mth );
}

protected final void setMethod(String name, Method mth) throws InterpretError
{
if ( this.localLookUpAttribute( name ) != null ) {
throw new InterpretError( "Already have an attribute named: " + name );
/**
* Returns a member, local to this object, given a name.
* @param id A String containing the name.
* @return The member corresponding to that id, or null.
*/
public Member localLookUpMember(String id) {
Member toret = localLookUpAttribute( id );

if ( toret == null ) {
toret = localLookUpMethod( id );
}

return toret;
}

protected final void setMethod(String name, Method mth) throws InterpretError
{
this.methods.put( name, mth );
}

protected final void setAttribute(String name, Attribute atr) throws InterpretError
{
if ( this.localLookUpMethod( name ) != null ) {
throw new InterpretError( "Already have a method named: " + name );
if ( this.localLookUpMember( name ) != null ) {
throw new InterpretError( "Already a member named: '" + name + "' in: " + this.getPath() );
}

this.attributes.put( name, atr );
Expand Down Expand Up @@ -635,6 +646,11 @@ public void renameMethod(String oldName, String newName) throws InterpretError {
if ( mth != null ) {
try {
this.chkIdentifier( newName );

if ( this.localLookUpMember( newName ) != null ) {
throw new InterpretError( "there is already a member with that name: " + newName );
}

mth.setName( newName );
this.methods.remove( oldName );
this.methods.put( newName, mth );
Expand Down Expand Up @@ -845,7 +861,7 @@ public ObjectBag createChild(String name, ObjectBag container)

/**
* Removes all attributes.
* @param completely Stes whether or not eliminate all attributes.
* @param completely States whether or not eliminate all attributes.
* If set to false, the parent attribute is preserved.
*/
public void clear(boolean completely)
Expand Down
12 changes: 12 additions & 0 deletions src/com/devbaltasarq/pooi/core/evaluables/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.devbaltasarq.pooi.core.evaluables;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.evaluables.literals.StrLiteral;

/**
* The command built from absParent.mth( arg0, arg1, ...argN)
Expand Down Expand Up @@ -80,7 +81,18 @@ public String getArgumentsAsString()
StringBuilder toret = new StringBuilder();

for(Evaluable evaluable: arguments) {
boolean isStringLiteral = evaluable instanceof StrLiteral;

if ( isStringLiteral ) {
toret.append( '"' );
}

toret.append( evaluable.toString() );

if ( isStringLiteral ) {
toret.append( '"' );
}

toret.append( ' ' );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,31 @@ public String getMethodBodyAsString() {

// Add commands
for(Command cmd: this.getCmds()) {
String replaceCmd = "";
String cmdAsStr = cmd.toString();
int pos = cmdAsStr.indexOf( Parser.PopTask );

if ( cmdAsStr.indexOf( Parser.PopTask ) >= 0 ) {
if ( pos >= 0 ) {
// Process the reference
if ( cmd.getReference().toString().equals( Parser.PopTask ) ) {
cmdAsStr = cmdAsStr.replaceFirst( Parser.PopTask, stack.pop() );
replaceCmd = stack.pop();
cmdAsStr = cmdAsStr.substring( 0, pos )
+ replaceCmd
+ cmdAsStr.substring( pos + Parser.PopTask.length(), cmdAsStr.length() );
}

// Process possible targets
pos += replaceCmd.length();
pos = cmdAsStr.indexOf( Parser.PopTask, pos );
while( pos >= 0 ) {
replaceCmd = stack.pop();
cmdAsStr = cmdAsStr.substring( 0, pos )
+ replaceCmd
+ cmdAsStr.substring( pos + Parser.PopTask.length(), cmdAsStr.length() );

// Next?
pos += replaceCmd.length();
pos = cmdAsStr.indexOf( Parser.PopTask, pos );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
ref.set( id1, mth );
} else {
obj2 = rt.solveToObject( params[ 1 ] );
final boolean wasALit = ( obj2.getContainer() == rt.getLiteralsContainer() );

ref.set( id1, obj2 );

if ( wasALit ) {
obj2.setName( id1 );
}
}

msg.append( '\'' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.evaluables.Attribute;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

Expand Down Expand Up @@ -32,9 +33,11 @@ public static ObjectBag rename(ObjectBag ref, String id, StringBuilder msg)
throws InterpretError
{
final ObjectBag container = ref.getContainer();
final String oldName = ref.getName();
String oldName = ref.getName();

try {
final Attribute attr = container.localInverseLookUp( ref );
oldName = attr.getName();
container.renameMember( oldName, id );
}
catch(InterpretError e)
Expand Down
1 change: 0 additions & 1 deletion src/com/devbaltasarq/pooi/core/objs/SysObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void set(String name, ObjectBag obj) throws InterpretError
{
final Attribute atr = new Attribute( name, obj );

this.setAttribute( name, atr );
atr.getReference().setContainer( this );
this.setAttribute( name, atr );
}
Expand Down
16 changes: 10 additions & 6 deletions src/com/devbaltasarq/pooi/ui/Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent evt) {
if ( !Inspector.this.beingBuilt ) {
visualEngine.execute( obj.getPath() + "." + edName.getText() + " = " + cbContents.getModel().getSelectedItem() );
if ( !( attr.getReference().getNameOrValueAsString().equals( cbContents.getSelectedItem() ) ) ) {
visualEngine.execute( obj.getPath() + "." + edName.getText()
+ " = " + cbContents.getModel().getSelectedItem() );
}
}
}
} );
Expand Down Expand Up @@ -428,14 +431,15 @@ private void launchMethodExecution(String methodName)
null,
"0" );

if ( arguments != null ) {
if ( arguments == null ) {
arguments = "";
} else {
arguments = arguments.trim();
if ( arguments.length() > 0 ) {
visualEngine.execute( obj.getPath() + " " + methodName + " " + arguments );
this.setVisible( false );
}
}
}

visualEngine.execute( obj.getPath() + " " + methodName + " " + arguments );
this.setVisible( false );
}

private void copyObject()
Expand Down
3 changes: 1 addition & 2 deletions src/com/devbaltasarq/pooi/ui/VisualEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectRoot;
import com.devbaltasarq.pooi.core.objs.SysObject;
import com.sun.deploy.config.Platform;

import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class VisualEngine extends JFrame {
/** Creates new form VisualEngine */
public VisualEngine()
{
this.currentDir = new File( Platform.get().getUserHome() );
this.currentDir = new File( System.getProperty( "user.home" ) );
this.build();
this.input.requestFocusInWindow();
}
Expand Down

0 comments on commit 972dcf2

Please sign in to comment.