Skip to content

Commit

Permalink
adding a check about annotationprocessor dependency and a clear error
Browse files Browse the repository at this point in the history
message for the user
  • Loading branch information
dvojtise authored and Thomas Degueule committed Mar 24, 2015
1 parent 6950e92 commit c676b62
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import org.eclipse.xtext.naming.IQualifiedNameConverter
import org.eclipse.xtext.naming.QualifiedName
import org.eclipse.xtext.xbase.XAbstractFeatureCall

import org.apache.log4j.Logger

class MetamodelExtensions
{
@Inject extension ModelingElementExtensions
Expand All @@ -41,6 +43,7 @@ class MetamodelExtensions
@Inject extension NamingHelper
@Inject ModelTypeAlgebra algebra
@Inject EPackageProvider provider
static Logger log = Logger.getLogger(MetamodelExtensions)

def List<GenModel> getGenmodels(Metamodel mm) {
return provider.getGenModels(mm)
Expand Down Expand Up @@ -122,13 +125,28 @@ class MetamodelExtensions
}

def boolean isDefinedOver(Aspect asp, Metamodel mm) {
return mm.packageFqn.toQualifiedName.skipLast(1).toString == asp.targetedNamespace.toString
try{
return mm.packageFqn.toQualifiedName.skipLast(1).toString == asp.targetedNamespace.toString
} catch (java.lang.IllegalArgumentException e){
val unresolvedProxyAspect = (asp.aspectTypeRef.type as JvmDeclaredType).annotations.exists[annotation.eIsProxy]
if(unresolvedProxyAspect){
log.debug("annotationProcessor dependency missing, please add k3al.annotationprocessor to the classpath ", e)
return false
}
else
throw e
}
}

// FIXME: We should check that the original mm is a super-type of mm
// Hard to find the metamodel declaration or the corresponding Ecore file
// in the workspace...
def boolean canBeCopiedFor(Aspect asp, Metamodel mm) {
val unresolvedProxyAspect = (asp.aspectTypeRef.type as JvmDeclaredType).annotations.exists[annotation.eIsProxy]
if(unresolvedProxyAspect){
// cannot copy the aspect because we don't have a correct dependency to the annotation processor
return false
}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import fr.inria.diverse.melange.ast.MetamodelExtensions
import fr.inria.diverse.melange.metamodel.melange.Metamodel
import fr.inria.diverse.melange.utils.AspectCopier
import javax.inject.Inject
import org.apache.log4j.Logger
import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder

class AspectsCopier extends DispatchMelangeProcessor
{
@Inject AspectCopier copier
@Inject extension MetamodelExtensions
@Inject JvmTypeReferenceBuilder.Factory builderFactory
static Logger log = Logger.getLogger(AspectsCopier)

def dispatch void preProcess(Metamodel mm) {
if (!mm.isGeneratedByMelange || mm.runtimeHasBeenGenerated) {
Expand All @@ -25,5 +27,6 @@ class AspectsCopier extends DispatchMelangeProcessor
}
]
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MelangeValidationConstants
public static final String METAMODEL_SELF_INHERITANCE = "METAMODEL_SELF_INHERITANCE"
public static final String METAMODEL_XTEXT_SETUP = "METAMODEL_XTEXT_SETUP"
public static final String ASPECT_NOT_FOUND = "METAMODEL_ASPECT_NOT_FOUND"
public static final String INVALID_ASPECT_IMPORT = "INVALID_METAMODEL_ASPECT_IMPORT"
public static final String ASPECT_NO_ANNOTATION = "METAMODEL_ASPECT_NO_ANNOTATION"
public static final String MODELING_ELEMENT_ECORE_URI_INVALID = "MODELING_ELEMENT_ECORE_URI_INVALID"
public static final String METAMODEL_NO_EMF_RUNTIME = "METAMODEL_NO_EMF_RUNTIME"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ class MelangeValidator extends AbstractMelangeValidator
MelangeValidationConstants.ASPECT_NOT_FOUND
)
}

@Check
def void checkHasAnnotationProcessorDependency(Aspect asp) {
if (asp.aspectTypeRef?.type !== null && asp.aspectTypeRef.type instanceof JvmDeclaredType &&
(asp.aspectTypeRef.type as JvmDeclaredType).annotations.exists[annotation.eIsProxy]
)
error(
"Cannot find dependency to annotation processor. Please add k3.al.annotationprocessor",
MelangePackage.Literals.ASPECT__ASPECT_TYPE_REF,
MelangeValidationConstants.INVALID_ASPECT_IMPORT
)
}

@Check
def void checkAspectHasAnnotation(Aspect a) {
Expand Down

0 comments on commit c676b62

Please sign in to comment.