Skip to content

Commit

Permalink
eclipse-archived#190 In progress TqCL - syntax (insert) and library s…
Browse files Browse the repository at this point in the history
…ervices
  • Loading branch information
rtotaro committed Jan 8, 2017
1 parent 0fc0001 commit 75abcbe
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ public interface TqCLLibraryProvider {
public boolean hasElement(String element);

public boolean hasElementInLibrary(String element, String library, String category);

public EntityDescriptor getDirector(String directorClass) throws TqCLLibraryException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ public EntityDescriptor getActor(String actorClass) throws TqCLLibraryException
}
return null;
}

@Override
public EntityDescriptor getDirector(String directorClass) throws TqCLLibraryException {
for (TqCLLibraryProvider provider : libraryProviders.values()) {
EntityDescriptor actor = provider.getDirector(directorClass);
if(actor!=null)
{
return actor;
}
}
return null;
}

@Override
public boolean hasElementInLibrary(String element, String library,String category) {
Expand All @@ -133,4 +145,5 @@ public boolean hasElementInLibrary(String element, String library,String categor
return false;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.triquetrum.commands.tqcl.Insert;
import org.eclipse.triquetrum.commands.tqcl.Library;
import org.eclipse.triquetrum.commands.tqcl.TriquetrumScript;
import org.eclipse.triquetrum.commands.validation.TqCLUtils;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
Expand All @@ -46,16 +47,15 @@
* on how to customize the content assistant.
*/
public class TqclProposalProvider extends AbstractTqclProposalProvider {

@Override
public void completeLibrary_Name(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
super.completeLibrary_Name(model, assignment, context, acceptor);
TqCLLibraryProvider tqclLibraryProvider = TqCLServices.getInstance().getTqclLibraryProvider();
Set<String> libraryNames = tqclLibraryProvider.getLibraryNames();
for (String string : libraryNames) {
ICompletionProposal completionProposal = createCompletionProposal(string,
string, null, context);
ICompletionProposal completionProposal = createCompletionProposal(string, string, null, context);
acceptor.accept(completionProposal);
}
}
Expand Down Expand Up @@ -136,20 +136,28 @@ public void completeInsert_Parameters(EObject model, Assignment assignment, Cont
ICompletionProposalAcceptor acceptor) {
if (model instanceof Insert) {
Insert insert = (Insert) model;
Category category = ((Insert) insert).getCategory();
if (category == null) {
category = Category.ACTOR;
}
Category category = TqCLUtils.getCategory((Insert) insert);
String entityClass = insert.getEntityClass();

EntityDescriptor actor;
try {
actor = TqCLServices.getInstance().getTqclLibraryProvider().getActor(cleanEntityName(entityClass));
TqCLLibraryProvider tqclLibraryProvider = TqCLServices.getInstance().getTqclLibraryProvider();
EntityDescriptor entityDescriptor = null;
switch (category) {
case ACTOR:
entityDescriptor = tqclLibraryProvider.getActor(TqCLUtils.cleanEntityName(entityClass));
break;
case DIRECTOR:
entityDescriptor = tqclLibraryProvider.getDirector(TqCLUtils.cleanEntityName(entityClass));
break;

default:
break;
}

if (actor == null) {
if (entityDescriptor == null) {
return;
}
List<ParameterDescriptor> parameters = actor.getParameters();
List<ParameterDescriptor> parameters = entityDescriptor.getParameters();
for (ParameterDescriptor parameterDescriptor : parameters) {
String displayName = parameterDescriptor.getDisplayName();
String proposal = "";
Expand All @@ -173,8 +181,4 @@ public void completeInsert_Parameters(EObject model, Assignment assignment, Cont
}
}

public String cleanEntityName(String entityClass) {
return entityClass.substring(1, entityClass.lastIndexOf('>'));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Set:
Connect:
"connect" from+=ConnectionPort(',' from+=ConnectionPort)* "to" to+=ConnectionPort(',' to+=ConnectionPort)*;

ConnectionPort:
actor=[Insert] '.' port=NamedObj;

GoInto returns Go:
"go" direction="into" obj = NamedObj
;
Expand Down Expand Up @@ -73,8 +76,7 @@ terminal ENTITY_CLASS:
//terminal ENTITY_INSTANCE_NAME: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|ESCAPED_CHAR)*;


ConnectionPort:
actor=[Insert] '.' port=NamedObj;




Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.triquetrum.commands.tqcl.Connect;
import org.eclipse.triquetrum.commands.tqcl.Insert;
import org.eclipse.triquetrum.commands.tqcl.TqclPackage;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.Scopes;
Expand All @@ -30,9 +32,15 @@ public class TqclScopeProvider extends AbstractTqclScopeProvider {

@Override
public IScope getScope(EObject context, EReference reference) {
if (context instanceof Connect) {
if (context instanceof Connect && reference == TqclPackage.Literals.CONNECTION_PORT__ACTOR) {
Connect connect = (Connect) context;

// Collect a list of candidates by going through the model
// EcoreUtil2 provides useful functionality to do that
// For example searching for all elements within the root Object's tree
EObject rootElement = EcoreUtil2.getRootContainer(context);
Iterable<Insert> candidates = EcoreUtil2.getAllContentsOfType(rootElement, Insert.class);
// Create IEObjectDescriptions and puts them into an IScope instance
return Scopes.scopeFor(candidates);

}
return super.getScope(context, reference);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.eclipse.triquetrum.commands.validation;

import org.eclipse.triquetrum.commands.tqcl.Category;
import org.eclipse.triquetrum.commands.tqcl.Insert;

public class TqCLUtils {

public static String cleanEntityName(String entityClass) {
return entityClass.substring(1, entityClass.lastIndexOf('>'));
}

public static Category getCategory(Insert insert) {
Category category = insert.getCategory();
if (category == null) {
category = Category.ACTOR;
}
return category;
}

public static String cleanParameterName(String id) {
if (id.startsWith("$")) {
return id.substring(1);
} else if (id.startsWith("\"")) {
return id.substring(1, id.lastIndexOf('"'));
}

// TODO : throw exception???
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.triquetrum.commands.api.services.ParameterDescriptor;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryException;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryProvider;
import org.eclipse.triquetrum.commands.tqcl.Category;
import org.eclipse.triquetrum.commands.tqcl.Insert;
import org.eclipse.triquetrum.commands.tqcl.Library;
import org.eclipse.triquetrum.commands.tqcl.Parameter;
Expand Down Expand Up @@ -83,25 +84,37 @@ public void checkEntityParameters(Insert insert) {
for (EObject eObject : eContents) {
if (eObject instanceof Library) {
Library library = (Library) eObject;
String libraryName = library.getName();
try {
EntityDescriptor actor = tqclLibraryProvider.getActor(libraryName,
cleanEntityClassName(insert.getEntityClass()));
if (actor != null) {
List<ParameterDescriptor> parameters = actor.getParameters();
Category category = TqCLUtils.getCategory(insert);
String entityClass = insert.getEntityClass();
EntityDescriptor entityDescriptor = null;
switch (category) {
case ACTOR:
entityDescriptor = tqclLibraryProvider.getActor(TqCLUtils.cleanEntityName(entityClass));
break;
case DIRECTOR:
entityDescriptor = tqclLibraryProvider.getDirector(TqCLUtils.cleanEntityName(entityClass));
break;

default:
break;
}

if (entityDescriptor != null) {
List<ParameterDescriptor> parameters = entityDescriptor.getParameters();
EList<Parameter> tqclParameters = insert.getParameters();
for (Parameter tqclParameter : tqclParameters) {
boolean found = false;
for (ParameterDescriptor parameterDescriptor : parameters) {
if (parameterDescriptor.getDisplayName()
.equals(cleanParameterName(tqclParameter.getId()))) {
.equals(TqCLUtils.cleanParameterName(tqclParameter.getId()))) {
found = true;
break;
}
}
if (!found) {
String message = MessageFormat.format("Invalid paramete name {0} for actor {1}",
tqclParameter.getId(), actor.getClazz());
String message = MessageFormat.format("Invalid parameter name {0} for actor {1}",
tqclParameter.getId(), entityDescriptor.getClazz());
error(message, tqclParameter, TqclPackage.Literals.PARAMETER__ID, INVALID_PARAMETER);
}
}
Expand All @@ -114,15 +127,4 @@ public void checkEntityParameters(Insert insert) {
}
}

private Object cleanParameterName(String id) {
if (id.startsWith("$")) {
return id.substring(1);
} else if (id.startsWith("\"")) {
return id.substring(1, id.lastIndexOf('"'));
}

// TODO : throw exception???
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public EntityDescriptor getActor(String library, String actorClass) throws TqCLL
public EntityDescriptor getActor(String actorClass) throws TqCLLibraryException {
return actors.get(actorClass);
}

@Override
public EntityDescriptor getDirector(String directorClass) throws TqCLLibraryException {
return directors.get(directorClass);
}

@Override
public boolean hasElementInLibrary(String element, String library, String category) {
Expand Down

0 comments on commit 75abcbe

Please sign in to comment.