public static org.lgna.project.ast.NamedUserType getNamedUserTypeFromSuperType( org.lgna.project.ast.JavaType superType) { // <lg> Added to support generality in reuse if (superType.isAssignableTo(org.lgna.story.SScene.class)) { return getSceneUserType(); } // </lg> org.lgna.project.ast.AbstractType<?, ?, ?> parameter0Type = ConstructorArgumentUtilities.getContructor0Parameter0Type(superType); ExtendsTypeCriterion criterion; if (parameter0Type != null) { criterion = new ExtendsTypeWithConstructorParameterTypeCriterion( superType, ConstructorArgumentUtilities.getContructor0Parameter0Type(superType)); } else { criterion = new DefaultConstructorExtendsTypeCriterion(superType); } org.alice.ide.IDE ide = org.alice.ide.IDE.getActiveInstance(); if (ide != null) { org.lgna.project.Project project = ide.getProject(); if (project != null) { java.util.Set<org.lgna.project.ast.NamedUserType> existingTypes = project.getNamedUserTypes(); for (org.lgna.project.ast.NamedUserType existingType : existingTypes) { if (criterion.accept(existingType)) { return existingType; } } } } return createTypeFor(superType, createClassNameFromSuperType(superType), null, null); }
public static org.lgna.project.ast.JavaField getEnumConstantFieldIfOneAndOnly( org.lgna.project.ast.AbstractType<?, ?, ?> type) { org.lgna.project.ast.JavaField rv = null; if (type instanceof org.lgna.project.ast.JavaType) { org.lgna.project.ast.JavaType javaType = (org.lgna.project.ast.JavaType) type; if (type.isAssignableTo(Enum.class)) { Class<Enum<?>> cls = (Class<Enum<?>>) javaType.getClassReflectionProxy().getReification(); Enum<?>[] constants = cls.getEnumConstants(); if (constants.length == 1) { Enum<?> constant = constants[0]; rv = org.lgna.project.ast.JavaField.getInstance(constant.getClass(), constant.name()); } } } return rv; }
public static SetOpacityMethodInvocationFillIn getInstance( org.alice.ide.instancefactory.InstanceFactory instanceFactory, org.lgna.project.ast.JavaType type, String methodName, Class<?>... parameterClses) { org.lgna.project.ast.JavaMethod method = type.getDeclaredMethod(methodName, parameterClses); assert method != null : methodName; return getInstance(instanceFactory, method); }
public static org.lgna.project.ast.NamedUserType getNamedUserTypeFromPersonResourceInstanceCreation( org.lgna.project.ast.InstanceCreation instanceCreation) { org.lgna.project.ast.JavaType bipedType = org.lgna.project.ast.JavaType.getInstance(org.lgna.story.SBiped.class); org.lgna.project.ast.AbstractType<?, ?, ?>[] argumentTypes = getArgumentTypes(bipedType, instanceCreation.getType()); return getNamedUserTypeFor(bipedType, argumentTypes, 0, null); }
public static SetOpacityMethodInvocationFillIn getInstance( org.alice.ide.instancefactory.InstanceFactory instanceFactory, Class<?> cls, String methodName, Class<?>... parameterClses) { return getInstance( instanceFactory, org.lgna.project.ast.JavaType.getInstance(cls), methodName, parameterClses); }
@Override protected void migrate( org.lgna.project.ast.MethodInvocation methodInvocation, org.lgna.project.Project projectIfApplicable) { org.lgna.project.ast.AbstractMethod method = methodInvocation.method.getValue(); if (method instanceof org.lgna.project.ast.JavaMethod) { org.lgna.project.ast.JavaMethod javaMethod = (org.lgna.project.ast.JavaMethod) method; if (javaMethod.getDeclaringType() == org.lgna.project.ast.JavaType.getInstance(org.lgna.story.SScene.class)) { String methodName = javaMethod.getName(); if (methodName.equals("addMouseClickOnScreenListener")) { for (org.lgna.project.ast.AbstractArgument argument : methodInvocation.keyedArguments) { if (DEBUG_MODE) { edu.cmu.cs.dennisc.java.util.logging.Logger.errln( "ALERT: migration removing", argument); } } methodInvocation.keyedArguments.clear(); methodInvocation.method.setValue( org.lgna.story.ast.EventListenerMethodUtilities .ADD_MOUSE_CLICK_ON_SCREEN_LISTENER_METHOD); } else if (methodName.equals("addMouseClickOnObjectListener")) { for (org.lgna.project.ast.AbstractArgument argument : methodInvocation.keyedArguments) { if (DEBUG_MODE) { edu.cmu.cs.dennisc.java.util.logging.Logger.errln( "ALERT: migration removing", argument); } } methodInvocation.keyedArguments.clear(); methodInvocation.method.setValue( org.lgna.story.ast.EventListenerMethodUtilities .ADD_MOUSE_CLICK_ON_OBJECT_LISTENER_METHOD); } } } }
private static org.lgna.project.ast.NamedUserType getNamedUserTypeFor( org.lgna.project.ast.AbstractType<?, ?, ?> ancestorType, org.lgna.project.ast.AbstractType<?, ?, ?>[] argumentTypes, int i, org.lgna.project.ast.AbstractField argumentField) { org.lgna.project.ast.AbstractType<?, ?, ?> superType; final int LAST_INDEX = argumentTypes.length - 1; if (i < LAST_INDEX) { superType = getNamedUserTypeFor(ancestorType, argumentTypes, i + 1, null); } else { superType = ancestorType; } edu.cmu.cs.dennisc.pattern.Criterion<org.lgna.project.ast.NamedUserType> criterion; if (argumentField != null) { criterion = new ExtendsTypeWithSuperArgumentFieldCriterion(superType, argumentField); } else { criterion = new ExtendsTypeWithConstructorParameterTypeCriterion(superType, argumentTypes[i]); } // org.alice.ide.IDE ide = org.alice.ide.IDE.getActiveInstance(); // if( ide != null ) { // org.alice.ide.ProjectDocument projectDocument = ide.getDocument(); // if( projectDocument != null ) { // org.alice.ide.type.TypeCache typeCache = projectDocument.getTypeCache(); // typeCache.getNamedUserTypeFor( ancestorType, argumentTypes, i, argumentField ); // } // } org.lgna.project.Project project = org.alice.ide.ProjectStack.peekProject(); if (project != null) { java.util.Set<org.lgna.project.ast.NamedUserType> existingTypes = project.getNamedUserTypes(); for (org.lgna.project.ast.NamedUserType existingType : existingTypes) { if (criterion.accept(existingType)) { return existingType; } } } org.lgna.project.ast.Expression[] expressions; if (argumentField != null) { expressions = new org.lgna.project.ast.Expression[] { new org.lgna.project.ast.FieldAccess( new org.lgna.project.ast.TypeExpression(argumentField.getDeclaringType()), argumentField) }; } else { expressions = USE_PARAMETER_ACCESSES_AS_ARGUMENTS_TO_SUPER; } String name = createClassNameFromResourceType(argumentTypes[i]); org.lgna.project.ast.NamedUserType rv = createTypeFor( superType, name, new org.lgna.project.ast.AbstractType[] {argumentTypes[i]}, expressions); if (argumentTypes[i] instanceof org.lgna.project.ast.JavaType) { org.lgna.project.ast.JavaType javaArgumentTypeI = (org.lgna.project.ast.JavaType) argumentTypes[i]; Class<?> cls = javaArgumentTypeI.getClassReflectionProxy().getReification(); if (edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.isFinal(cls)) { boolean isSetResourceMethodDesired; if (cls.isEnum()) { isSetResourceMethodDesired = cls.getEnumConstants().length > 1; } else { isSetResourceMethodDesired = true; } if (isSetResourceMethodDesired) { String simpleClsName = cls.getSimpleName(); org.lgna.project.ast.UserMethod setResourceMethod = new org.lgna.project.ast.UserMethod(); setResourceMethod.managementLevel.setValue( org.lgna.project.ast.ManagementLevel.GENERATED); setResourceMethod.name.setValue("set" + simpleClsName); setResourceMethod.returnType.setValue(org.lgna.project.ast.JavaType.VOID_TYPE); org.lgna.project.ast.BlockStatement body = new org.lgna.project.ast.BlockStatement(); setResourceMethod.body.setValue(body); StringBuilder parameterNameSB = new StringBuilder(); parameterNameSB.append(Character.toLowerCase(simpleClsName.charAt(0))); parameterNameSB.append(simpleClsName.substring(1)); org.lgna.project.ast.UserParameter parameter = new org.lgna.project.ast.UserParameter(); parameter.name.setValue(parameterNameSB.toString()); parameter.valueType.setValue(javaArgumentTypeI); setResourceMethod.requiredParameters.add(parameter); body.statements.add( org.lgna.project.ast.AstUtilities.createMethodInvocationStatement( new org.lgna.project.ast.ThisExpression(), SET_JOINTED_MODEL_RESOURCE_METHOD, new org.lgna.project.ast.ParameterAccess(parameter))); setResourceMethod.isSignatureLocked.setValue(true); rv.methods.add(setResourceMethod); } } } return rv; }