Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Spoon metamodel #1183

Closed
2 tasks done
pvojtechovsky opened this issue Feb 11, 2017 · 4 comments
Closed
2 tasks done

feature: Spoon metamodel #1183

pvojtechovsky opened this issue Feb 11, 2017 · 4 comments
Labels

Comments

@pvojtechovsky
Copy link
Collaborator

pvojtechovsky commented Feb 11, 2017

Requirements:


Some code in spoon library is generated by generators. Do we have in spoon an metamodel, which can be used as good input for future generators?

Idea: if we would have a good and complete metamodel of spoon model, then this metamodel might be used to generate more sources and to implement issues like #741, #1168 faster.

If I understood it well current spoon generators are using CtScanner and annotations on spoon model interfaces as source metamodel. May be we might write a code which scans current spoon sources, mainly

  • class CtScanner,
  • package: spoon.reflect.code
  • package: spoon.reflect.declaration
  • package: spoon.reflect.reference
    and to automatically build a real - easy to use :-) ... metamodel, which might be then used as input of next generation generators and may be might be even used to update spoon model itself.

... I know, it is quite big task, but may be once ...

@monperrus
Copy link
Collaborator

To some extent, creating the Spoon of model of spoon.reflect.declaration/code is the spoon metamodel itself, and this is what's done for generating classes and testing the metamodel itself.

If I understood it well current spoon generators are using CtScanner and annotations on spoon model interfaces as source metamodel

Correct

Moving this information elsewhere make it more explicit but is one more level of indirection to understand and maintain.

@pvojtechovsky
Copy link
Collaborator Author

I understand what you mean and I agree.

I am thinking, how to minimize amount of manually written code and replace it by generated code. May be the spoon sources (even one file) might contain both manually written and generated code. The generated code would be marked (e.g by some comment) and the generator would be allowed to update only such sections. For example the sources file below contains both manually written and generated code:

public class CtBreakImpl extends CtStatementImpl implements CtBreak {
	private static final long serialVersionUID = 1L;

//begin of code genereated by: ModelGeneratorTemplate#primitiveProperty
	String targetLabel;
//end of genereated code

//begin of code genereated by: ModelGeneratorTemplate#visitorPattern_accept
	@Override
	public void accept(CtVisitor visitor) {
		visitor.visitCtBreak(this);
	}
//end of genereated code

//begin of code genereated by: ModelGeneratorTemplate#primitiveGetter
	@Override
	public String getTargetLabel() {
		return targetLabel;
	}
//end of genereated code

//begin of code genereated by: ModelGeneratorTemplate#primitiveSetter
	@Override
	public <T extends CtBreak> T setTargetLabel(String targetLabel) {
		this.targetLabel = targetLabel;
		return (T) this;
	}
//end of genereated code

//begin of code genereated by: ModelGeneratorTemplate#clone
	@Override
	public CtBreak clone() {
		return (CtBreak) super.clone();
	}
//end of genereated code
}

Such sources would allow mixing of manually written code and generated code. The generator must of course assure that manually written code is not lost during update of generated code.
It would let us to apply design patterns on spoon sources and to implement new features, which needs the same change in each property setter consistently, with lower effort, less mistakes and lower maintenance - because the code is generated and not manually written.

@monperrus
Copy link
Collaborator

monperrus commented Feb 15, 2017 via email

@monperrus
Copy link
Collaborator

Considered closed per the recent work on annotations for roles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants