-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first implementation of model inferrer for the test language
- Loading branch information
1 parent
d7e50c9
commit 4cc8ad6
Showing
4 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...e/xtext/xbase/testlanguages/jvmmodel/JvmGenericTypeValidatorTestLangJmvModelInferrer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.xtext.xbase.testlanguages.jvmmodel; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.xtext.common.types.JvmGenericType; | ||
import org.eclipse.xtext.naming.IQualifiedNameProvider; | ||
import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer; | ||
import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; | ||
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; | ||
import org.eclipse.xtext.xbase.testlanguages.jvmGenericTypeValidatorTestLang.MyClass; | ||
import org.eclipse.xtext.xbase.testlanguages.jvmGenericTypeValidatorTestLang.MyInterface; | ||
|
||
import com.google.inject.Inject; | ||
|
||
/** | ||
* @author Lorenzo Bettini | ||
* | ||
*/ | ||
public class JvmGenericTypeValidatorTestLangJmvModelInferrer extends AbstractModelInferrer { | ||
@Inject | ||
private JvmTypesBuilder jvmTypesBuilder; | ||
|
||
@Inject | ||
private IQualifiedNameProvider qualifiedNameProvider; | ||
|
||
protected void _infer(MyClass myClass, IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) { | ||
acceptor.accept(jvmTypesBuilder.toClass(myClass, qualifiedNameProvider.getFullyQualifiedName(myClass)), | ||
(JvmGenericType it) -> { | ||
jvmTypesBuilder.setDocumentation(it, jvmTypesBuilder.getDocumentation(myClass)); | ||
if (myClass.getExtends() != null) { | ||
it.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(myClass.getExtends())); | ||
} | ||
for (var interf : myClass.getImplements()) { | ||
it.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(interf)); | ||
} | ||
}); | ||
} | ||
|
||
protected void _infer(MyInterface myInterface, IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) { | ||
acceptor.accept(jvmTypesBuilder.toClass(myInterface, qualifiedNameProvider.getFullyQualifiedName(myInterface)), | ||
(JvmGenericType it) -> { | ||
it.setInterface(true); | ||
jvmTypesBuilder.setDocumentation(it, jvmTypesBuilder.getDocumentation(myInterface)); | ||
for (var interf : myInterface.getExtends()) { | ||
it.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(interf)); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void infer(EObject element, IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) { | ||
if (element instanceof MyClass) { | ||
_infer((MyClass) element, acceptor, prelinkingPhase); | ||
return; | ||
} else if (element instanceof MyInterface) { | ||
_infer((MyInterface) element, acceptor, prelinkingPhase); | ||
return; | ||
} else { | ||
super.infer(element, acceptor, prelinkingPhase); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ext/xbase/testlanguages/scoping/JvmGenericTypeValidatorTestLangQualifiedNameProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.eclipse.xtext.xbase.testlanguages.scoping; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.xtext.naming.QualifiedName; | ||
import org.eclipse.xtext.xbase.scoping.XbaseQualifiedNameProvider; | ||
import org.eclipse.xtext.xbase.testlanguages.jvmGenericTypeValidatorTestLang.JvmGenericTypeValidatorTestLangModel; | ||
|
||
/** | ||
* @author Lorenzo Bettini | ||
* | ||
*/ | ||
public class JvmGenericTypeValidatorTestLangQualifiedNameProvider extends XbaseQualifiedNameProvider { | ||
|
||
@Override | ||
public QualifiedName getFullyQualifiedName(EObject obj) { | ||
if (obj instanceof JvmGenericTypeValidatorTestLangModel) { | ||
JvmGenericTypeValidatorTestLangModel model = (JvmGenericTypeValidatorTestLangModel) obj; | ||
if (model.getPackage() != null) | ||
return getConverter().toQualifiedName(model.getPackage()); | ||
} | ||
return super.getFullyQualifiedName(obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters