diff --git a/config/default.ini b/config/default.ini index 741b96b1..427aeaf2 100755 --- a/config/default.ini +++ b/config/default.ini @@ -4,7 +4,7 @@ name: Scratch2Catrobat Converter short_name: S2CC version: 0.10.0 build_name: Aegean cat -build_number: 992 +build_number: 995 build_type: S2CC ;------------------------------------------------------------------------------- diff --git a/sourcecodefilter/config/config.yml b/sourcecodefilter/config/config.yml index 2e187bf5..6d3d6935 100644 --- a/sourcecodefilter/config/config.yml +++ b/sourcecodefilter/config/config.yml @@ -6,7 +6,9 @@ xstream_class_name: BackwardCompatibleCatrobatLanguageXStream archive_extension: "zip" #URL: "https://github.com/Catrobat/Catroid/archive/master.%{archive_extension}" #URL: "https://github.com/Catrobat/Catroid/archive/%{catroid_version}.%{archive_extension}" -URL: "https://github.com/Catrobat/Catroid/archive/release-0.9.34.%{archive_extension}" +#URL: "https://github.com/Catrobat/Catroid/archive/release-0.9.34.%{archive_extension}" +#URL: "https://github.com/Catrobat/Catroid/archive/v0.9.60.zip" +URL: "https://github.com/Catrobat/Catroid/archive/v0.9.64.zip" xstream_version: "1.4.7" xstream_lib_extension: "jar" xstream_download_URL: "http://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/%{xstream_version}/xstream-%{xstream_version}.%{xstream_lib_extension}" @@ -45,15 +47,15 @@ remove_classes: [ WhenNfcBrick, WhenNfcScript, SetNfcTagBrick, # Raspi bricks - RaspiPwmBrick, RaspiSendDigitalValueBrick, RaspiInterruptScript, + RaspiPwmBrick, RaspiSendDigitalValueBrick, RaspiInterruptScript, WhenRaspiPinChangedBrick, # physics bricks CollisionScript, CollisionReceiverBrick, SetBounceBrick, SetFrictionBrick, SetGravityBrick, SetMassBrick, SetPhysicsObjectTypeBrick, SetVelocityBrick, - TurnLeftSpeedBrick, TurnRightSpeedBrick, + TurnLeftSpeedBrick, TurnRightSpeedBrick, WhenBounceOffScript, WhenBounceOffBrick, # Miscellaneous - WhenGamepadButtonBrick, WhenGamepadButtonScript + WhenGamepadButtonBrick, WhenGamepadButtonScript, ThreadScheduler, DroneVideoLookData, NfcTagData ] remove_method_invocations: @@ -65,12 +67,13 @@ remove_method_invocations: remove_method_invocations_with_parameter_mapping: org.catrobat.catroid.content.Project: - removeInvalidVariablesAndLists(oldProject.dataContainer) + - backgroundSprite.look.setZIndex(Z_INDEX_BACKGROUND) org.catrobat.catroid.content.Scene: - background.look.setZIndex(0) - addSprite(background) org.catrobat.catroid.content.Look: - flipLookDataIfNeeded(mode) - org.catrobat.catroid.io.StorageHandler: + org.catrobat.catroid.io.XstreamSerializer: - xstream.alias("nfcTag",NfcTagData.class) - xstream.alias("script",WhenNfcScript.class) - xstream.alias("script",RaspiInterruptScript.class) @@ -123,6 +126,13 @@ remove_method_invocations_with_parameter_mapping: - xstream.alias("brick",LegoEv3SetLedBrick.class) - xstream.alias("script",WhenGamepadButtonScript.class) - xstream.alias("brick",WhenGamepadButtonBrick.class) + - xstream.alias("brick",WhenRaspiPinChangedBrick.class) + - xstream.alias("droneLook",DroneVideoLookData.class) + - xstream.omitField(RaspiInterruptScript.class,"receivedMessage") + - xstream.omitField(SetNfcTagBrick.class,"nfcTagNdefDefaultType") + - xstream.alias("script",WhenBounceOffScript.class) + - xstream.alias("brick",WhenBounceOffBrick.class) + org.catrobat.catroid.io.BackwardCompatibleCatrobatLanguageXStream: - brickInfo.addBrickFieldToMap("speed",BrickField.LEGO_NXT_SPEED) - brickInfoMap.put("legoNxtMotorMoveBrick",brickInfo) @@ -202,7 +212,9 @@ remove_method_invocations_with_parameter_mapping: - brickInfoMap.put("setNfcTagBrick",brickInfo) - brickInfoMap.put("whenGamepadButtonBrick",brickInfo) - scriptInfoMap.put("whenGamepadButtonScript",WhenGamepadButtonScript.class.getSimpleName()) - + - scriptInfoMap.put("collisionScript",WhenBounceOffScript.class.getSimpleName()) + org.catrobat.catroid.content.bricks.FormulaBrick: + - brickFieldToTextViewIdMap.put(brickField,textViewResourceId) remove_assignments_mapping: org.catrobat.catroid.formulaeditor.Formula: - internFormula=new InternFormula(formulaTree.getInternTokenList()) @@ -249,7 +261,17 @@ remove_assignments_mapping: - brickInfo=new BrickInfo(TurnRightSpeedBrick.class.getSimpleName()) - brickInfo=new BrickInfo(SetNfcTagBrick.class.getSimpleName()) - brickInfo=new BrickInfo(WhenGamepadButtonBrick.class.getSimpleName()) - + - brickInfo=new BrickInfo(WhenBounceOffBrick.class.getSimpleName()) + org.catrobat.catroid.common.LookData: + - this.file=file + org.catrobat.catroid.common.SoundInfo: + - this.file=file + org.catrobat.catroid.content.bricks.SetPenColorBrick: + - showFormulaEditorStrategy=new ShowColorPickerFormulaEditorStrategy() + org.catrobat.catroid.content.bricks.ShowTextColorSizeAlignmentBrick: + - showFormulaEditorStrategy=new ShowColorPickerFormulaEditorStrategy() + org.catrobat.catroid.content.Look: + - scheduler=new ThreadScheduler(this) remove_if_else_blocks_mapping: org.catrobat.catroid.io.StorageHandler: - "!Utils.externalStorageAvailable()" @@ -258,6 +280,7 @@ remove_if_else_blocks_mapping: org.catrobat.catroid.content.Project: - "ScreenValues.SCREEN_HEIGHT == 0 || ScreenValues.SCREEN_WIDTH == 0" - "context == null" + - "isCastProject" org.catrobat.catroid.content.bricks.BroadcastReceiverBrick: - "receiveScript != null && receiveScript.isCommentedOut()" org.catrobat.catroid.content.bricks.WhenBrick: @@ -266,6 +289,10 @@ remove_if_else_blocks_mapping: - "script != null && script.isCommentedOut()" org.catrobat.catroid.content.bricks.WhenTouchDownBrick: - "script != null && script.isCommentedOut()" + org.catrobat.catroid.common.LookData: + - "file != null" + org.catrobat.catroid.common.SoundInfo: + - "file != null" remove_variable_declarations_mapping: org.catrobat.catroid.content.Look: @@ -286,6 +313,7 @@ additional_serialization_classes: - AllowedAfterDeadEndBrick - BaseDataContainer - Brick + - BrickBaseType - Constants - DeadEndBrick - DroneBrick @@ -293,6 +321,7 @@ additional_serialization_classes: - ElementType - Formula - FormulaElement + - FormulaBrick - Functions - Operators - ScreenModes @@ -310,16 +339,23 @@ additional_serialization_classes: - AskSpeechBrick - Project - ThreadScheduler - - DataContainer - SupportProject - SupportDataContainer - BroadcastMessageBrick - XstreamSerializer + - Scene + - PenColor + - ScriptBrickBaseType + - UserVariableBrickInterface + - Nameable + - UserData + - R + preserved_interfaces: [Brick, BroadcastMessage, Converter, LoopBeginBrick, MindstormsSensor, - MindstormsCommand, ScriptBrick] + MindstormsCommand, ScriptBrick, UserVariableBrickInterface, Nameable, UserData] additional_helper_classes: - BroadcastMessage @@ -353,15 +389,10 @@ additional_helper_classes: - UserBrickVariableBehaviour - ProjectVariableBehaviour - ProjectListBehaviour + - Nameable + - R class_to_preserved_fields_mapping: - DataContainer: - - project - - spriteVariableBehaviour - - spriteListBehaviour - - userBrickVariableBehaviour - - projectVariableBehaviour - - projectListBehaviour GoToBrick: - oldSelectedObject Scene: @@ -375,14 +406,12 @@ class_to_preserved_fields_mapping: PointToBrick: - oldSelectedObject Script: - - brick + - scriptBrick Sprite: [look, isPaused, newUserBrickNext, isBackpackObject] SetLookBrick: - oldSelectedLook - wait - SetLookByIndexBrick: - - wait UserVariable: - value WhenScript: @@ -417,6 +446,7 @@ class_to_preserved_fields_mapping: - version UserList: - list + - name UserBrickParameter: - parent SetVariableBrick: @@ -459,6 +489,9 @@ class_to_preserved_methods_mapping: - setIfBrickReferences - setIfThenBrickReferences - setLoopBrickReferences + - getScriptBrick + ScriptBrick: + - getScript StartScript: - getScriptBrick WhenScript: @@ -474,6 +507,8 @@ class_to_preserved_methods_mapping: - getName - isBackgroundObject - getDefaultScene + - getUserVariable + - getUserList SoundInfo: - compareTo - setTitle @@ -511,6 +546,8 @@ class_to_preserved_methods_mapping: - updateUserVariableReferencesInUserVariableBricks - getListWithAllBricks - addUserBrick + - getUserVariable + - getUserList UserVariablesContainer: - addSpriteUserVariableToSprite - getOrCreateVariableListForSprite @@ -519,38 +556,6 @@ class_to_preserved_methods_mapping: - getFormulaWithBrickField - setFormulaWithBrickField - getFormulas - DataContainer: - - addUserBrickVariableToUserBrick - - addUserBrickVariableToUserBrickIfNotExists - - addSpriteUserVariable - - addSpriteUserVariableToSprite - - addSpriteVariableIfDoesNotExist - - addProjectUserVariable - - getOrCreateVariableListForUserBrick - - getOrCreateVariableListForSprite - - cleanVariableListForSprite - - getUserVariable - - getUserVariableContext - - addSpriteUserList - - addSpriteUserListToSprite - - addProjectUserList - - getOrCreateUserListListForSprite - - findProjectVariable - - findProjectList - - findSpriteUserVariable - - findSpriteUserList - - getUserList - - existSpriteList - - getCurrentUserBrick - - setSpriteVariablesForSupportContainer - - getProjectVariables - - getProjectLists - - removeSpriteVariableWithSameSpriteName - - setUserBrickVariables - - getSpriteListMap - - getSpriteVariableMap - - getCurrentSprite - - getUserBrickVariableMap AddItemToUserListBrick: - initializeBrickFields ChangeTransparencyByNBrick: @@ -664,6 +669,8 @@ class_to_preserved_methods_mapping: XmlHeader: - setlandscapeMode - setUrl + - setProjectName + - getProjectName NfcTagData: - compareTo WhenBackgroundChangesScript: @@ -672,14 +679,71 @@ class_to_preserved_methods_mapping: - getScriptBrick WhenConditionScript: - getScriptBrick - + UserVariableBrickInterface: + - getUserVariable + - setUserVariable + BroadcastReceiverBrick: + - getScript + - getBroadcastMessage + - setBroadcastMessage + BroadcastMessageBrick: + - getBroadcastMessage + - setBroadcastMessage + XStreamConcurrentFormulaHashMapConverter: + - marshal + - unmarshal + - canConvert + CatroidFieldKeySorter: + - sort + - findAnnotationInClassHierarchy + - sortAlphabeticallyByClassHierarchy + - sortByList + - getAliasOrFieldName + - checkMissingSerializableField + - isSerializable + SpriteFactory: + - newInstance + Nameable: + - getName + - setName + XStreamSettingConverter: + - doMarshal + - canConvert + - doUnmarshal + XStreamSpriteConverter: + - doMarshal + - canConvert + - doUnmarshal + XStreamUserVariableConverter: + - doMarshal + - canConvert + - doUnmarshal + XStreamScriptConverter: + - doMarshal + - canConvert + - doUnmarshal + XStreamBrickConverter: + - doMarshal + - canConvert + - doUnmarshal + CloneBrick: + - CloneBrick + remove_fields_mapping: + Brick: + [Resources] BrickValues: [PHYSIC_TYPE, PHYSIC_MASS, PHYSIC_BOUNCE_FACTOR, PHYSIC_FRICTION, PHYSIC_GRAVITY, PHYSIC_VELOCITY, PHYSIC_TURN_DEGREES] Constants: - [DEFAULT_ROOT, TMP_PATH, TMP_IMAGE_PATH, TMP_LOOKS_PATH, TMP_SOUNDS_PATH, TEXT_TO_SPEECH_TMP_PATH] + [ + DEFAULT_ROOT, TMP_PATH, TMP_IMAGE_PATH, TMP_LOOKS_PATH, TMP_SOUNDS_PATH, TEXT_TO_SPEECH_TMP_PATH, + MAIN_URL_HTTPS, SHARE_PROGRAM_URL, CATROBAT_TERMS_OF_USE_URL, CATROBAT_HELP_URL, + CATROBAT_TOKEN_LOGIN_URL, CATROBAT_DELETE_ACCOUNT_URL, CACHE_DIR, EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY, + BACKPACK_DIRECTORY, POCKET_PAINT_CACHE_DIR, CAMERA_CACHE_DIR, SOUND_RECORDER_CACHE_DIR, MEDIA_LIBRARY_CACHE_DIR, + BACKPACK_FILE, BACKPACK_SCENE_DIRECTORY, BACKPACK_SOUND_DIRECTORY, BACKPACK_IMAGE_DIRECTORY, LegoSensorType, LegoPort + ] Look: - [actionsToRestart, pixmap, whenParallelAction, shader] + [actionsToRestart, pixmap, whenParallelAction, shader, RotationStyle, scheduler] NXTSensor: - connection StorageHandler: @@ -693,6 +757,10 @@ remove_fields_mapping: FormulaBrick: - backPackedListData - backPackedVariableData + ProjectManager: + - brickController + Sprite: + - nfcTagList remove_methods_mapping: GoToBrick: @@ -704,6 +772,7 @@ remove_methods_mapping: Sprite: - cloneUserBricks - cloneLook + - getNfcTagList Script: - setIfBrickReferences - setIfThenBrickReferences @@ -713,7 +782,7 @@ remove_methods_mapping: [uploadProject, loadProject, cancelLoadProject, canLoadProject, saveProject, initializeDefaultProject, initializeDroneProject, initializeNewProject, deleteCurrentProject, checkCurrentSprite, checkCurrentScript, deleteProject, renameProject, - addScript, createAndShowUploadDialog] + addScript, createAndShowUploadDialog, loadLegoNXTSettingsFromProject, loadLegoEV3SettingsFromProject, createNewEmptyProject, createNewExampleProject] XmlHeader: - setTags Look: @@ -734,6 +803,10 @@ remove_methods_mapping: - isClone UserBrickVariableBehaviour: - isClone + WhenConditionBrick: + - getPositionInScript + WhenBackgroundChangesBrick: + - getPositionInScript remove_packages_mapping: - android @@ -741,3 +814,13 @@ remove_packages_mapping: - org.catrobat.catroid.R - org.catrobat.catroid.common.Constants.DEFAULT_ROOT - org.catrobat.catroid.pocketmusic + +remove_annotations: + - VisibleForTesting + - Look.RotationStyle +remove_superclass: + - Image +remove_method_parameter_at_position: + addAllowedBrickField: + - 1 + \ No newline at end of file diff --git a/sourcecodefilter/src/sourcecodefilter/Config.java b/sourcecodefilter/src/sourcecodefilter/Config.java index a53821a1..e3febaec 100644 --- a/sourcecodefilter/src/sourcecodefilter/Config.java +++ b/sourcecodefilter/src/sourcecodefilter/Config.java @@ -78,8 +78,8 @@ public Map> getMap(String key) throws IOException { Map> itemsMap = new HashMap<>(); for (Entry> entry : ((Map>)configMap.get(key)).entrySet()) { HashSet itemSet = new HashSet<>(); - for (String item : entry.getValue()) { - itemSet.add(replacePlaceholders(item)); + for (Object item : entry.getValue()) { + itemSet.add(replacePlaceholders(item.toString())); } itemsMap.put(entry.getKey(), itemSet); } diff --git a/sourcecodefilter/src/sourcecodefilter/ConverterRelevantCatroidSource.java b/sourcecodefilter/src/sourcecodefilter/ConverterRelevantCatroidSource.java old mode 100755 new mode 100644 index 5b11b247..235f67a6 --- a/sourcecodefilter/src/sourcecodefilter/ConverterRelevantCatroidSource.java +++ b/sourcecodefilter/src/sourcecodefilter/ConverterRelevantCatroidSource.java @@ -54,6 +54,7 @@ public class ConverterRelevantCatroidSource { private Set fieldsToRemove; private Set methodsToPreserve; private Set methodsToRemove; + private Set annotationsToRemove; private CompilationUnit sourceAst; private Boolean isSerializationClass; private Document internalSource; diff --git a/sourcecodefilter/src/sourcecodefilter/SourceCodeFilter.java b/sourcecodefilter/src/sourcecodefilter/SourceCodeFilter.java old mode 100755 new mode 100644 index 7efb9163..9962dd30 --- a/sourcecodefilter/src/sourcecodefilter/SourceCodeFilter.java +++ b/sourcecodefilter/src/sourcecodefilter/SourceCodeFilter.java @@ -37,20 +37,22 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; import org.eclipse.jdt.core.dom.Annotation; +import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; import org.eclipse.jdt.core.dom.Block; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.EnumDeclaration; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.IExtendedModifier; import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.ParameterizedType; import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.Statement; import org.eclipse.jdt.core.dom.Type; @@ -92,24 +94,35 @@ public class SourceCodeFilter { public static Map> classToPreservedMethodsMapping = null; public static Map> removeFieldsMapping = null; public static Map> removeMethodsMapping = null; + public static Set REMOVE_ANNOTATIONS = null; + public static Set REMOVE_SUPERCLASS = null; + public static Map> removeMethodParameterAtPosition = null; @SuppressWarnings("deprecation") private static ASTParser astParser = ASTParser.newParser(AST.JLS4); static { astParser.setKind(ASTParser.K_COMPILATION_UNIT); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "deprecation" }) private static void removeUnsupportedClassHierarchyTypesIn(ConverterRelevantCatroidSource catroidSource) { final List types = catroidSource.getSourceAst().types(); List superInterfaceTypes = null; - + for (AbstractTypeDeclaration abstractTypeDecl : types) { if (abstractTypeDecl.getNodeType() == ASTNode.TYPE_DECLARATION) { TypeDeclaration typeDecl = (TypeDeclaration) abstractTypeDecl; superInterfaceTypes = typeDecl.superInterfaceTypes(); + // Delete inner types for (TypeDeclaration innerType : Arrays.asList(typeDecl.getTypes())) { innerType.delete(); } + + if (typeDecl.getSuperclassType() != null) + { + if (REMOVE_SUPERCLASS.contains(typeDecl.getSuperclassType().toString())) { + typeDecl.getSuperclassType().delete(); + } + } } else if (abstractTypeDecl.getNodeType() == ASTNode.ENUM_DECLARATION) { EnumDeclaration enumDecl = (EnumDeclaration) abstractTypeDecl; @@ -122,14 +135,23 @@ private static void removeUnsupportedClassHierarchyTypesIn(ConverterRelevantCatr // modify type hierarchy for (Iterator iterator = superInterfaceTypes.iterator(); iterator.hasNext();) { Type interfaceType = iterator.next(); - if (interfaceType.getNodeType() == ASTNode.SIMPLE_TYPE) { - String interfaceName = ((SimpleType) interfaceType).getName().getFullyQualifiedName(); + if (interfaceType.getNodeType() == ASTNode.SIMPLE_TYPE ) { + String interfaceName = ((SimpleType)interfaceType).getName().getFullyQualifiedName(); + if (! (PRESERVED_INTERFACES.contains(interfaceName))) { + iterator.remove(); + } + } + else if (interfaceType.getNodeType() == ASTNode.PARAMETERIZED_TYPE) { + ParameterizedType t1 = ((ParameterizedType)interfaceType); + SimpleType interfaceName = (SimpleType)(t1.getType()); + String n = interfaceName.getName().getFullyQualifiedName(); if (! (PRESERVED_INTERFACES.contains(interfaceName))) { iterator.remove(); } } } } + } @SuppressWarnings("unchecked") @@ -148,7 +170,6 @@ private static boolean isRelatedToNonTransientFields(final String methodName, Se for (VariableDeclarationFragment varDeclFrgmt : ((List)fieldDeclaration.fragments())) { String fieldName = varDeclFrgmt.getName().getIdentifier(); String fieldNameFirstUpper = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); - // System.out.println(methodName + " " + fieldNameFirstUpper); if (methodName.endsWith(fieldNameFirstUpper)) { return true; } @@ -182,7 +203,7 @@ private static void removeUnsupportedImportsIn(ConverterRelevantCatroidSource ca ImportDeclaration importDecl = iterator.next(); String importName = importDecl.getName().getFullyQualifiedName(); - if (importName.contains("android") || importName.startsWith("com.") || importName.endsWith(".R") + if (importName.contains("android") || importName.startsWith("com.") /*|| importName.endsWith(".R")*/ || importName.contains("catroid.ui")) { if (!importName.startsWith("com.thoughtworks") && !project.isRelevantClass(importName)) { iterator.remove(); @@ -217,6 +238,21 @@ private static boolean isImportOfRemovedPackage(String importName) { return false; } + + private static void removeUnneededAnnotations(List modifiers) + { + for (ASTNode modifier : modifiers) + { + if (modifier.getNodeType() == ASTNode.MARKER_ANNOTATION || modifier.getNodeType() == ASTNode.NORMAL_ANNOTATION) + { + if (REMOVE_ANNOTATIONS.contains(((Annotation)modifier).getTypeName().toString())) + { + modifier.delete(); + } + } + } + } + @SuppressWarnings("unchecked") private static void removeNonSerializedFieldsAndUnusedMethodsIn(ConverterRelevantCatroidSource source) { final List types = source.getSourceAst().types(); @@ -231,6 +267,7 @@ private static void removeNonSerializedFieldsAndUnusedMethodsIn(ConverterRelevan assert fieldDecl.fragments().size() == 1 : String.format("Unsupported multi field declaration: '%s'", fieldDecl.toString()); String fieldName = ((VariableDeclarationFragment) fieldDecl.fragments().get(0)).getName().getIdentifier(); + removeUnneededAnnotations(fieldDecl.modifiers()); if (source.isRemovedField(fieldName)) { fieldDecl.delete(); } else if (Modifier.isTransient(fieldDecl.getModifiers()) && !(source.isPreservedField(fieldName))) { @@ -239,24 +276,36 @@ private static void removeNonSerializedFieldsAndUnusedMethodsIn(ConverterRelevan nonTransientFields.add(fieldDecl); } } + else if (bodyDecl.getNodeType() == ASTNode.ANNOTATION_TYPE_DECLARATION) + { + AnnotationTypeDeclaration annotationDecl = (AnnotationTypeDeclaration) bodyDecl; + String fieldName = annotationDecl.getName().getIdentifier(); + if (source.isRemovedField(fieldName)) + { + annotationDecl.delete(); + } + } } - for (BodyDeclaration bodyDecl : new ArrayList(abstractTypeDecl.bodyDeclarations())) { if (bodyDecl.getNodeType() == ASTNode.METHOD_DECLARATION) { MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDecl; if (! methodDeclaration.isConstructor()) { // removeOverrideAnnotation(methodDeclaration); + final String methodName = methodDeclaration.getName().getIdentifier(); + removeUnneededAnnotations(methodDeclaration.modifiers()); + if (methodName.equals("init")) { Block body = methodDeclaration.getBody(); for (Iterator iterator2 = body.statements().iterator(); iterator2.hasNext();) { iterator2.next(); iterator2.remove(); } - } else if (source.isRemovedMethod(methodName)) { + } + else if (source.isRemovedMethod(methodName)) { methodDeclaration.delete(); } else if (!(source.isPreservedMethod(methodName))) { - if (!(isRelatedToNonTransientFields(methodName, nonTransientFields)) || isOverriding(methodDeclaration)) { + if (!(isRelatedToNonTransientFields(methodName, nonTransientFields)) /*|| isOverriding(methodDeclaration)*/ ) { methodDeclaration.delete(); } } @@ -276,15 +325,15 @@ public static void writePreprocessedCatrobatSource(final File inputProjectDir, F for (ConverterRelevantCatroidSource catroidSource : ConverterRelevantCatroidSource.converterRelevantSources(project)) { final String fullClassName = catroidSource.getQualifiedClassName(); - // if class is part of Pocket Code serialization XML if (catroidSource.isSerializationClass()) { // remove types from class type hierarchy in class removeUnsupportedClassHierarchyTypesIn(catroidSource); // remove all fields are not serializable (`transient` keyword) in class. Skip fields to be ignored // remove all methods which method name do not include a serialize field name in class. Skip method names to ignore. - removeNonSerializedFieldsAndUnusedMethodsIn(catroidSource); + //removeNonSerializedFieldsAndUnusedMethodsIn(catroidSource); } + removeNonSerializedFieldsAndUnusedMethodsIn(catroidSource); removeUnsupportedImportsIn(catroidSource, project); @@ -313,7 +362,7 @@ public static void writePreprocessedCatrobatSource(final File inputProjectDir, F if (tryCatchBlocksToBeRemoved != null) { new TryCatchFilter(catroidSource, tryCatchBlocksToBeRemoved).removeUnallowedTryCatchBlocks();; } - + Set inlineClassesToBeInjected = INJECT_INLINE_CLASSES_TO_EXISTING_CLASS.get(catroidSource.getQualifiedClassName()); if (inlineClassesToBeInjected != null) { new InlineClassInjector(catroidSource, inlineClassesToBeInjected).inject(); @@ -361,7 +410,9 @@ public static void main(String[] args) { classToPreservedMethodsMapping = config.getMap("class_to_preserved_methods_mapping"); removeFieldsMapping = config.getMap("remove_fields_mapping"); removeMethodsMapping = config.getMap("remove_methods_mapping"); - + REMOVE_ANNOTATIONS = config.getSet("remove_annotations"); + REMOVE_SUPERCLASS = config.getSet("remove_superclass"); + removeMethodParameterAtPosition = config.getMap("remove_method_parameter_at_position"); // download Catroid code project from Github File downloadDir = new File(downloadPath); downloadDir.mkdirs(); // create intermediate recursive directories if needed... diff --git a/sourcecodefilter/src/sourcecodefilter/filter/MethodInvocationFilter.java b/sourcecodefilter/src/sourcecodefilter/filter/MethodInvocationFilter.java index 5b564691..30e9d75b 100644 --- a/sourcecodefilter/src/sourcecodefilter/filter/MethodInvocationFilter.java +++ b/sourcecodefilter/src/sourcecodefilter/filter/MethodInvocationFilter.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Set; +import org.eclipse.core.internal.resources.refresh.win32.Convert; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; @@ -37,13 +38,14 @@ import org.eclipse.jdt.core.dom.MethodInvocation; import sourcecodefilter.ConverterRelevantCatroidSource; +import sourcecodefilter.SourceCodeFilter; public class MethodInvocationFilter extends ASTVisitor { final private ConverterRelevantCatroidSource catroidSource; final private Set methodInvocationsToBeRemoved; final private Set methodInvocationsWithParameterToBeRemoved; - + public MethodInvocationFilter(ConverterRelevantCatroidSource catroidSource, Set methodInvocationsToBeRemoved, Set methodInvocationsWithParameterToBeRemoved) { @@ -106,6 +108,14 @@ public boolean visit(MethodInvocation methodInvocation) { methodInvocation.getParent().delete(); } } + + if (SourceCodeFilter.removeMethodParameterAtPosition.containsKey(fullName) ) { + Set indicesToRemove = SourceCodeFilter.removeMethodParameterAtPosition.get(fullName); + for (String indToRemove : indicesToRemove) + { + methodInvocation.arguments().remove(Integer.parseInt(indToRemove)); + } + } return false; } }