Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DefaultWeaver/resources/specification/artifacts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
</artifact>
<artifact class="function" default="name">
<attribute name="name" type="string" />
<attribute name="usesThis" type="this">
<parameter name="param1" type="List&lt;this&gt;"/>
</attribute>
</artifact>
</artifacts>
16 changes: 6 additions & 10 deletions DefaultWeaver/resources/specification/joinPointModel.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?xml version="1.0"?>
<joinpoints root_class="workspace">
<joinpoint class="folder">
<select class="file"/>
</joinpoint>
<joinpoint class="file">
<select class="function"/>
</joinpoint>
<joinpoint class="function"/>
<joinpoint class="workspace">
<select class="folder"/>
</joinpoint>
<joinpoint class="folder"/>
<joinpoint class="file"/>
<joinpoint class="function"/>
<joinpoint class="class"/>
<joinpoint class="method" extends="function"/>
<joinpoint class="workspace"/>
</joinpoints>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.lara.interpreter.weaver.defaultweaver.DefaultWeaver;
import org.lara.interpreter.weaver.defaultweaver.abstracts.joinpoints.AFile;

public class DWFile extends AFile {
public class DWFile extends AFile<DWFile> {

private final File file;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.lara.interpreter.weaver.defaultweaver.DefaultWeaver;
import org.lara.interpreter.weaver.defaultweaver.abstracts.joinpoints.AFolder;

public class DWFolder extends AFolder {
public class DWFolder extends AFolder<DWFolder> {

private final boolean getFilesRecursively = true;
private final List<DWFile> files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
*/
package org.lara.interpreter.weaver.defaultweaver.joinpoints;

import java.util.List;

import org.lara.interpreter.weaver.defaultweaver.DefaultWeaver;
import org.lara.interpreter.weaver.defaultweaver.abstracts.joinpoints.AFunction;
import org.lara.interpreter.weaver.interf.JoinPoint;
import org.lara.interpreter.weaver.defaultweaver.abstracts.joinpoints.AJoinPoint;

public class DWFunction extends AFunction {
public class DWFunction extends AFunction<DWFunction> {

private final String name;

Expand All @@ -39,7 +41,7 @@ public Object getNode() {
// }

@Override
public JoinPoint[] insertImpl(String position, String code) {
public AJoinPoint[] insertImpl(String position, String code) {
System.out.println("#########INSERTING#########");
System.out.println(
"Action not available. But would insert " + position + " function " + name + ": " + code.trim());//
Expand All @@ -58,4 +60,9 @@ public JoinPoint[] insertImpl(String position, String code) {
public String getNameImpl() {
return name;
}

@Override
public DWFunction usesThisImpl(List<DWFunction> param1) {
throw new UnsupportedOperationException("Not implemented");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2026 SPeCS.
*
* 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.lara.interpreter.weaver.defaultweaver.joinpoints;

import java.util.List;

import org.lara.interpreter.weaver.defaultweaver.DefaultWeaver;
import org.lara.interpreter.weaver.defaultweaver.abstracts.joinpoints.AFunction;
import org.lara.interpreter.weaver.defaultweaver.abstracts.joinpoints.AMethod;

public class DWMethod extends AMethod<DWMethod> {

public DWMethod(AFunction<?> aFunction, DefaultWeaver weaver) {
super(aFunction, weaver);
}


@Override
public DWMethod usesThisImpl(List<DWMethod> param1) {
throw new UnsupportedOperationException("Not implemented");
}


@Override
public Object getNode() {
throw new UnsupportedOperationException("Unimplemented method 'getNode'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author Tiago Carvalho
*
*/
public class DWorkspace extends AWorkspace {
public class DWorkspace extends AWorkspace<DWorkspace> {

private final Map<File, DWFolder> folders;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package org.lara.language.specification.dsl;

import org.lara.language.specification.dsl.types.ThisType;
import org.lara.language.specification.exception.LanguageSpecificationException;

import java.util.Set;

/**
* Central place for identifier validation shared across the language specification model.
*/
public final class IdentifierValidator {

/**
* Reserved keywords that cannot be used as identifiers for join points, attributes, etc.
*/
private static final Set<String> RESERVED_KEYWORDS = Set.of(
ThisType.THIS_KEYWORD // 'this' is reserved for late-bound self type
);

private IdentifierValidator() {
}

Expand All @@ -15,13 +25,29 @@ public static void requireValid(String identifier, String context) {
return;
}

if (RESERVED_KEYWORDS.contains(identifier)) {
throw new LanguageSpecificationException(
"Identifier '" + identifier + "' for " + context
+ " is a reserved keyword and cannot be used");
}

if (!isValidJavaLikeIdentifier(identifier)) {
throw new LanguageSpecificationException(
"Identifier '" + identifier + "' for " + context
+ " must follow Java identifier rules");
}
}

/**
* Checks if the given identifier is a reserved keyword.
*
* @param identifier the identifier to check
* @return true if it's a reserved keyword
*/
public static boolean isReservedKeyword(String identifier) {
return identifier != null && RESERVED_KEYWORDS.contains(identifier);
}

private static boolean isValidJavaLikeIdentifier(String identifier) {
int firstCodePoint = identifier.codePointAt(0);
if (!Character.isJavaIdentifierStart(firstCodePoint)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.lara.language.specification.dsl.types.IType;

import pt.up.fe.specs.util.collections.MultiMap;
import pt.up.fe.specs.util.lazy.Lazy;

public class JoinPointClass extends BaseNode implements Comparable<JoinPointClass> {

Expand All @@ -35,10 +34,6 @@ public class JoinPointClass extends BaseNode implements Comparable<JoinPointClas
private List<Attribute> attributes;
private List<Action> actions;

// TODO: There is attribute and action overloading, fix this
private final Lazy<MultiMap<String, Attribute>> attributeMap;
private final Lazy<MultiMap<String, Action>> actionsMap;

public JoinPointClass(String name) {
this(name, null, null);
}
Expand All @@ -50,9 +45,6 @@ public JoinPointClass(String name, JoinPointClass extend, String defaultAttribut
setDefaultAttribute(defaultAttribute);
attributes = new ArrayList<>();
actions = new ArrayList<>();

attributeMap = Lazy.newInstance(() -> buildMultiMap(getAttributesSelf(), Attribute::getName));
actionsMap = Lazy.newInstance(() -> buildMultiMap(getActionsSelf(), Action::getName));
}

public String getName() {
Expand All @@ -74,6 +66,14 @@ private <T extends BaseNode> MultiMap<String, T> buildMultiMap(List<T> nodes, Fu
return map;
}

private MultiMap<String, Attribute> buildAttributeMap() {
return buildMultiMap(getAttributesSelf(), Attribute::getName);
}

private MultiMap<String, Action> buildActionMap() {
return buildMultiMap(getActionsSelf(), Action::getName);
}

public boolean hasExtend() {
return extend.isPresent();
}
Expand Down Expand Up @@ -156,23 +156,23 @@ public List<Action> getActionsSelf() {
}

public List<Attribute> getAttributeSelf(String name) {
return attributeMap.get().get(name);
return buildAttributeMap().get(name);
}

/**
* @return the actions corresponding to the given name, or empty list if none
* exists.
*/
public List<Action> getActionSelf(String name) {
return actionsMap.get().get(name);
return buildActionMap().get(name);
}

public boolean hasAttributeSelf(String name) {
return attributeMap.get().containsKey(name);
return buildAttributeMap().containsKey(name);
}

public boolean hasActionSelf(String name) {
return actionsMap.get().containsKey(name);
return buildActionMap().containsKey(name);
}

public boolean hasAttribute(String name) {
Expand Down Expand Up @@ -223,7 +223,7 @@ public List<Action> getActions() {
* attributes of this join point, including hierarchy
*/
public List<Attribute> getAttribute(String name) {
List<Attribute> attribute = new ArrayList<>(attributeMap.get().get(name));
List<Attribute> attribute = new ArrayList<>(buildAttributeMap().get(name));
extend.ifPresent(superJp -> attribute.addAll(superJp.getAttribute(name)));
return attribute;
}
Expand All @@ -234,29 +234,13 @@ public List<Attribute> getAttribute(String name) {
* actions of this join point, including hierarchy
*/
public List<Action> getAction(String name) {
List<Action> action = new ArrayList<>(actionsMap.get().get(name));
List<Action> action = new ArrayList<>(buildActionMap().get(name));
extend.ifPresent(superJp -> action.addAll(superJp.getAction(name)));
return action;
}

public static JoinPointClass globalJoinPoint() {
JoinPointClass globalNode = new JoinPointClass(JoinPointClass.GLOBAL_NAME);

// TODO: Handle this in another way, it is here for compatibility reasons with
// the weaver generator
// Add default define (def) action
// var defAction = new Action(new GenericType("Object", false), "def");
// globalNode.add(defAction);
/*
* globalNode.add(new Action(new ArrayType(new JPType(globalNode)), "insert",
* List.of(new Parameter(PrimitiveClasses.STRING, "position"),
* new Parameter(PrimitiveClasses.STRING, "code"))));
*
* globalNode.add(new Action(new ArrayType(new JPType(globalNode)), "insert",
* List.of(new Parameter(PrimitiveClasses.STRING, "position"),
* new Parameter(new GenericType("Joinpoint", false), "code"))));
*/
return globalNode;
return LaraJoinPointContract.build(JoinPointClass.GLOBAL_NAME);
}

@Override
Expand Down
Loading
Loading