├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
└── org.eclipse.jdt.ui.prefs
├── LICENSE
├── META-INF
└── MANIFEST.MF
├── README.md
├── build.properties
├── icons
├── 0.jpg
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
├── compass.png
├── glasgowstoplist.txt
├── magnifier.png
└── repair.png
├── plugin.xml
└── src
├── ca
└── concordia
│ └── jdeodorant
│ └── clone
│ └── parsers
│ ├── CCFinderOutputParser.java
│ ├── CloneDROutputParser.java
│ ├── CloneDetectorOutputParseException.java
│ ├── CloneDetectorOutputParser.java
│ ├── CloneDetectorOutputParserFactory.java
│ ├── CloneDetectorOutputParserProgressObserver.java
│ ├── CloneDetectorType.java
│ ├── CloneGroup.java
│ ├── CloneGroupList.java
│ ├── CloneInstance.java
│ ├── CloneInstanceLocationInfo.java
│ ├── CloneInstanceStatus.java
│ ├── ClonesRelativeLocation.java
│ ├── ConQATOutputParser.java
│ ├── DeckardOutputParser.java
│ ├── InvalidInputFileException.java
│ ├── JavaModelUtility.java
│ ├── NiCadOutputParser.java
│ ├── ResourceInfo.java
│ └── TextDiff.java
└── gr
└── uom
└── java
├── ast
├── ASTInformation.java
├── ASTInformationGenerator.java
├── ASTReader.java
├── AbstractMethodDeclaration.java
├── AbstractMethodInvocationObject.java
├── Access.java
├── AnonymousClassDeclarationObject.java
├── ArrayAccessObject.java
├── ArrayCreationObject.java
├── ClassDeclarationObject.java
├── ClassInstanceCreationObject.java
├── ClassObject.java
├── CommentObject.java
├── CommentType.java
├── CompilationErrorDetectedException.java
├── CompilationUnitCache.java
├── ConstructorInvocationObject.java
├── ConstructorObject.java
├── CreationObject.java
├── EnumConstantDeclarationObject.java
├── FieldInstructionObject.java
├── FieldObject.java
├── IfStatementExpressionAnalyzer.java
├── Indexer.java
├── LibraryClassStorage.java
├── LiteralObject.java
├── LiteralType.java
├── LocalVariableDeclarationObject.java
├── LocalVariableInstructionObject.java
├── MethodInvocationObject.java
├── MethodObject.java
├── ParameterObject.java
├── Standalone.java
├── SuperFieldInstructionObject.java
├── SuperMethodInvocationObject.java
├── SystemObject.java
├── TypeCheckCodeFragmentAnalyzer.java
├── TypeObject.java
├── TypeSearchRequestor.java
├── VariableDeclarationObject.java
├── association
│ ├── Association.java
│ └── AssociationDetection.java
├── decomposition
│ ├── AbstractExpression.java
│ ├── AbstractMethodFragment.java
│ ├── AbstractStatement.java
│ ├── CatchClauseObject.java
│ ├── CompositeStatementObject.java
│ ├── ExpressionType.java
│ ├── MethodBodyObject.java
│ ├── StatementObject.java
│ ├── StatementType.java
│ ├── SynchronizedStatementObject.java
│ ├── TryStatementObject.java
│ ├── cfg
│ │ ├── AbstractVariable.java
│ │ ├── BasicBlock.java
│ │ ├── BasicBlockCFG.java
│ │ ├── CFG.java
│ │ ├── CFGBlockNode.java
│ │ ├── CFGBranchConditionalNode.java
│ │ ├── CFGBranchDoLoopNode.java
│ │ ├── CFGBranchIfNode.java
│ │ ├── CFGBranchLoopNode.java
│ │ ├── CFGBranchNode.java
│ │ ├── CFGBranchSwitchNode.java
│ │ ├── CFGBreakNode.java
│ │ ├── CFGContinueNode.java
│ │ ├── CFGExitNode.java
│ │ ├── CFGNode.java
│ │ ├── CFGSwitchCaseNode.java
│ │ ├── CFGSynchronizedNode.java
│ │ ├── CFGThrowNode.java
│ │ ├── CFGTryNode.java
│ │ ├── CompositeVariable.java
│ │ ├── Flow.java
│ │ ├── Graph.java
│ │ ├── GraphEdge.java
│ │ ├── GraphNode.java
│ │ ├── MethodCallAnalyzer.java
│ │ ├── PDG.java
│ │ ├── PDGAbstractDataDependence.java
│ │ ├── PDGAntiDependence.java
│ │ ├── PDGBlockNode.java
│ │ ├── PDGControlDependence.java
│ │ ├── PDGControlPredicateNode.java
│ │ ├── PDGDataDependence.java
│ │ ├── PDGDependence.java
│ │ ├── PDGDependenceType.java
│ │ ├── PDGExitNode.java
│ │ ├── PDGExpression.java
│ │ ├── PDGMethodEntryNode.java
│ │ ├── PDGNode.java
│ │ ├── PDGObjectSliceUnion.java
│ │ ├── PDGObjectSliceUnionCollection.java
│ │ ├── PDGOutputDependence.java
│ │ ├── PDGSlice.java
│ │ ├── PDGSliceUnion.java
│ │ ├── PDGSliceUnionCollection.java
│ │ ├── PDGStatementNode.java
│ │ ├── PDGSynchronizedNode.java
│ │ ├── PDGTryNode.java
│ │ ├── PlainVariable.java
│ │ ├── ReachingAliasSet.java
│ │ └── mapping
│ │ │ ├── BottomUpCDTMapper.java
│ │ │ ├── CloneInstanceMapper.java
│ │ │ ├── CloneRefactoringType.java
│ │ │ ├── CloneStructureNode.java
│ │ │ ├── CloneType.java
│ │ │ ├── CodeFragmentDecomposer.java
│ │ │ ├── CompleteSubTreeMatch.java
│ │ │ ├── ControlDependenceTreeGenerator.java
│ │ │ ├── ControlDependenceTreeNode.java
│ │ │ ├── ControlDependenceTreeNodeMatchPair.java
│ │ │ ├── ControlDependenceTreeNodeMatchPairComparator.java
│ │ │ ├── DivideAndConquerMatcher.java
│ │ │ ├── ExtractStatementsVisitor.java
│ │ │ ├── IdBasedGap.java
│ │ │ ├── IdBasedMapping.java
│ │ │ ├── IdenticalStatementDecomposer.java
│ │ │ ├── MappingState.java
│ │ │ ├── NodeMapping.java
│ │ │ ├── PDGEdgeMapping.java
│ │ │ ├── PDGElseGap.java
│ │ │ ├── PDGElseMapping.java
│ │ │ ├── PDGMapper.java
│ │ │ ├── PDGNodeGap.java
│ │ │ ├── PDGNodeMapping.java
│ │ │ ├── PDGRegionSubTreeMapper.java
│ │ │ ├── PDGSubTreeMapper.java
│ │ │ ├── PreconditionExaminer.java
│ │ │ ├── StatementCollector.java
│ │ │ ├── SubTreeMatchComparator.java
│ │ │ ├── SwitchBodyDecomposer.java
│ │ │ ├── TopDownCDTMapper.java
│ │ │ ├── VariableBindingKeyPair.java
│ │ │ ├── VariableBindingPair.java
│ │ │ └── precondition
│ │ │ ├── BoldStyler.java
│ │ │ ├── DualExpressionPreconditionViolation.java
│ │ │ ├── DualExpressionWithCommonSuperTypePreconditionViolation.java
│ │ │ ├── ExpressionPreconditionViolation.java
│ │ │ ├── NormalStyler.java
│ │ │ ├── NotAllPossibleExecutionFlowsEndInReturnPreconditionViolation.java
│ │ │ ├── PreconditionViolation.java
│ │ │ ├── PreconditionViolationType.java
│ │ │ ├── ReturnedVariablePreconditionViolation.java
│ │ │ ├── StatementPreconditionViolation.java
│ │ │ ├── Suggestion.java
│ │ │ ├── UncommonSuperclassPreconditionViolation.java
│ │ │ └── ZeroMatchedStatementsPreconditionViolation.java
│ └── matching
│ │ ├── ASTNodeDifference.java
│ │ ├── ASTNodeMatcher.java
│ │ ├── BindingSignature.java
│ │ ├── BindingSignaturePair.java
│ │ ├── BindingSignatureVisitor.java
│ │ ├── Difference.java
│ │ ├── DifferenceType.java
│ │ ├── FieldAccessReplacedWithGetterInvocationDifference.java
│ │ ├── FieldAssignmentReplacedWithSetterInvocationDifference.java
│ │ ├── NodePair.java
│ │ ├── NodePairComparisonCache.java
│ │ ├── conditional
│ │ ├── AbstractControlCase.java
│ │ ├── AbstractControlStructure.java
│ │ ├── AbstractControlStructureUtilities.java
│ │ ├── IfControlCase.java
│ │ ├── IfControlStructure.java
│ │ ├── Pair.java
│ │ ├── SwitchControlCase.java
│ │ ├── SwitchControlStructure.java
│ │ └── TernaryControlStructure.java
│ │ └── loop
│ │ ├── AbstractControlVariable.java
│ │ ├── AbstractLoop.java
│ │ ├── AbstractLoopBindingInformation.java
│ │ ├── AbstractLoopUtilities.java
│ │ ├── ConditionalLoop.java
│ │ ├── ConditionalLoopASTNodeMatcher.java
│ │ ├── ControlVariable.java
│ │ ├── EarliestStartPositionComparator.java
│ │ ├── EnhancedForLoop.java
│ │ ├── VariableUpdater.java
│ │ └── VariableValue.java
├── delegation
│ ├── DelegationDetection.java
│ ├── DelegationPath.java
│ └── DelegationTree.java
├── inheritance
│ ├── CompleteInheritanceDetection.java
│ ├── InheritanceDetection.java
│ ├── InheritanceTree.java
│ └── TypeBindingInheritanceDetection.java
├── metrics
│ ├── ConnectivityMetric.java
│ ├── LCOM.java
│ └── MMImportCoupling.java
├── util
│ ├── ExpressionExtractor.java
│ ├── ExpressionInstanceChecker.java
│ ├── InstanceOfArrayAccess.java
│ ├── InstanceOfArrayCreation.java
│ ├── InstanceOfAssignment.java
│ ├── InstanceOfBranchingStatement.java
│ ├── InstanceOfBreakStatement.java
│ ├── InstanceOfCastExpression.java
│ ├── InstanceOfClassInstanceCreation.java
│ ├── InstanceOfConditionalExpression.java
│ ├── InstanceOfConstructorInvocation.java
│ ├── InstanceOfContinueStatement.java
│ ├── InstanceOfDoStatement.java
│ ├── InstanceOfEnhancedForStatement.java
│ ├── InstanceOfExpression.java
│ ├── InstanceOfFieldAccess.java
│ ├── InstanceOfForStatement.java
│ ├── InstanceOfIfStatement.java
│ ├── InstanceOfInfixExpression.java
│ ├── InstanceOfInstanceofExpression.java
│ ├── InstanceOfLiteral.java
│ ├── InstanceOfMethodInvocation.java
│ ├── InstanceOfPostfixExpression.java
│ ├── InstanceOfPrefixExpression.java
│ ├── InstanceOfReturnStatement.java
│ ├── InstanceOfSimpleName.java
│ ├── InstanceOfSuperFieldAccess.java
│ ├── InstanceOfSuperMethodInvocation.java
│ ├── InstanceOfSwitchStatement.java
│ ├── InstanceOfThisExpression.java
│ ├── InstanceOfTryStatement.java
│ ├── InstanceOfTypeDeclarationStatement.java
│ ├── InstanceOfTypeLiteral.java
│ ├── InstanceOfVariableDeclarationExpression.java
│ ├── InstanceOfVariableDeclarationStatement.java
│ ├── InstanceOfVariableModifier.java
│ ├── InstanceOfWhileStatement.java
│ ├── MethodDeclarationUtility.java
│ ├── StatementExtractor.java
│ ├── StatementInstanceChecker.java
│ ├── SuperMethodInvocationVisitor.java
│ ├── ThrownExceptionVisitor.java
│ ├── TopicFinder.java
│ ├── TypeVisitor.java
│ └── math
│ │ ├── AdjacencyList.java
│ │ ├── Cluster.java
│ │ ├── Clustering.java
│ │ ├── DoubleArray.java
│ │ ├── Edge.java
│ │ ├── Hierarchical.java
│ │ ├── HumaniseCamelCase.java
│ │ ├── LevenshteinDistance.java
│ │ ├── Node.java
│ │ ├── Stemmer.java
│ │ └── TarjanAlgorithm.java
└── visualization
│ ├── ClassFigure.java
│ ├── ClassFigureMover.java
│ ├── CompartmentFigure.java
│ ├── CompartmentFigureBorder.java
│ ├── ConnectionType.java
│ ├── DecorationConstants.java
│ ├── EntityFigure.java
│ ├── EntityFigureListener.java
│ ├── FeatureEnviedMethodInformationControl.java
│ ├── FeatureEnviedMethodInformationControlCreator.java
│ ├── FeatureEnvyDiagram.java
│ ├── FeatureEnvyVisualizationData.java
│ ├── GodClassDiagram.java
│ ├── GodClassDiagram2.java
│ ├── GodClassInformationControl.java
│ ├── GodClassInformationControlCreator.java
│ ├── GodClassVisualizationData.java
│ ├── ICustomInformationControlCreator.java
│ ├── IInformationProvider.java
│ ├── InformationControlManager.java
│ ├── JConnection.java
│ ├── LeftAnchor.java
│ ├── Legend.java
│ ├── MethodClassSection.java
│ ├── MyContentProposalProvider.java
│ ├── PMClassFigure.java
│ ├── PackageFigure.java
│ ├── PackageMapDiagram.java
│ ├── PackageMapDiagramInformationProvider.java
│ ├── PackageMapFigure.java
│ ├── ProportionalFlowLayout.java
│ ├── RightAnchor.java
│ ├── SearchDialog.java
│ ├── SearchInputAction.java
│ ├── SectionCompartment.java
│ ├── SmellyClassMouseListener.java
│ ├── VisualizationData.java
│ ├── ZoomAction.java
│ └── ZoomInputAction.java
├── distance
├── CandidateRefactoring.java
├── ClusterSizeComparator.java
├── DistanceCalculator.java
├── DistanceMatrix.java
├── Entity.java
├── ExtractClassCandidateGroup.java
├── ExtractClassCandidateRefactoring.java
├── ExtractedConcept.java
├── MoveMethodCandidateRefactoring.java
├── MyAbstractExpression.java
├── MyAbstractStatement.java
├── MyAttribute.java
├── MyAttributeInstruction.java
├── MyClass.java
├── MyCompositeStatement.java
├── MyMethod.java
├── MyMethodBody.java
├── MyMethodInvocation.java
├── MyStatement.java
└── MySystem.java
├── history
├── Evolution.java
├── FeatureEnvyEvolution.java
├── MethodEvolution.java
├── ProjectEvolution.java
├── ProjectVersion.java
├── ProjectVersionPair.java
└── TypeCheckingEvolution.java
└── jdeodorant
├── preferences
├── PreferenceConstants.java
├── PreferenceInitializer.java
└── PropertyManagerPreferencePage.java
└── refactoring
├── Activator.java
├── actions
└── BadSmellsMenu.java
├── manipulators
├── ASTSlice.java
├── ASTSliceGroup.java
├── ExtractClassRefactoring.java
├── ExtractClassRefactoringDescriptor.java
├── ExtractCloneRefactoring.java
├── ExtractCloneRefactoringDescriptor.java
├── ExtractMethodFragmentRefactoring.java
├── ExtractMethodRefactoring.java
├── ExtractMethodRefactoringDescriptor.java
├── MoveMethodRefactoring.java
├── MoveMethodRefactoringDescriptor.java
├── PolymorphismRefactoring.java
├── RefactoringUtility.java
├── ReplaceConditionalWithPolymorphism.java
├── ReplaceConditionalWithPolymorphismDescriptor.java
├── ReplaceTypeCodeWithStateStrategy.java
├── ReplaceTypeCodeWithStateStrategyDescriptor.java
├── TypeCheckElimination.java
└── TypeCheckEliminationGroup.java
└── views
├── CloneDiffContentProvider.java
├── CloneDiffSide.java
├── CloneDiffStyledLabelProvider.java
├── CloneDiffTooltip.java
├── CloneDiffWizardPage.java
├── CloneRefactoringAction.java
├── CodeSmellPackageExplorer.java
├── CodeSmellVisualization.java
├── CodeSmellVisualizationDataSingleton.java
├── DuplicatedCode.java
├── ElementChangedListener.java
├── EvolutionDialog.java
├── EvolutionRow.java
├── ExtractClassInputPage.java
├── ExtractMethodInputPage.java
├── FeatureEnvy.java
├── GodClass.java
├── ImportClonesWizard.java
├── ImportClonesWizardPage.java
├── LabelControlContribution.java
├── LongMethod.java
├── MethodEvolutionAction.java
├── MethodNameValidator.java
├── MoveMethodInputPage.java
├── MultilineButton.java
├── MyComboBoxCellEditor.java
├── MyRefactoringWizard.java
├── ReplaceTypeCodeWithStateStrategyInputPage.java
├── SliceAnnotation.java
├── SliceProfileAction.java
├── SliceProfileDialog.java
├── SliceProfileRow.java
├── StringCompareEditorInput.java
├── StyledStringStyler.java
├── StyledStringVisitor.java
├── TypeChecking.java
└── ZoomValueValidator.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | JDeodorant
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.pde.ManifestBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.pde.SchemaBuilder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.pde.PluginNature
26 | org.eclipse.jdt.core.javanature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Thu Jun 21 00:11:49 EEST 2007
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.5
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.5
13 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | #Thu Jun 21 00:11:49 EEST 2007
2 | eclipse.preferences.version=1
3 | internal.default.compliance=default
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Nikolaos Tsantalis
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: JDeodorant Plug-in
4 | Bundle-SymbolicName: gr.uom.java.jdeodorant; singleton:=true
5 | Bundle-Version: 5.0.68
6 | Bundle-Activator: gr.uom.java.jdeodorant.refactoring.Activator
7 | Bundle-Localization: plugin
8 | Require-Bundle: org.eclipse.ui,
9 | org.eclipse.core.runtime,
10 | org.eclipse.jdt.core,
11 | org.eclipse.core.resources,
12 | org.eclipse.jface.text,
13 | org.eclipse.ui.workbench.texteditor,
14 | org.eclipse.jdt.ui,
15 | org.eclipse.ltk.core.refactoring,
16 | org.eclipse.ltk.ui.refactoring,
17 | org.eclipse.compare,
18 | org.eclipse.draw2d,
19 | org.eclipse.core.filebuffers,
20 | org.eclipse.ui.ide
21 | Bundle-ActivationPolicy: lazy
22 | Import-Package: org.eclipse.jdt.core.refactoring
23 | Export-Package: ca.concordia.jdeodorant.clone.parsers,
24 | gr.uom.java.ast,
25 | gr.uom.java.ast.decomposition,
26 | gr.uom.java.ast.decomposition.cfg,
27 | gr.uom.java.ast.decomposition.cfg.mapping,
28 | gr.uom.java.ast.decomposition.cfg.mapping.precondition,
29 | gr.uom.java.ast.decomposition.matching,
30 | gr.uom.java.distance,
31 | gr.uom.java.jdeodorant.refactoring.manipulators,
32 | gr.uom.java.jdeodorant.refactoring.views
33 |
--------------------------------------------------------------------------------
/build.properties:
--------------------------------------------------------------------------------
1 | source.. = src/
2 | output.. = bin/
3 | bin.includes = plugin.xml,\
4 | META-INF/,\
5 | .,\
6 | icons/
7 |
--------------------------------------------------------------------------------
/icons/0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/0.jpg
--------------------------------------------------------------------------------
/icons/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/1.jpg
--------------------------------------------------------------------------------
/icons/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/2.jpg
--------------------------------------------------------------------------------
/icons/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/3.jpg
--------------------------------------------------------------------------------
/icons/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/4.jpg
--------------------------------------------------------------------------------
/icons/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/5.jpg
--------------------------------------------------------------------------------
/icons/compass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/compass.png
--------------------------------------------------------------------------------
/icons/magnifier.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/magnifier.png
--------------------------------------------------------------------------------
/icons/repair.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsantalis/JDeodorant/78fd8695436831e0858100a6da785efcc0c46857/icons/repair.png
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/CloneDetectorOutputParseException.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | public class CloneDetectorOutputParseException extends Exception {
4 |
5 | private static final long serialVersionUID = 1L;
6 |
7 | public CloneDetectorOutputParseException() {
8 | super();
9 | }
10 |
11 | public CloneDetectorOutputParseException(String message) {
12 | super(message);
13 | }
14 |
15 | public CloneDetectorOutputParseException(Throwable throwable) {
16 | super(throwable);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/CloneDetectorOutputParserFactory.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | import org.eclipse.jdt.core.IJavaProject;
4 |
5 | public class CloneDetectorOutputParserFactory {
6 |
7 | public static CloneDetectorOutputParser getCloneToolParser(CloneDetectorType tool, IJavaProject jProject, String mainFile, String... otherArgs) throws InvalidInputFileException {
8 | switch (tool) {
9 | case CCFINDER:
10 | return new CCFinderOutputParser(jProject, mainFile, otherArgs[0]);
11 | case CONQAT:
12 | return new ConQATOutputParser(jProject, mainFile);
13 | case DECKARD:
14 | return new DeckardOutputParser(jProject, mainFile);
15 | case NICAD:
16 | return new NiCadOutputParser(jProject, mainFile);
17 | case CLONEDR:
18 | return new CloneDROutputParser(jProject, mainFile);
19 | default:
20 | throw new IllegalArgumentException("Not yet implemented.");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/CloneDetectorOutputParserProgressObserver.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | public interface CloneDetectorOutputParserProgressObserver {
4 | public void notify(int cloneGroupIndex);
5 | }
6 |
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/CloneDetectorType.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | public enum CloneDetectorType {
4 |
5 | CCFINDER("CCFinder"),
6 | CONQAT("ConQAT"),
7 | DECKARD("Deckard"),
8 | NICAD("NiCad"),
9 | CLONEDR("CloneDR");
10 |
11 | private final String detectorName;
12 |
13 | private CloneDetectorType(String detectorName) {
14 | this.detectorName = detectorName;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return this.detectorName;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/CloneGroupList.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | import java.util.Iterator;
4 | import java.util.LinkedHashMap;
5 | import java.util.Map;
6 |
7 | import org.eclipse.jdt.core.IJavaProject;
8 |
9 | public class CloneGroupList implements Iterable {
10 | private IJavaProject javaProject;
11 | private final Map cloneGroupMap = new LinkedHashMap();
12 |
13 | public CloneGroupList(IJavaProject javaProject) {
14 | this.javaProject = javaProject;
15 | }
16 |
17 | public IJavaProject getJavaProject() {
18 | return javaProject;
19 | }
20 |
21 | public void add(CloneGroup cloneGroup) {
22 | if (!cloneGroupMap.containsKey(cloneGroup.hashCode())) {
23 | for (CloneGroup otherCloneGroup : cloneGroupMap.values()) {
24 | if (cloneGroup.isSubCloneOf(otherCloneGroup)) {
25 | cloneGroup.setSubCloneOf(otherCloneGroup);
26 | break;
27 | } else if (otherCloneGroup.isSubCloneOf(cloneGroup)) {
28 | otherCloneGroup.setSubCloneOf(cloneGroup);
29 | break;
30 | }
31 | }
32 | cloneGroupMap.put(cloneGroup.hashCode(), cloneGroup);
33 | }
34 | }
35 |
36 | public Iterator iterator() {
37 | return cloneGroupMap.values().iterator();
38 | }
39 |
40 | public CloneGroup[] getCloneGroups() {
41 | return cloneGroupMap.values().toArray(new CloneGroup[cloneGroupMap.size()]);
42 | }
43 |
44 | public int getCloneGroupsCount() {
45 | return cloneGroupMap.size();
46 | }
47 |
48 | public boolean containsCloneGroup(CloneGroup cloneGroup) {
49 | return cloneGroupMap.containsKey(cloneGroup.hashCode());
50 | }
51 |
52 | public boolean removeClonesExistingInFile(String filePath) {
53 | boolean changed = false;
54 | for (CloneGroup cloneGroup : cloneGroupMap.values()) {
55 | changed |= cloneGroup.removeClonesExistingInFile(filePath);
56 | }
57 | return changed;
58 | }
59 |
60 | public boolean updateClonesExistingInFile(String filePath, String newSourceCode) {
61 | boolean changed = false;
62 | for (CloneGroup cloneGroup : cloneGroupMap.values()) {
63 | changed |= cloneGroup.updateClonesExistingInFile(filePath, newSourceCode);
64 | }
65 | return changed;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/CloneInstanceStatus.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | public enum CloneInstanceStatus {
4 | ORIGINAL_LOCATION,
5 | OFFSETS_SHIFTED,
6 | TAMPERED
7 | }
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/ClonesRelativeLocation.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | public enum ClonesRelativeLocation {
4 |
5 | WITHIN_THE_SAME_METHOD("within the same method"),
6 | WITHIN_THE_SAME_FILE("within the same file"),
7 | DIFFERENT_FILES("in different files");
8 |
9 | private final String location;
10 |
11 | private ClonesRelativeLocation(String location) {
12 | this.location = location;
13 | }
14 |
15 | @Override
16 | public String toString() {
17 | return "Clones are " + this.location;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/ca/concordia/jdeodorant/clone/parsers/InvalidInputFileException.java:
--------------------------------------------------------------------------------
1 | package ca.concordia.jdeodorant.clone.parsers;
2 |
3 | public class InvalidInputFileException extends Exception {
4 |
5 | private static final long serialVersionUID = 1L;
6 |
7 | public InvalidInputFileException() {
8 | super();
9 | }
10 |
11 | public InvalidInputFileException(String message) {
12 | super(message);
13 | }
14 |
15 | public InvalidInputFileException(Throwable throwable) {
16 | super(throwable);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/ASTInformation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import org.eclipse.jdt.core.ITypeRoot;
4 | import org.eclipse.jdt.core.dom.ASTNode;
5 | import org.eclipse.jdt.core.dom.CompilationUnit;
6 | import org.eclipse.jdt.core.dom.NodeFinder;
7 |
8 | public class ASTInformation {
9 |
10 | private ITypeRoot iTypeRoot;
11 | private int startPosition;
12 | private int length;
13 | private int nodeType;
14 | private volatile int hashCode = 0;
15 |
16 | public ASTInformation(ITypeRoot iTypeRoot, ASTNode astNode) {
17 | this.iTypeRoot = iTypeRoot;
18 | this.startPosition = astNode.getStartPosition();
19 | this.length = astNode.getLength();
20 | this.nodeType = astNode.getNodeType();
21 | }
22 |
23 | public ASTNode recoverASTNode() {
24 | CompilationUnit compilationUnit = CompilationUnitCache.getInstance().getCompilationUnit(iTypeRoot);
25 | ASTNode astNode = NodeFinder.perform(compilationUnit, startPosition, length);
26 | return astNode;
27 | }
28 |
29 | public ITypeRoot getITypeRoot() {
30 | return iTypeRoot;
31 | }
32 |
33 | public int getStartPosition() {
34 | return startPosition;
35 | }
36 |
37 | public int getLength() {
38 | return length;
39 | }
40 |
41 | public boolean equals(Object o) {
42 | if(this == o) {
43 | return true;
44 | }
45 |
46 | if(o instanceof ASTInformation) {
47 | ASTInformation astInformation = (ASTInformation)o;
48 | return this.iTypeRoot.equals(astInformation.iTypeRoot) &&
49 | this.startPosition == astInformation.startPosition &&
50 | this.length == astInformation.length &&
51 | this.nodeType == astInformation.nodeType;
52 | }
53 | return false;
54 | }
55 |
56 | public int hashCode() {
57 | if(hashCode == 0) {
58 | int result = 17;
59 | result = 37*result + iTypeRoot.hashCode();
60 | result = 37*result + startPosition;
61 | result = 37*result + length;
62 | result = 37*result + nodeType;
63 | hashCode = result;
64 | }
65 | return hashCode;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/ASTInformationGenerator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import org.eclipse.jdt.core.ITypeRoot;
4 | import org.eclipse.jdt.core.dom.ASTNode;
5 |
6 | public class ASTInformationGenerator {
7 |
8 | private static ITypeRoot iTypeRoot;
9 |
10 | public static void setCurrentITypeRoot(ITypeRoot typeRoot) {
11 | iTypeRoot = typeRoot;
12 | }
13 |
14 | public static ASTInformation generateASTInformation(ASTNode astNode) {
15 | return new ASTInformation(iTypeRoot, astNode);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/Access.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | public enum Access {
4 | NONE, PUBLIC, PRIVATE, PROTECTED;
5 |
6 | public String toString() {
7 | switch(this) {
8 | case NONE: return "";
9 | case PUBLIC: return "public";
10 | case PRIVATE: return "private";
11 | case PROTECTED: return "protected";
12 | default: return "";
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/AnonymousClassDeclarationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Set;
6 |
7 | import org.eclipse.core.resources.IFile;
8 | import org.eclipse.jdt.core.ITypeRoot;
9 | import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
10 |
11 | public class AnonymousClassDeclarationObject extends ClassDeclarationObject {
12 | private ASTInformation anonymousClassDeclaration;
13 | private ClassObject classObject;
14 |
15 | public void setAnonymousClassDeclaration(AnonymousClassDeclaration anonymous) {
16 | this.anonymousClassDeclaration = ASTInformationGenerator.generateASTInformation(anonymous);
17 | }
18 |
19 | public AnonymousClassDeclaration getAnonymousClassDeclaration() {
20 | return (AnonymousClassDeclaration)anonymousClassDeclaration.recoverASTNode();
21 | }
22 |
23 | public ClassObject getClassObject() {
24 | return classObject;
25 | }
26 |
27 | public void setClassObject(ClassObject classObject) {
28 | this.classObject = classObject;
29 | }
30 |
31 | public ITypeRoot getITypeRoot() {
32 | return anonymousClassDeclaration.getITypeRoot();
33 | }
34 |
35 | public IFile getIFile() {
36 | if(classObject != null) {
37 | return classObject.getIFile();
38 | }
39 | return null;
40 | }
41 |
42 | public TypeObject getSuperclass() {
43 | return null;
44 | }
45 |
46 | protected void accessedFieldFromThisClass(Set fields, FieldInstructionObject fieldInstruction) {
47 | List allFields = new ArrayList(fieldList);
48 | if(classObject != null) {
49 | //add the fields of the class in which the anonymous class is declared
50 | allFields.addAll(classObject.fieldList);
51 | }
52 | for(FieldObject field : allFields) {
53 | if(field.equals(fieldInstruction)) {
54 | if(!fields.contains(field))
55 | fields.add(field);
56 | break;
57 | }
58 | }
59 | }
60 |
61 | public String toString() {
62 | StringBuilder sb = new StringBuilder();
63 | sb.append(name);
64 | sb.append("\n\n").append("Fields:");
65 | for(FieldObject field : fieldList)
66 | sb.append("\n").append(field.toString());
67 |
68 | sb.append("\n\n").append("Methods:");
69 | for(MethodObject method : methodList)
70 | sb.append("\n").append(method.toString());
71 |
72 | return sb.toString();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/ArrayAccessObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import org.eclipse.jdt.core.dom.ArrayAccess;
4 |
5 | public class ArrayAccessObject {
6 | private TypeObject type;
7 | private ASTInformation arrayAccess;
8 |
9 | public ArrayAccessObject(TypeObject type) {
10 | this.type = type;
11 | }
12 |
13 | public TypeObject getType() {
14 | return type;
15 | }
16 |
17 | public ArrayAccess getArrayAccess() {
18 | return (ArrayAccess)this.arrayAccess.recoverASTNode();
19 | }
20 |
21 | public void setArrayAccess(ArrayAccess arrayAccess) {
22 | this.arrayAccess = ASTInformationGenerator.generateASTInformation(arrayAccess);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/ArrayCreationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import org.eclipse.jdt.core.dom.ArrayCreation;
4 |
5 | public class ArrayCreationObject extends CreationObject {
6 |
7 | public ArrayCreationObject(TypeObject type) {
8 | super(type);
9 | }
10 |
11 | public ArrayCreation getArrayCreation() {
12 | return (ArrayCreation)this.creation.recoverASTNode();
13 | }
14 |
15 | public void setArrayCreation(ArrayCreation creation) {
16 | this.creation = ASTInformationGenerator.generateASTInformation(creation);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/ClassInstanceCreationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashSet;
5 | import java.util.List;
6 | import java.util.ListIterator;
7 | import java.util.Set;
8 |
9 | import org.eclipse.jdt.core.dom.ClassInstanceCreation;
10 |
11 | public class ClassInstanceCreationObject extends CreationObject {
12 |
13 | private List parameterList;
14 | private Set thrownExceptions;
15 |
16 | public ClassInstanceCreationObject(TypeObject type) {
17 | super(type);
18 | this.parameterList = new ArrayList();
19 | this.thrownExceptions = new LinkedHashSet();
20 | }
21 |
22 | public ClassInstanceCreation getClassInstanceCreation() {
23 | return (ClassInstanceCreation)this.creation.recoverASTNode();
24 | }
25 |
26 | public void setClassInstanceCreation(ClassInstanceCreation creation) {
27 | this.creation = ASTInformationGenerator.generateASTInformation(creation);
28 | }
29 |
30 | public boolean addParameter(TypeObject parameterType) {
31 | return parameterList.add(parameterType);
32 | }
33 |
34 | public ListIterator getParameterListIterator() {
35 | return parameterList.listIterator();
36 | }
37 |
38 | public List getParameterTypeList() {
39 | return this.parameterList;
40 | }
41 |
42 | public List getParameterList() {
43 | List list = new ArrayList();
44 | for(TypeObject typeObject : parameterList)
45 | list.add(typeObject.toString());
46 | return list;
47 | }
48 |
49 | public void addThrownException(String type) {
50 | thrownExceptions.add(type);
51 | }
52 |
53 | public Set getThrownExceptions() {
54 | return this.thrownExceptions;
55 | }
56 |
57 | public String toString() {
58 | StringBuilder sb = new StringBuilder();
59 | sb.append("new ");
60 | sb.append(getType().toString());
61 | sb.append("(");
62 | if(!parameterList.isEmpty()) {
63 | for(int i=0; i markers;
11 |
12 | public CompilationErrorDetectedException(List markers) {
13 | this.markers = markers;
14 | }
15 |
16 | public List getMarkers() {
17 | return markers;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/ConstructorInvocationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import java.util.List;
4 |
5 | import org.eclipse.jdt.core.dom.ConstructorInvocation;
6 |
7 | public class ConstructorInvocationObject extends AbstractMethodInvocationObject {
8 |
9 | public ConstructorInvocationObject(TypeObject originClassType, String methodName, TypeObject returnType) {
10 | super(originClassType, methodName, returnType);
11 | }
12 |
13 | public ConstructorInvocationObject(TypeObject originClassType, String methodName, TypeObject returnType, List parameterList) {
14 | super(originClassType, methodName, returnType, parameterList);
15 | }
16 |
17 | public void setConstructorInvocation(ConstructorInvocation constructorInvocation) {
18 | this.methodInvocation = ASTInformationGenerator.generateASTInformation(constructorInvocation);
19 | }
20 |
21 | public ConstructorInvocation getConstructorInvocation() {
22 | //return this.superMethodInvocation;
23 | return (ConstructorInvocation)this.methodInvocation.recoverASTNode();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/CreationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | public abstract class CreationObject {
4 | private TypeObject type;
5 | protected ASTInformation creation;
6 |
7 | public CreationObject(TypeObject type) {
8 | this.type = type;
9 | }
10 |
11 | public TypeObject getType() {
12 | return type;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/LibraryClassStorage.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import gr.uom.java.jdeodorant.preferences.PreferenceConstants;
4 | import gr.uom.java.jdeodorant.refactoring.Activator;
5 |
6 | import java.util.LinkedHashSet;
7 | import java.util.LinkedList;
8 | import java.util.Set;
9 |
10 | import org.eclipse.jdt.core.IClassFile;
11 | import org.eclipse.jdt.core.dom.ASTParser;
12 | import org.eclipse.jdt.core.dom.CompilationUnit;
13 | import org.eclipse.jface.preference.IPreferenceStore;
14 |
15 | public class LibraryClassStorage extends Indexer {
16 | private static LibraryClassStorage instance;
17 | private LinkedList iClassFileList;
18 | private LinkedList compilationUnitList;
19 | private Set unMatchedClassFiles;
20 |
21 | private LibraryClassStorage() {
22 | super();
23 | this.iClassFileList = new LinkedList();
24 | this.compilationUnitList = new LinkedList();
25 | this.unMatchedClassFiles = new LinkedHashSet();
26 | }
27 |
28 | public static LibraryClassStorage getInstance() {
29 | if(instance == null) {
30 | instance = new LibraryClassStorage();
31 | }
32 | return instance;
33 | }
34 |
35 | public CompilationUnit getCompilationUnit(IClassFile classFile) {
36 | if(iClassFileList.contains(classFile)) {
37 | int position = iClassFileList.indexOf(classFile);
38 | return compilationUnitList.get(position);
39 | }
40 | else {
41 | CompilationUnit compilationUnit = null;
42 | try {
43 | if(!unMatchedClassFiles.contains(classFile)) {
44 | ASTParser parser = ASTParser.newParser(ASTReader.JLS);
45 | parser.setSource(classFile);
46 | parser.setResolveBindings(true);
47 | compilationUnit = (CompilationUnit)parser.createAST(null);
48 |
49 | IPreferenceStore store = Activator.getDefault().getPreferenceStore();
50 | int maximumCacheSize = store.getInt(PreferenceConstants.P_LIBRARY_COMPILATION_UNIT_CACHE_SIZE);
51 | if(iClassFileList.size() < maximumCacheSize) {
52 | iClassFileList.add(classFile);
53 | compilationUnitList.add(compilationUnit);
54 | }
55 | else {
56 | iClassFileList.removeFirst();
57 | compilationUnitList.removeFirst();
58 | iClassFileList.add(classFile);
59 | compilationUnitList.add(compilationUnit);
60 | }
61 | }
62 | }
63 | catch(IllegalStateException e) {
64 | unMatchedClassFiles.add(classFile);
65 | }
66 | return compilationUnit;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/LiteralType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | public enum LiteralType {
4 | BOOLEAN, CHARACTER, NULL, NUMBER, STRING, TYPE;
5 | }
6 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/MethodInvocationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import java.util.List;
4 |
5 | import org.eclipse.jdt.core.dom.MethodInvocation;
6 |
7 | public class MethodInvocationObject extends AbstractMethodInvocationObject {
8 |
9 | public MethodInvocationObject(TypeObject originClassType, String methodName, TypeObject returnType) {
10 | super(originClassType, methodName, returnType);
11 | }
12 |
13 | public MethodInvocationObject(TypeObject originClassType, String methodName, TypeObject returnType, List parameterList) {
14 | super(originClassType, methodName, returnType, parameterList);
15 | }
16 |
17 | public void setMethodInvocation(MethodInvocation methodInvocation) {
18 | //this.methodInvocation = methodInvocation;
19 | this.methodInvocation = ASTInformationGenerator.generateASTInformation(methodInvocation);
20 | }
21 |
22 | public MethodInvocation getMethodInvocation() {
23 | //return this.methodInvocation;
24 | return (MethodInvocation)this.methodInvocation.recoverASTNode();
25 | }
26 | }
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/SuperFieldInstructionObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import org.eclipse.jdt.core.dom.SimpleName;
4 |
5 | public class SuperFieldInstructionObject {
6 |
7 | private String ownerClass;
8 | private TypeObject type;
9 | private String name;
10 | private boolean _static;
11 | //private SimpleName simpleName;
12 | private ASTInformation simpleName;
13 | private volatile int hashCode = 0;
14 |
15 | public SuperFieldInstructionObject(String ownerClass, TypeObject type, String name) {
16 | this.ownerClass = ownerClass;
17 | this.type = type;
18 | this.name = name;
19 | this._static = false;
20 | }
21 |
22 | public String getOwnerClass() {
23 | return ownerClass;
24 | }
25 |
26 | public TypeObject getType() {
27 | return type;
28 | }
29 |
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | public boolean isStatic() {
35 | return _static;
36 | }
37 |
38 | public void setStatic(boolean s) {
39 | _static = s;
40 | }
41 |
42 | public void setSimpleName(SimpleName simpleName) {
43 | //this.simpleName = simpleName;
44 | this.simpleName = ASTInformationGenerator.generateASTInformation(simpleName);
45 | }
46 |
47 | public SimpleName getSimpleName() {
48 | //return this.simpleName;
49 | return (SimpleName)this.simpleName.recoverASTNode();
50 | }
51 |
52 | public boolean equals(Object o) {
53 | if(this == o) {
54 | return true;
55 | }
56 |
57 | if (o instanceof SuperFieldInstructionObject) {
58 | SuperFieldInstructionObject sfio = (SuperFieldInstructionObject)o;
59 | return this.ownerClass.equals(sfio.ownerClass) && this.name.equals(sfio.name) && this.type.equals(sfio.type);
60 | }
61 | return false;
62 | }
63 |
64 | public int hashCode() {
65 | if(hashCode == 0) {
66 | int result = 17;
67 | result = 37*result + ownerClass.hashCode();
68 | result = 37*result + name.hashCode();
69 | result = 37*result + type.hashCode();
70 | hashCode = result;
71 | }
72 | return hashCode;
73 | }
74 |
75 | public String toString() {
76 | StringBuilder sb = new StringBuilder();
77 | sb.append(ownerClass).append("::");
78 | //sb.append(type).append(" ");
79 | sb.append(name);
80 | return sb.toString();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/SuperMethodInvocationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import java.util.List;
4 |
5 | import org.eclipse.jdt.core.dom.SuperMethodInvocation;
6 |
7 | public class SuperMethodInvocationObject extends AbstractMethodInvocationObject {
8 |
9 | public SuperMethodInvocationObject(TypeObject originClassType, String methodName, TypeObject returnType) {
10 | super(originClassType, methodName, returnType);
11 | }
12 |
13 | public SuperMethodInvocationObject(TypeObject originClassType, String methodName, TypeObject returnType, List parameterList) {
14 | super(originClassType, methodName, returnType, parameterList);
15 | }
16 |
17 | public void setSuperMethodInvocation(SuperMethodInvocation superMethodInvocation) {
18 | //this.superMethodInvocation = superMethodInvocation;
19 | this.methodInvocation = ASTInformationGenerator.generateASTInformation(superMethodInvocation);
20 | }
21 |
22 | public SuperMethodInvocation getSuperMethodInvocation() {
23 | //return this.superMethodInvocation;
24 | return (SuperMethodInvocation)this.methodInvocation.recoverASTNode();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/TypeSearchRequestor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import java.util.Set;
4 |
5 | import org.eclipse.core.runtime.CoreException;
6 | import org.eclipse.jdt.core.IType;
7 | import org.eclipse.jdt.core.search.SearchMatch;
8 | import org.eclipse.jdt.core.search.SearchRequestor;
9 |
10 | public class TypeSearchRequestor extends SearchRequestor {
11 |
12 | private Set subTypes;
13 |
14 | public TypeSearchRequestor(Set subTypes) {
15 | this.subTypes = subTypes;
16 | }
17 |
18 | public void acceptSearchMatch(SearchMatch match) throws CoreException {
19 | Object element = match.getElement();
20 | if (match.getElement() instanceof IType) {
21 | IType iType = (IType)element;
22 | if(!iType.isAnonymous()) {
23 | subTypes.add(iType);
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/VariableDeclarationObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast;
2 |
3 | import org.eclipse.jdt.core.dom.VariableDeclaration;
4 |
5 | public abstract class VariableDeclarationObject {
6 |
7 | protected String variableBindingKey;
8 |
9 | public String getVariableBindingKey() {
10 | return variableBindingKey;
11 | }
12 | public abstract VariableDeclaration getVariableDeclaration();
13 | public abstract String getName();
14 | }
15 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/association/Association.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.association;
2 |
3 | import gr.uom.java.ast.FieldObject;
4 |
5 | public class Association {
6 |
7 | private String from;
8 | private String to;
9 | private boolean container;
10 | private FieldObject fieldObject;
11 |
12 | public Association(FieldObject fieldObject, String from, String to) {
13 | this.fieldObject = fieldObject;
14 | this.from = from;
15 | this.to = to;
16 | this.container = false;
17 | }
18 |
19 | public FieldObject getFieldObject() {
20 | return fieldObject;
21 | }
22 |
23 | public String getTo() {
24 | return to;
25 | }
26 |
27 | public String getFrom() {
28 | return from;
29 | }
30 |
31 | public boolean isContainer() {
32 | return container;
33 | }
34 |
35 | public void setContainer(boolean container) {
36 | this.container = container;
37 | }
38 |
39 | public boolean equals(Object o) {
40 | if(this == o) {
41 | return true;
42 | }
43 |
44 | if (o instanceof Association) {
45 | Association association = (Association)o;
46 | return this.from.equals(association.from) && this.to.equals(association.to) &&
47 | this.fieldObject.equals(association.fieldObject) && this.container == association.container;
48 | }
49 | return false;
50 | }
51 |
52 | public String toString() {
53 | StringBuilder sb = new StringBuilder();
54 | sb.append(from).append(" -->");
55 | if(container)
56 | sb.append("(*) ");
57 | else
58 | sb.append("(1) ");
59 | sb.append(to);
60 | return sb.toString();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/AbstractStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition;
2 |
3 | import java.util.List;
4 |
5 | import gr.uom.java.ast.ASTInformation;
6 | import gr.uom.java.ast.ASTInformationGenerator;
7 |
8 | import org.eclipse.jdt.core.dom.Statement;
9 |
10 | public abstract class AbstractStatement extends AbstractMethodFragment {
11 |
12 | private ASTInformation statement;
13 | private StatementType type;
14 |
15 | public AbstractStatement(Statement statement, StatementType type, AbstractMethodFragment parent) {
16 | super(parent);
17 | this.type = type;
18 | this.statement = ASTInformationGenerator.generateASTInformation(statement);
19 | }
20 |
21 | public Statement getStatement() {
22 | return (Statement)this.statement.recoverASTNode();
23 | }
24 |
25 | public StatementType getType() {
26 | return type;
27 | }
28 |
29 | public int getNestingDepth() {
30 | AbstractStatement parent = (AbstractStatement) this.getParent();
31 | int depth = 0;
32 | while (parent != null) {
33 | if (!parent.getType().equals(StatementType.BLOCK)) {
34 | depth++;
35 | }
36 | parent = (AbstractStatement) parent.getParent();
37 | }
38 | return depth;
39 | }
40 |
41 | public abstract List stringRepresentation();
42 | }
43 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/ExpressionType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition;
2 |
3 | public enum ExpressionType {
4 | NORMAL_ANNOTATION,
5 | MARKER_ANNOTATION,
6 | SINGLE_MEMBER_ANNOTATION,
7 | ARRAY_ACCESS,
8 | ARRAY_CREATION,
9 | ARRAY_INITIALIZER,
10 | ASSIGNMENT,
11 | BOOLEAN_LITERAL,
12 | CAST,
13 | CHARACTER_LITERAL,
14 | CLASS_INSTANCE_CREATION,
15 | CONDITIONAL,
16 | FIELD_ACCESS,
17 | INFIX,
18 | INSTANCE_OF,
19 | METHOD_INVOCATION,
20 | SIMPLE_NAME,
21 | QUALIFIED_NAME,
22 | NULL_LITERAL,
23 | NUMBER_LITERAL,
24 | PARENTHESIZED,
25 | POSTFIX,
26 | PREFIX,
27 | STRING_LITERAL,
28 | SUPER_FIELD_ACCESS,
29 | SUPER_METHOD_INVOCATION,
30 | THIS,
31 | TYPE_LITERAL,
32 | VARIABLE_DECLARATION;
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/StatementType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition;
2 |
3 | public enum StatementType {
4 | ASSERT,
5 | BLOCK {
6 | public String toString() {
7 | return "{";
8 | }
9 | },
10 | BREAK,
11 | CONSTRUCTOR_INVOCATION,
12 | CONTINUE,
13 | DO,
14 | EMPTY,
15 | ENHANCED_FOR {
16 | public String toString() {
17 | return "for";
18 | }
19 | },
20 | EXPRESSION,
21 | FOR,
22 | IF,
23 | LABELED,
24 | RETURN,
25 | SUPER_CONSTRUCTOR_INVOCATION,
26 | SWITCH_CASE,
27 | SWITCH,
28 | SYNCHRONIZED,
29 | THROW,
30 | TRY,
31 | TYPE_DECLARATION,
32 | VARIABLE_DECLARATION,
33 | WHILE;
34 |
35 | public String toString() {
36 | return name().toLowerCase();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/SynchronizedStatementObject.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 | import org.eclipse.jdt.core.dom.SynchronizedStatement;
5 |
6 | public class SynchronizedStatementObject extends CompositeStatementObject {
7 |
8 | public SynchronizedStatementObject(Statement statement, AbstractMethodFragment parent) {
9 | super(statement, StatementType.SYNCHRONIZED, parent);
10 | AbstractExpression abstractExpression = new AbstractExpression(
11 | ((SynchronizedStatement)statement).getExpression(), this);
12 | this.addExpression(abstractExpression);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/BasicBlock.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class BasicBlock {
7 | private static int blockNum = 0;
8 | private int id;
9 | private CFGNode leader;
10 | private List nodes;
11 | private List tryNodes;
12 | private BasicBlock previousBasicBlock;
13 | private BasicBlock nextBasicBlock;
14 |
15 | public BasicBlock(CFGNode node) {
16 | blockNum++;
17 | this.id = blockNum;
18 | this.leader = node;
19 | node.setBasicBlock(this);
20 | this.nodes = new ArrayList();
21 | this.tryNodes = new ArrayList();
22 | }
23 |
24 | public int getId() {
25 | return id;
26 | }
27 |
28 | public CFGNode getLeader() {
29 | return leader;
30 | }
31 |
32 | public List getNodes() {
33 | return nodes;
34 | }
35 |
36 | public List getAllNodes() {
37 | List allNodes = new ArrayList();
38 | allNodes.add(leader);
39 | allNodes.addAll(nodes);
40 | return allNodes;
41 | }
42 |
43 | public List getAllNodesIncludingTry() {
44 | List allNodes = new ArrayList();
45 | allNodes.add(leader);
46 | allNodes.addAll(nodes);
47 | allNodes.addAll(tryNodes);
48 | return allNodes;
49 | }
50 |
51 | public CFGNode getLastNode() {
52 | if(!nodes.isEmpty())
53 | return nodes.get(nodes.size()-1);
54 | else
55 | return leader;
56 | }
57 |
58 | public void add(CFGNode node) {
59 | nodes.add(node);
60 | node.setBasicBlock(this);
61 | }
62 |
63 | public void addTryNode(CFGTryNode tryNode) {
64 | tryNodes.add(tryNode);
65 | tryNode.setBasicBlock(this);
66 | }
67 |
68 | public BasicBlock getPreviousBasicBlock() {
69 | return previousBasicBlock;
70 | }
71 |
72 | public void setPreviousBasicBlock(BasicBlock previousBasicBlock) {
73 | this.previousBasicBlock = previousBasicBlock;
74 | }
75 |
76 | public BasicBlock getNextBasicBlock() {
77 | return nextBasicBlock;
78 | }
79 |
80 | public void setNextBasicBlock(BasicBlock nextBasicBlock) {
81 | this.nextBasicBlock = nextBasicBlock;
82 | }
83 |
84 | public static void resetBlockNum() {
85 | blockNum = 0;
86 | }
87 |
88 | public String toString() {
89 | return leader.toString() + nodes.toString();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGBlockNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import gr.uom.java.ast.decomposition.AbstractStatement;
4 |
5 | public class CFGBlockNode extends CFGNode {
6 |
7 | private CFGNode controlParent;
8 |
9 | public CFGBlockNode(AbstractStatement statement) {
10 | super(statement);
11 | }
12 |
13 | public CFGNode getControlParent() {
14 | return controlParent;
15 | }
16 |
17 | public void setControlParent(CFGNode controlParent) {
18 | this.controlParent = controlParent;
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGBranchConditionalNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import gr.uom.java.ast.decomposition.AbstractStatement;
7 |
8 | public abstract class CFGBranchConditionalNode extends CFGBranchNode {
9 | private CFGNode joinNode;
10 |
11 | public CFGBranchConditionalNode(AbstractStatement statement) {
12 | super(statement);
13 | }
14 |
15 | public void setJoinNode(CFGNode joinNode) {
16 | this.joinNode = joinNode;
17 | }
18 |
19 | public CFGNode getJoinNode() {
20 | return joinNode;
21 | }
22 |
23 | public List getNestedBasicBlocks() {
24 | List blocksBetween = new ArrayList();
25 | BasicBlock srcBlock = getBasicBlock();
26 | if(joinNode != null) {
27 | CFGNode dstNode = joinNode;
28 | if(dstNode.getBasicBlock().getId() < srcBlock.getId() && joinNode instanceof CFGBranchLoopNode) {
29 | CFGBranchLoopNode loopNode = (CFGBranchLoopNode)joinNode;
30 | Flow falseControlFlow = loopNode.getFalseControlFlow();
31 | if(falseControlFlow != null)
32 | dstNode = (CFGNode)falseControlFlow.dst;
33 | else
34 | return getNestedBasicBlocksToEnd();
35 | }
36 | BasicBlock dstBlock = dstNode.getBasicBlock();
37 | if(srcBlock.getId() < dstBlock.getId()) {
38 | BasicBlock nextBlock = srcBlock;
39 | while(!nextBlock.getNextBasicBlock().equals(dstBlock)) {
40 | nextBlock = nextBlock.getNextBasicBlock();
41 | blocksBetween.add(nextBlock);
42 | }
43 | }
44 | else if(srcBlock.getId() >= dstBlock.getId()) {
45 | return getNestedBasicBlocksToEnd();
46 | }
47 | }
48 | else {
49 | return getNestedBasicBlocksToEnd();
50 | }
51 | return blocksBetween;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGBranchDoLoopNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import gr.uom.java.ast.decomposition.AbstractStatement;
7 |
8 | public class CFGBranchDoLoopNode extends CFGBranchNode {
9 |
10 | public CFGBranchDoLoopNode(AbstractStatement statement) {
11 | super(statement);
12 | }
13 |
14 | public CFGNode getJoinNode() {
15 | Flow flow = getTrueControlFlow();
16 | return (CFGNode)flow.dst;
17 | }
18 |
19 | public List getNestedBasicBlocks() {
20 | List blocksBetween = new ArrayList();
21 | BasicBlock srcBlock = getBasicBlock();
22 | BasicBlock joinBlock = getJoinNode().getBasicBlock();
23 | //join node is always before do-loop node
24 | blocksBetween.add(joinBlock);
25 | BasicBlock nextBlock = joinBlock;
26 | if(!joinBlock.equals(srcBlock)) {
27 | while(!nextBlock.getNextBasicBlock().equals(srcBlock)) {
28 | nextBlock = nextBlock.getNextBasicBlock();
29 | blocksBetween.add(nextBlock);
30 | }
31 | }
32 | return blocksBetween;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGBranchLoopNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import gr.uom.java.ast.decomposition.AbstractStatement;
7 |
8 | public class CFGBranchLoopNode extends CFGBranchNode {
9 |
10 | public CFGBranchLoopNode(AbstractStatement statement) {
11 | super(statement);
12 | }
13 |
14 | public CFGNode getJoinNode() {
15 | return this;
16 | }
17 |
18 | public List getNestedBasicBlocks() {
19 | List blocksBetween = new ArrayList();
20 | BasicBlock srcBlock = getBasicBlock();
21 | Flow falseControlFlow = getFalseControlFlow();
22 | if(falseControlFlow != null) {
23 | CFGNode dstNode = (CFGNode)falseControlFlow.dst;
24 | if(dstNode.getBasicBlock().getId() < srcBlock.getId() && dstNode instanceof CFGBranchLoopNode) {
25 | CFGBranchLoopNode loopNode = (CFGBranchLoopNode)dstNode;
26 | Flow falseControlFlow2 = loopNode.getFalseControlFlow();
27 | if(falseControlFlow2 != null)
28 | dstNode = (CFGNode)falseControlFlow2.dst;
29 | else
30 | return getNestedBasicBlocksToEnd();
31 | }
32 | BasicBlock dstBlock = dstNode.getBasicBlock();
33 | if(srcBlock.getId() < dstBlock.getId()) {
34 | BasicBlock nextBlock = srcBlock;
35 | while(!nextBlock.getNextBasicBlock().equals(dstBlock)) {
36 | nextBlock = nextBlock.getNextBasicBlock();
37 | blocksBetween.add(nextBlock);
38 | }
39 | }
40 | else if(srcBlock.getId() > dstBlock.getId()) {
41 | return getNestedBasicBlocksToEnd();
42 | }
43 | }
44 | else {
45 | return getNestedBasicBlocksToEnd();
46 | }
47 | return blocksBetween;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGBranchSwitchNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import gr.uom.java.ast.decomposition.AbstractStatement;
4 |
5 | public class CFGBranchSwitchNode extends CFGBranchConditionalNode {
6 |
7 | public CFGBranchSwitchNode(AbstractStatement statement) {
8 | super(statement);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGBreakNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import org.eclipse.jdt.core.dom.BreakStatement;
4 |
5 | import gr.uom.java.ast.decomposition.AbstractStatement;
6 |
7 | public class CFGBreakNode extends CFGNode {
8 | private String label;
9 | private CFGNode innerMostLoopNode;
10 |
11 | public CFGBreakNode(AbstractStatement statement) {
12 | super(statement);
13 | BreakStatement breakStatement = (BreakStatement)statement.getStatement();
14 | if(breakStatement.getLabel() != null)
15 | label = breakStatement.getLabel().getIdentifier();
16 | }
17 |
18 | public String getLabel() {
19 | return label;
20 | }
21 |
22 | public boolean isLabeled() {
23 | return label != null;
24 | }
25 |
26 | public CFGNode getInnerMostLoopNode() {
27 | return innerMostLoopNode;
28 | }
29 |
30 | public void setInnerMostLoopNode(CFGNode innerMostLoopNode) {
31 | this.innerMostLoopNode = innerMostLoopNode;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGContinueNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import org.eclipse.jdt.core.dom.ContinueStatement;
4 |
5 | import gr.uom.java.ast.decomposition.AbstractStatement;
6 |
7 | public class CFGContinueNode extends CFGNode {
8 | private String label;
9 | private CFGNode innerMostLoopNode;
10 |
11 | public CFGContinueNode(AbstractStatement statement) {
12 | super(statement);
13 | ContinueStatement continueStatement = (ContinueStatement)statement.getStatement();
14 | if(continueStatement.getLabel() != null)
15 | label = continueStatement.getLabel().getIdentifier();
16 | }
17 |
18 | public String getLabel() {
19 | return label;
20 | }
21 |
22 | public boolean isLabeled() {
23 | return label != null;
24 | }
25 |
26 | public CFGNode getInnerMostLoopNode() {
27 | return innerMostLoopNode;
28 | }
29 |
30 | public void setInnerMostLoopNode(CFGNode innerMostLoopNode) {
31 | this.innerMostLoopNode = innerMostLoopNode;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGExitNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import gr.uom.java.ast.decomposition.AbstractStatement;
7 |
8 | public class CFGExitNode extends CFGNode {
9 | private PlainVariable returnedVariable;
10 |
11 | public CFGExitNode(AbstractStatement statement) {
12 | super(statement);
13 | List usedVariables = new ArrayList(statement.getUsedLocalVariables());
14 | List usedFields = new ArrayList(statement.getUsedFieldsThroughThisReference());
15 | if(usedVariables.size() == 1 && usedFields.size() == 0) {
16 | returnedVariable = usedVariables.get(0);
17 | }
18 | if(usedVariables.size() == 0 && usedFields.size() == 1) {
19 | returnedVariable = usedFields.get(0);
20 | }
21 | }
22 |
23 | public PlainVariable getReturnedVariable() {
24 | return returnedVariable;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGSwitchCaseNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import org.eclipse.jdt.core.dom.SwitchCase;
4 |
5 | import gr.uom.java.ast.decomposition.AbstractStatement;
6 |
7 | public class CFGSwitchCaseNode extends CFGNode {
8 | private boolean isDefault;
9 |
10 | public CFGSwitchCaseNode(AbstractStatement statement) {
11 | super(statement);
12 | SwitchCase switchCase = (SwitchCase)statement.getStatement();
13 | if(switchCase.isDefault())
14 | isDefault = true;
15 | else
16 | isDefault = false;
17 | }
18 |
19 | public boolean isDefault() {
20 | return isDefault;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGSynchronizedNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import gr.uom.java.ast.decomposition.AbstractStatement;
4 |
5 | public class CFGSynchronizedNode extends CFGBlockNode {
6 | public CFGSynchronizedNode(AbstractStatement statement) {
7 | super(statement);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGThrowNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import gr.uom.java.ast.decomposition.AbstractStatement;
4 |
5 | public class CFGThrowNode extends CFGNode {
6 |
7 | public CFGThrowNode(AbstractStatement statement) {
8 | super(statement);
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/CFGTryNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import gr.uom.java.ast.decomposition.AbstractStatement;
7 | import gr.uom.java.ast.decomposition.CatchClauseObject;
8 | import gr.uom.java.ast.decomposition.TryStatementObject;
9 |
10 | public class CFGTryNode extends CFGBlockNode {
11 | private List handledExceptions;
12 | private boolean hasResources;
13 | public CFGTryNode(AbstractStatement statement) {
14 | super(statement);
15 | this.handledExceptions = new ArrayList();
16 | TryStatementObject tryStatement = (TryStatementObject)statement;
17 | this.hasResources = tryStatement.hasResources();
18 | for(CatchClauseObject catchClause : tryStatement.getCatchClauses()) {
19 | handledExceptions.addAll(catchClause.getExceptionTypes());
20 | }
21 | }
22 |
23 | public boolean hasResources() {
24 | return hasResources;
25 | }
26 |
27 | public List getHandledExceptions() {
28 | return handledExceptions;
29 | }
30 |
31 | public boolean hasFinallyClauseClosingVariable(AbstractVariable variable) {
32 | return ((TryStatementObject)getStatement()).hasFinallyClauseClosingVariable(variable);
33 | }
34 |
35 | public boolean hasCatchClause() {
36 | return ((TryStatementObject)getStatement()).hasCatchClause();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/Flow.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public class Flow extends GraphEdge {
4 | private boolean loopbackFlow = false;
5 | private boolean trueControlFlow = false;
6 | private boolean falseControlFlow = false;
7 |
8 | public Flow(CFGNode src, CFGNode dst) {
9 | super(src, dst);
10 | src.addOutgoingEdge(this);
11 | dst.addIncomingEdge(this);
12 | }
13 |
14 | public boolean isLoopbackFlow() {
15 | return loopbackFlow;
16 | }
17 |
18 | public void setLoopbackFlow(boolean loopbackFlow) {
19 | this.loopbackFlow = loopbackFlow;
20 | }
21 |
22 | public boolean isTrueControlFlow() {
23 | return trueControlFlow;
24 | }
25 |
26 | public void setTrueControlFlow(boolean trueControlFlow) {
27 | this.trueControlFlow = trueControlFlow;
28 | }
29 |
30 | public boolean isFalseControlFlow() {
31 | return falseControlFlow;
32 | }
33 |
34 | public void setFalseControlFlow(boolean falseControlFlow) {
35 | this.falseControlFlow = falseControlFlow;
36 | }
37 |
38 | public String toString() {
39 | StringBuilder type = new StringBuilder();
40 | if(trueControlFlow)
41 | type.append("T");
42 | if(falseControlFlow)
43 | type.append("F");
44 | if(loopbackFlow)
45 | type.append("LB");
46 | return src.toString() + "-->" + type.toString() + "\n" + dst.toString();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/Graph.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.LinkedHashSet;
4 | import java.util.Set;
5 |
6 | public class Graph {
7 | protected Set nodes;
8 | protected Set edges;
9 |
10 | public Graph() {
11 | this.nodes = new LinkedHashSet();
12 | this.edges = new LinkedHashSet();
13 | }
14 |
15 | public Set getNodes() {
16 | return nodes;
17 | }
18 |
19 | public Set getEdges() {
20 | return edges;
21 | }
22 |
23 | public void addNode(GraphNode node) {
24 | nodes.add(node);
25 | }
26 |
27 | public void addEdge(GraphEdge edge) {
28 | edges.add(edge);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/GraphEdge.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public class GraphEdge {
4 | protected GraphNode src;
5 | protected GraphNode dst;
6 |
7 | public GraphEdge(GraphNode src, GraphNode dst) {
8 | this.src = src;
9 | this.dst = dst;
10 | }
11 |
12 | public GraphNode getSrc() {
13 | return src;
14 | }
15 |
16 | public GraphNode getDst() {
17 | return dst;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/GraphNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.LinkedHashSet;
4 | import java.util.Set;
5 |
6 | public class GraphNode {
7 | private static int nodeNum = 0;
8 | protected int id;
9 | protected Set incomingEdges;
10 | protected Set outgoingEdges;
11 |
12 | public GraphNode() {
13 | nodeNum++;
14 | this.id = nodeNum;
15 | this.incomingEdges = new LinkedHashSet();
16 | this.outgoingEdges = new LinkedHashSet();
17 | }
18 |
19 | public int getId() {
20 | return id;
21 | }
22 |
23 | public void addIncomingEdge(GraphEdge edge) {
24 | incomingEdges.add(edge);
25 | }
26 |
27 | public void addOutgoingEdge(GraphEdge edge) {
28 | outgoingEdges.add(edge);
29 | }
30 |
31 | public static void resetNodeNum() {
32 | nodeNum = 0;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGAbstractDataDependence.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public abstract class PDGAbstractDataDependence extends PDGDependence {
4 | private AbstractVariable data;
5 | private CFGBranchNode loop;
6 | private volatile int hashCode = 0;
7 |
8 | public PDGAbstractDataDependence(PDGNode src, PDGNode dst, PDGDependenceType type,
9 | AbstractVariable data, CFGBranchNode loop) {
10 | super(src, dst, type);
11 | this.data = data;
12 | this.loop = loop;
13 | src.addOutgoingEdge(this);
14 | dst.addIncomingEdge(this);
15 | }
16 |
17 | public AbstractVariable getData() {
18 | return data;
19 | }
20 |
21 | public CFGBranchNode getLoop() {
22 | return loop;
23 | }
24 |
25 | public boolean isLoopCarried() {
26 | if(loop != null)
27 | return true;
28 | else
29 | return false;
30 | }
31 |
32 | public boolean equals(Object o) {
33 | if(this == o)
34 | return true;
35 |
36 | if(o instanceof PDGAbstractDataDependence) {
37 | PDGAbstractDataDependence dataDependence = (PDGAbstractDataDependence)o;
38 | boolean equalLoop = false;
39 | if(this.loop != null && dataDependence.loop != null)
40 | equalLoop = this.loop.equals(dataDependence.loop);
41 | if(this.loop == null && dataDependence.loop == null)
42 | equalLoop = true;
43 | return this.src.equals(dataDependence.src) && this.dst.equals(dataDependence.dst) &&
44 | this.data.equals(dataDependence.data) && equalLoop &&
45 | this.getType().equals(dataDependence.getType());
46 | }
47 | return false;
48 | }
49 |
50 | public int hashCode() {
51 | if(hashCode == 0) {
52 | int result = 17;
53 | result = 37*result + src.hashCode();
54 | result = 37*result + dst.hashCode();
55 | result = 37*result + data.hashCode();
56 | if(loop != null)
57 | result = 37*result + loop.hashCode();
58 | result = 37*result + getType().hashCode();
59 | hashCode = result;
60 | }
61 | return hashCode;
62 | }
63 |
64 | public String toString() {
65 | String loopInfo = isLoopCarried() ? " through loop " + loop.getId() : "";
66 | return src.toString() + "-->" + data.toString() +
67 | " <" + getType().toString().toLowerCase() + ">" +
68 | loopInfo +
69 | "\n" + dst.toString();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGAntiDependence.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public class PDGAntiDependence extends PDGAbstractDataDependence {
4 |
5 | public PDGAntiDependence(PDGNode src, PDGNode dst,
6 | AbstractVariable data, CFGBranchNode loop) {
7 | super(src, dst, PDGDependenceType.ANTI, data, loop);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGControlDependence.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public class PDGControlDependence extends PDGDependence {
4 | private boolean trueControlDependence;
5 | private volatile int hashCode = 0;
6 |
7 | public PDGControlDependence(PDGNode src, PDGNode dst, boolean trueControlDependence) {
8 | super(src, dst, PDGDependenceType.CONTROL);
9 | this.trueControlDependence = trueControlDependence;
10 | src.addOutgoingEdge(this);
11 | dst.addIncomingEdge(this);
12 | }
13 |
14 | public boolean isTrueControlDependence() {
15 | if(trueControlDependence == true)
16 | return true;
17 | else
18 | return false;
19 | }
20 |
21 | public boolean isFalseControlDependence() {
22 | if(trueControlDependence == true)
23 | return false;
24 | else
25 | return true;
26 | }
27 |
28 | public boolean sameLabel(PDGControlDependence other) {
29 | return this.trueControlDependence == other.trueControlDependence;
30 | }
31 |
32 | public boolean equals(Object o) {
33 | if(this == o)
34 | return true;
35 |
36 | if(o instanceof PDGControlDependence) {
37 | PDGControlDependence controlDependence = (PDGControlDependence)o;
38 | return this.src.equals(controlDependence.src) && this.dst.equals(controlDependence.dst) &&
39 | this.trueControlDependence == controlDependence.trueControlDependence;
40 | }
41 | return false;
42 | }
43 |
44 | public int hashCode() {
45 | if(hashCode == 0) {
46 | int result = 17;
47 | result = 37*result + src.hashCode();
48 | result = 37*result + dst.hashCode();
49 | result = 37*result + Boolean.valueOf(trueControlDependence).hashCode();
50 | hashCode = result;
51 | }
52 | return hashCode;
53 | }
54 |
55 | public String toString() {
56 | StringBuilder type = new StringBuilder();
57 | if(trueControlDependence == true)
58 | type.append("T");
59 | else
60 | type.append("F");
61 | return src.toString() + "-->" + type.toString() + "\n" + dst.toString();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGDataDependence.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public class PDGDataDependence extends PDGAbstractDataDependence {
4 |
5 | public PDGDataDependence(PDGNode src, PDGNode dst,
6 | AbstractVariable data, CFGBranchNode loop) {
7 | super(src, dst, PDGDependenceType.DATA, data, loop);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGDependence.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public abstract class PDGDependence extends GraphEdge {
4 | private PDGDependenceType type;
5 |
6 | public PDGDependence(PDGNode src, PDGNode dst, PDGDependenceType type) {
7 | super(src, dst);
8 | this.type = type;
9 | }
10 |
11 | public GraphNode getSrc() {
12 | return src;
13 | }
14 |
15 | public GraphNode getDst() {
16 | return dst;
17 | }
18 |
19 | public PDGDependenceType getType() {
20 | return type;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGDependenceType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public enum PDGDependenceType {
4 | CONTROL, DATA, ANTI, OUTPUT;
5 | }
6 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGExitNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.Set;
4 |
5 | import gr.uom.java.ast.FieldObject;
6 | import gr.uom.java.ast.VariableDeclarationObject;
7 |
8 | public class PDGExitNode extends PDGStatementNode {
9 | private AbstractVariable returnedVariable;
10 |
11 | public PDGExitNode(CFGNode cfgNode, Set variableDeclarationsInMethod,
12 | Set fieldsAccessedInMethod) {
13 | super(cfgNode, variableDeclarationsInMethod, fieldsAccessedInMethod);
14 | if(cfgNode instanceof CFGExitNode) {
15 | CFGExitNode exitNode = (CFGExitNode)cfgNode;
16 | returnedVariable = exitNode.getReturnedVariable();
17 | }
18 | }
19 |
20 | public AbstractVariable getReturnedVariable() {
21 | return returnedVariable;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGMethodEntryNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ListIterator;
4 |
5 | import gr.uom.java.ast.AbstractMethodDeclaration;
6 | import gr.uom.java.ast.ParameterObject;
7 |
8 | public class PDGMethodEntryNode extends PDGNode {
9 | private AbstractMethodDeclaration method;
10 |
11 | public PDGMethodEntryNode(AbstractMethodDeclaration method) {
12 | super();
13 | this.method = method;
14 | this.id = 0;
15 | ListIterator parameterIterator = method.getParameterListIterator();
16 | while(parameterIterator.hasNext()) {
17 | ParameterObject parameter = parameterIterator.next();
18 | PlainVariable parameterVariable = new PlainVariable(parameter.getSingleVariableDeclaration());
19 | declaredVariables.add(parameterVariable);
20 | definedVariables.add(parameterVariable);
21 | }
22 | }
23 |
24 | public AbstractMethodDeclaration getMethod() {
25 | return method;
26 | }
27 |
28 | public BasicBlock getBasicBlock() {
29 | return null;
30 | }
31 |
32 | public boolean equals(Object o) {
33 | if(this == o)
34 | return true;
35 |
36 | if(o instanceof PDGMethodEntryNode) {
37 | PDGMethodEntryNode pdgNode = (PDGMethodEntryNode)o;
38 | return this.method.equals(pdgNode.method);
39 | }
40 | return false;
41 | }
42 |
43 | public int hashCode() {
44 | return method.hashCode();
45 | }
46 |
47 | public String toString() {
48 | return id + "\t" + method.getName();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGOutputDependence.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | public class PDGOutputDependence extends PDGAbstractDataDependence {
4 |
5 | public PDGOutputDependence(PDGNode src, PDGNode dst,
6 | AbstractVariable data, CFGBranchNode loop) {
7 | super(src, dst, PDGDependenceType.OUTPUT, data, loop);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGSliceUnionCollection.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.LinkedHashMap;
6 | import java.util.LinkedHashSet;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Set;
10 |
11 | public class PDGSliceUnionCollection {
12 | private Map sliceUnionMap;
13 |
14 | public PDGSliceUnionCollection(PDG pdg, PlainVariable localVariableCriterion) {
15 | this.sliceUnionMap = new LinkedHashMap();
16 | Set nodeCriteria = pdg.getAssignmentNodesOfVariableCriterion(localVariableCriterion);
17 | Map> boundaryBlockMap = new LinkedHashMap>();
18 | for(PDGNode nodeCriterion : nodeCriteria) {
19 | Set boundaryBlocks = pdg.boundaryBlocks(nodeCriterion);
20 | boundaryBlockMap.put(nodeCriterion, boundaryBlocks);
21 | }
22 | List> list = new ArrayList>(boundaryBlockMap.values());
23 | if(!list.isEmpty()) {
24 | Set basicBlockIntersection = new LinkedHashSet(list.get(0));
25 | for(int i=1; i getSliceUnions() {
37 | return sliceUnionMap.values();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGSynchronizedNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.Set;
4 |
5 | import gr.uom.java.ast.FieldObject;
6 | import gr.uom.java.ast.VariableDeclarationObject;
7 |
8 | public class PDGSynchronizedNode extends PDGBlockNode {
9 | public PDGSynchronizedNode(CFGSynchronizedNode cfgSynchronizedNode, Set variableDeclarationsInMethod,
10 | Set fieldsAccessedInMethod) {
11 | super(cfgSynchronizedNode, variableDeclarationsInMethod, fieldsAccessedInMethod);
12 | this.controlParent = cfgSynchronizedNode.getControlParent();
13 | determineDefinedAndUsedVariables();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PDGTryNode.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Set;
6 |
7 | import gr.uom.java.ast.FieldObject;
8 | import gr.uom.java.ast.VariableDeclarationObject;
9 | import gr.uom.java.ast.decomposition.AbstractStatement;
10 | import gr.uom.java.ast.decomposition.CatchClauseObject;
11 | import gr.uom.java.ast.decomposition.TryStatementObject;
12 |
13 | public class PDGTryNode extends PDGBlockNode {
14 | public PDGTryNode(CFGTryNode cfgTryNode, Set variableDeclarationsInMethod,
15 | Set fieldsAccessedInMethod) {
16 | super(cfgTryNode, variableDeclarationsInMethod, fieldsAccessedInMethod);
17 | this.controlParent = cfgTryNode.getControlParent();
18 | determineDefinedAndUsedVariables();
19 | }
20 |
21 | public boolean hasFinallyClauseClosingVariable(AbstractVariable variable) {
22 | return ((CFGTryNode)getCFGNode()).hasFinallyClauseClosingVariable(variable);
23 | }
24 |
25 | public boolean hasCatchClause() {
26 | return ((CFGTryNode)getCFGNode()).hasCatchClause();
27 | }
28 |
29 | protected void determineDefinedAndUsedVariables() {
30 | super.determineDefinedAndUsedVariables();
31 | CFGNode cfgNode = getCFGNode();
32 | if(cfgNode.getStatement() instanceof TryStatementObject) {
33 | TryStatementObject tryStatement = (TryStatementObject)cfgNode.getStatement();
34 | List statementsInCatchClausesAndFinallyBlock = new ArrayList();
35 | for(CatchClauseObject catchClause : tryStatement.getCatchClauses()) {
36 | statementsInCatchClausesAndFinallyBlock.add(catchClause.getBody());
37 | }
38 | if(tryStatement.getFinallyClause() != null) {
39 | statementsInCatchClausesAndFinallyBlock.add(tryStatement.getFinallyClause());
40 | }
41 | for(AbstractStatement statement : statementsInCatchClausesAndFinallyBlock) {
42 | for(PlainVariable variable : statement.getDefinedLocalVariables()) {
43 | definedVariables.add(variable);
44 | }
45 | for(PlainVariable variable : statement.getUsedLocalVariables()) {
46 | usedVariables.add(variable);
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/PlainVariable.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg;
2 |
3 | import org.eclipse.jdt.core.dom.IVariableBinding;
4 | import org.eclipse.jdt.core.dom.VariableDeclaration;
5 |
6 | public class PlainVariable extends AbstractVariable {
7 | private volatile int hashCode = 0;
8 |
9 | public PlainVariable(VariableDeclaration variableName) {
10 | super(variableName);
11 | }
12 |
13 | public PlainVariable(IVariableBinding variableBinding) {
14 | super(variableBinding);
15 | }
16 |
17 | public PlainVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic) {
18 | super(variableBindingKey, variableName, variableType, isField, isParameter, isStatic);
19 | }
20 |
21 | public boolean containsPlainVariable(PlainVariable variable) {
22 | return this.variableBindingKey.equals(variable.variableBindingKey);
23 | }
24 |
25 | public boolean startsWithVariable(AbstractVariable variable) {
26 | if(variable instanceof PlainVariable) {
27 | return this.equals((PlainVariable)variable);
28 | }
29 | return false;
30 | }
31 |
32 | public PlainVariable getInitialVariable() {
33 | return this;
34 | }
35 |
36 | public boolean equals(Object o) {
37 | if(this == o) {
38 | return true;
39 | }
40 | if(o instanceof PlainVariable) {
41 | PlainVariable plain = (PlainVariable)o;
42 | return this.variableBindingKey.equals(plain.variableBindingKey);
43 | }
44 | return false;
45 | }
46 |
47 | public int hashCode() {
48 | if(hashCode == 0) {
49 | int result = 17;
50 | result = 31*result + variableBindingKey.hashCode();
51 | hashCode = result;
52 | }
53 | return hashCode;
54 | }
55 |
56 | public String toString() {
57 | StringBuilder sb = new StringBuilder();
58 | sb.append(variableName);
59 | return sb.toString();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/CloneRefactoringType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | public enum CloneRefactoringType {
4 | EXTRACT_LOCAL_METHOD,
5 | PULL_UP_TO_EXISTING_SUPERCLASS,
6 | PULL_UP_TO_NEW_INTERMEDIATE_SUPERCLASS_EXTENDING_COMMON_INTERNAL_SUPERCLASS,
7 | PULL_UP_TO_NEW_INTERMEDIATE_SUPERCLASS_IMPLEMENTING_COMMON_INTERNAL_INTERFACE,
8 | PULL_UP_TO_NEW_SUPERCLASS_EXTENDING_COMMON_EXTERNAL_SUPERCLASS,
9 | PULL_UP_TO_NEW_SUPERCLASS_IMPLEMENTING_COMMON_EXTERNAL_INTERFACE,
10 | PULL_UP_TO_NEW_SUPERCLASS_EXTENDING_OBJECT,
11 | EXTRACT_STATIC_METHOD_TO_NEW_UTILITY_CLASS,
12 | INFEASIBLE;
13 | }
14 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/CloneType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | public enum CloneType {
4 | TYPE_1("Type 1"),
5 | TYPE_2("Type 2"),
6 | TYPE_3("Type 3"),
7 | UNKNOWN("Unknown type");
8 |
9 | private String typeString;
10 | private CloneType(String typeString) {
11 | this.typeString = typeString;
12 | }
13 |
14 | @Override
15 | public String toString() {
16 | return this.typeString;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/ControlDependenceTreeNodeMatchPairComparator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import java.util.Comparator;
4 |
5 | public class ControlDependenceTreeNodeMatchPairComparator implements
6 | Comparator {
7 |
8 | public int compare(ControlDependenceTreeNodeMatchPair o1,
9 | ControlDependenceTreeNodeMatchPair o2) {
10 |
11 | int count1 = o1.getDistinctDifferenceCount();
12 | int count2 = o2.getDistinctDifferenceCount();
13 | if(count1 != count2) {
14 | return Integer.valueOf(count1).compareTo(Integer.valueOf(count2));
15 | }
16 | else {
17 | count1 = o1.getNonDistinctDifferenceCount();
18 | count2 = o2.getNonDistinctDifferenceCount();
19 | if(count1 != count2) {
20 | return Integer.valueOf(count1).compareTo(Integer.valueOf(count2));
21 | }
22 | else {
23 | count1 = o1.getNonDistinctDifferenceCountIncludingTypeMismatches();
24 | count2 = o2.getNonDistinctDifferenceCountIncludingTypeMismatches();
25 | if(count1 != count2) {
26 | return Integer.valueOf(count1).compareTo(Integer.valueOf(count2));
27 | }
28 | }
29 | }
30 | return 0;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/IdBasedGap.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | public abstract class IdBasedGap extends NodeMapping {
4 | protected double id1;
5 | protected double id2;
6 | private boolean advancedMatch;
7 | //if an id is equal to zero it means that this id does not exist
8 | public IdBasedGap(double id1, double id2, boolean advancedMatch) {
9 | this.id1 = id1;
10 | this.id2 = id2;
11 | this.advancedMatch = advancedMatch;
12 | }
13 |
14 | public double getId1() {
15 | return id1;
16 | }
17 |
18 | public double getId2() {
19 | return id2;
20 | }
21 |
22 | public boolean isAdvancedMatch() {
23 | return advancedMatch;
24 | }
25 |
26 | public int compareTo(IdBasedGap other) {
27 | if(this.id1 != 0 && other.id1 != 0)
28 | return Double.compare(this.id1, other.id1);
29 | if(this.id2 != 0 && other.id2 != 0)
30 | return Double.compare(this.id2, other.id2);
31 |
32 | if(this.id1 != 0 && other.id2 != 0) {
33 | double id1 = this.id1;
34 | double id2 = other.id2;
35 | if(id1 == id2)
36 | return -1;
37 | else
38 | return Double.compare(id1, id2);
39 | }
40 | if(other.id1 != 0 && this.id2 != 0) {
41 | double id2 = other.id1;
42 | double id1 = this.id2;
43 | if(id1 == id2)
44 | return -1;
45 | else
46 | return Double.compare(id1, id2);
47 | }
48 | return 0;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/IdBasedMapping.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | public abstract class IdBasedMapping extends NodeMapping {
4 | protected double id1;
5 | protected double id2;
6 |
7 | public IdBasedMapping(double id1, double id2) {
8 | this.id1 = id1;
9 | this.id2 = id2;
10 | }
11 |
12 | public double getId1() {
13 | return id1;
14 | }
15 |
16 | public double getId2() {
17 | return id2;
18 | }
19 |
20 | public int compareTo(IdBasedMapping other) {
21 | return Double.compare(this.id1, other.id1);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/IdenticalStatementDecomposer.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import gr.uom.java.ast.decomposition.cfg.PDGNode;
4 |
5 | import java.util.LinkedHashMap;
6 | import java.util.LinkedHashSet;
7 | import java.util.Map;
8 | import java.util.Set;
9 |
10 | public class IdenticalStatementDecomposer {
11 |
12 | private Map> identicalNodeMap;
13 |
14 | public IdenticalStatementDecomposer(Set nodes) {
15 | this.identicalNodeMap = new LinkedHashMap>();
16 | Map> tempMap = new LinkedHashMap>();
17 | for(PDGNode node : nodes) {
18 | String nodeString = node.getASTStatement().toString();
19 | if(tempMap.containsKey(nodeString)) {
20 | Set keyNodes = tempMap.get(nodeString);
21 | keyNodes.add(node);
22 | }
23 | else {
24 | Set keyNodes = new LinkedHashSet();
25 | keyNodes.add(node);
26 | tempMap.put(nodeString, keyNodes);
27 | }
28 | }
29 | for(String key : tempMap.keySet()) {
30 | Set keyNodes = tempMap.get(key);
31 | if(keyNodes.size() > 1) {
32 | identicalNodeMap.put(key, keyNodes);
33 | }
34 | }
35 | }
36 |
37 | public Map> getIdenticalNodeMap() {
38 | return identicalNodeMap;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/PDGElseGap.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import gr.uom.java.ast.decomposition.cfg.PDGNode;
4 | import gr.uom.java.ast.decomposition.matching.ASTNodeDifference;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class PDGElseGap extends IdBasedGap {
10 | private volatile int hashCode = 0;
11 |
12 | public PDGElseGap(double id1, double id2, boolean advancedMatch) {
13 | super(id1, id2, advancedMatch);
14 | }
15 |
16 | public PDGNode getNodeG1() {
17 | return null;
18 | }
19 |
20 | public PDGNode getNodeG2() {
21 | return null;
22 | }
23 |
24 | public List getNodeDifferences() {
25 | return new ArrayList();
26 | }
27 |
28 | public boolean equals(Object o) {
29 | if(this == o)
30 | return true;
31 | if(o instanceof PDGElseGap) {
32 | PDGElseGap gap = (PDGElseGap)o;
33 | if(this.id1 == 0 && gap.id1 == 0)
34 | return this.id2 == gap.id2;
35 | if(this.id2 == 0 && gap.id2 == 0)
36 | return this.id1 == gap.id1;
37 | }
38 | return false;
39 | }
40 |
41 | public int hashCode() {
42 | if(hashCode == 0) {
43 | int result = 17;
44 | long id1 = Double.doubleToLongBits(this.id1);
45 | result = 37*result + (int) (id1 ^ (id1 >>> 32));
46 | long id2 = Double.doubleToLongBits(this.id2);
47 | result = 37*result + (int) (id2 ^ (id2 >>> 32));
48 | hashCode = result;
49 | }
50 | return hashCode;
51 | }
52 |
53 | public String toString() {
54 | StringBuilder sb = new StringBuilder();
55 | if(id1 != 0)
56 | sb.append(id1 + "\telse\n");
57 | else
58 | sb.append("\n");
59 | if(id2 != 0)
60 | sb.append(id2 + "\telse\n");
61 | else
62 | sb.append("\n");
63 | return sb.toString();
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/PDGElseMapping.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import gr.uom.java.ast.decomposition.cfg.PDGNode;
4 | import gr.uom.java.ast.decomposition.matching.ASTNodeDifference;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class PDGElseMapping extends IdBasedMapping {
10 | private PDGNodeMapping symmetricalIfNodePair;
11 | private volatile int hashCode = 0;
12 |
13 | public PDGElseMapping(double id1, double id2) {
14 | super(id1, id2);
15 | }
16 |
17 | public PDGNode getNodeG1() {
18 | return null;
19 | }
20 |
21 | public PDGNode getNodeG2() {
22 | return null;
23 | }
24 |
25 | public List getNodeDifferences() {
26 | return new ArrayList();
27 | }
28 |
29 | public boolean isAdvancedMatch() {
30 | return false;
31 | }
32 |
33 | public PDGNodeMapping getSymmetricalIfNodePair() {
34 | return symmetricalIfNodePair;
35 | }
36 |
37 | public void setSymmetricalIfNodePair(PDGNodeMapping symmetricalIfNodePair) {
38 | this.symmetricalIfNodePair = symmetricalIfNodePair;
39 | }
40 |
41 | public boolean equals(Object o) {
42 | if(this == o)
43 | return true;
44 | if(o instanceof PDGElseMapping) {
45 | PDGElseMapping mapping = (PDGElseMapping)o;
46 | return this.id1 == mapping.id1 &&
47 | this.id2 == mapping.id2;
48 | }
49 | return false;
50 | }
51 |
52 | public int hashCode() {
53 | if(hashCode == 0) {
54 | int result = 17;
55 | long id1 = Double.doubleToLongBits(this.id1);
56 | result = 37*result + (int) (id1 ^ (id1 >>> 32));
57 | long id2 = Double.doubleToLongBits(this.id2);
58 | result = 37*result + (int) (id2 ^ (id2 >>> 32));
59 | hashCode = result;
60 | }
61 | return hashCode;
62 | }
63 |
64 | public String toString() {
65 | StringBuilder sb = new StringBuilder();
66 | sb.append(id1 + "\telse\n");
67 | sb.append(id2 + "\telse\n");
68 | return sb.toString();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/SubTreeMatchComparator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import java.util.Comparator;
4 |
5 | public class SubTreeMatchComparator implements Comparator {
6 |
7 | public int compare(CompleteSubTreeMatch o1, CompleteSubTreeMatch o2) {
8 | int size1 = o1.getMatchPairs().size();
9 | int size2 = o2.getMatchPairs().size();
10 | return -Integer.valueOf(size1).compareTo(Integer.valueOf(size2));
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/SwitchBodyDecomposer.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import gr.uom.java.ast.decomposition.cfg.PDGNode;
4 |
5 | import java.util.LinkedHashMap;
6 | import java.util.LinkedHashSet;
7 | import java.util.Map;
8 | import java.util.Set;
9 |
10 | import org.eclipse.jdt.core.dom.SwitchCase;
11 |
12 | public class SwitchBodyDecomposer {
13 | private Map> switchCaseNodeMap;
14 |
15 | public SwitchBodyDecomposer(Set nodes) {
16 | this.switchCaseNodeMap = new LinkedHashMap>();
17 | PDGNode currentSwitchCase = null;
18 | for(PDGNode node : nodes) {
19 | if(node.getASTStatement() instanceof SwitchCase) {
20 | currentSwitchCase = node;
21 | switchCaseNodeMap.put(currentSwitchCase, new LinkedHashSet());
22 | }
23 | else {
24 | if(currentSwitchCase != null) {
25 | if(switchCaseNodeMap.containsKey(currentSwitchCase)) {
26 | Set switchCaseNodes = switchCaseNodeMap.get(currentSwitchCase);
27 | switchCaseNodes.add(node);
28 | }
29 | else {
30 | Set switchCaseNodes = new LinkedHashSet();
31 | switchCaseNodes.add(node);
32 | switchCaseNodeMap.put(currentSwitchCase, switchCaseNodes);
33 | }
34 | }
35 | }
36 | }
37 | }
38 |
39 | public Map> getSwitchCaseNodeMap() {
40 | return switchCaseNodeMap;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/VariableBindingKeyPair.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | public class VariableBindingKeyPair {
4 | private String key1;
5 | private String key2;
6 |
7 | public VariableBindingKeyPair(String key1, String key2) {
8 | this.key1 = key1;
9 | this.key2 = key2;
10 | }
11 |
12 | public String getKey1() {
13 | return key1;
14 | }
15 |
16 | public String getKey2() {
17 | return key2;
18 | }
19 |
20 | public boolean equals(Object o) {
21 | if(this == o)
22 | return true;
23 | if(o instanceof VariableBindingKeyPair) {
24 | VariableBindingKeyPair keyPair = (VariableBindingKeyPair)o;
25 | return this.key1.equals(keyPair.key1) &&
26 | this.key2.equals(keyPair.key2);
27 | }
28 | return false;
29 | }
30 |
31 | public int hashCode() {
32 | int result = 17;
33 | result = 37*result + key1.hashCode();
34 | result = 37*result + key2.hashCode();
35 | return result;
36 | }
37 |
38 | public String toString() {
39 | StringBuilder sb = new StringBuilder();
40 | sb.append(key1);
41 | sb.append("\n");
42 | sb.append(key2);
43 | return sb.toString();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/VariableBindingPair.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping;
2 |
3 | import org.eclipse.jdt.core.dom.IVariableBinding;
4 | import org.eclipse.jdt.core.dom.VariableDeclaration;
5 |
6 | import gr.uom.java.jdeodorant.refactoring.manipulators.RefactoringUtility;
7 |
8 | public class VariableBindingPair {
9 | private IVariableBinding binding1;
10 | private IVariableBinding binding2;
11 | private boolean hasQualifiedType = false;
12 |
13 | public VariableBindingPair(IVariableBinding binding1, IVariableBinding binding2) {
14 | this.binding1 = binding1;
15 | this.binding2 = binding2;
16 | }
17 |
18 | public VariableBindingPair(IVariableBinding binding1, IVariableBinding binding2, VariableDeclaration variableDeclaration) {
19 | this(binding1, binding2);
20 | this.hasQualifiedType = RefactoringUtility.hasQualifiedType(variableDeclaration);
21 | }
22 |
23 | public IVariableBinding getBinding1() {
24 | return binding1;
25 | }
26 |
27 | public IVariableBinding getBinding2() {
28 | return binding2;
29 | }
30 |
31 | public boolean hasQualifiedType() {
32 | return hasQualifiedType;
33 | }
34 |
35 | public VariableBindingKeyPair getVariableBindingKeyPair() {
36 | return new VariableBindingKeyPair(binding1.getKey(), binding2.getKey());
37 | }
38 |
39 | public boolean equals(Object o) {
40 | if(this == o)
41 | return true;
42 | if(o instanceof VariableBindingPair) {
43 | VariableBindingPair keyPair = (VariableBindingPair)o;
44 | return this.binding1.getKey().equals(keyPair.binding1.getKey()) &&
45 | this.binding2.getKey().equals(keyPair.binding2.getKey());
46 | }
47 | return false;
48 | }
49 |
50 | public int hashCode() {
51 | int result = 17;
52 | result = 37*result + binding1.getKey().hashCode();
53 | result = 37*result + binding2.getKey().hashCode();
54 | return result;
55 | }
56 |
57 | public String toString() {
58 | StringBuilder sb = new StringBuilder();
59 | sb.append(binding1);
60 | sb.append("\n");
61 | sb.append(binding2);
62 | return sb.toString();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/BoldStyler.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import org.eclipse.jface.viewers.StyledString.Styler;
4 | import org.eclipse.swt.SWT;
5 | import org.eclipse.swt.graphics.Font;
6 | import org.eclipse.swt.graphics.FontData;
7 | import org.eclipse.swt.graphics.TextStyle;
8 |
9 | public class BoldStyler extends Styler {
10 |
11 | private static final Font CONSOLAS_BOLD_FONT = new Font(null, new FontData("consolas", 8, SWT.BOLD));
12 |
13 | public void applyStyles(TextStyle textStyle) {
14 | textStyle.font = CONSOLAS_BOLD_FONT;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/ExpressionPreconditionViolation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import gr.uom.java.ast.decomposition.AbstractExpression;
4 | import gr.uom.java.ast.decomposition.matching.ASTNodeDifference;
5 |
6 | import org.eclipse.jdt.core.dom.Expression;
7 | import org.eclipse.jface.viewers.StyledString;
8 |
9 | public class ExpressionPreconditionViolation extends PreconditionViolation {
10 | private AbstractExpression expression;
11 |
12 | public ExpressionPreconditionViolation(AbstractExpression expression, PreconditionViolationType type) {
13 | super(type);
14 | this.expression = expression;
15 | }
16 |
17 | public AbstractExpression getExpression() {
18 | return expression;
19 | }
20 |
21 | public String getViolation() {
22 | StringBuilder sb = new StringBuilder();
23 | sb.append("Expression ");
24 | Expression expression = this.expression.getExpression();
25 | expression = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(expression);
26 | sb.append(expression.toString());
27 | sb.append(" ");
28 | sb.append(type.toString());
29 | return sb.toString();
30 | }
31 |
32 | public StyledString getStyledViolation() {
33 | BoldStyler boldStyler = new BoldStyler();
34 | NormalStyler normalStyler = new NormalStyler();
35 | StyledString styledString = new StyledString();
36 | styledString.append("Expression ", normalStyler);
37 | Expression expression = this.expression.getExpression();
38 | expression = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(expression);
39 | styledString.append(expression.toString(), boldStyler);
40 | styledString.append(" ", normalStyler);
41 | styledString.append(type.toString(), normalStyler);
42 | return styledString;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/NormalStyler.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import org.eclipse.jface.viewers.StyledString.Styler;
4 | import org.eclipse.swt.SWT;
5 | import org.eclipse.swt.graphics.Font;
6 | import org.eclipse.swt.graphics.FontData;
7 | import org.eclipse.swt.graphics.TextStyle;
8 |
9 | public class NormalStyler extends Styler {
10 |
11 | private static final Font TAHOMA_NORMAL_FONT = new Font(null, new FontData("Tahoma", 8, SWT.NORMAL));
12 |
13 | @Override
14 | public void applyStyles(TextStyle textStyle) {
15 | textStyle.font = TAHOMA_NORMAL_FONT;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/NotAllPossibleExecutionFlowsEndInReturnPreconditionViolation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import org.eclipse.jface.viewers.StyledString;
4 |
5 | public class NotAllPossibleExecutionFlowsEndInReturnPreconditionViolation extends PreconditionViolation {
6 |
7 | public NotAllPossibleExecutionFlowsEndInReturnPreconditionViolation() {
8 | super(PreconditionViolationType.NOT_ALL_POSSIBLE_EXECUTION_FLOWS_END_IN_RETURN);
9 | }
10 |
11 | @Override
12 | public String getViolation() {
13 | StringBuilder sb = new StringBuilder();
14 | sb.append("Not all possible execution flows end in a return statement");
15 | return sb.toString();
16 | }
17 |
18 | @Override
19 | public StyledString getStyledViolation() {
20 | StyledString styledString = new StyledString();
21 | NormalStyler normalStyler = new NormalStyler();
22 | styledString.append("Not all possible execution flows end in a return statement", normalStyler);
23 | return styledString;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/PreconditionViolation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.eclipse.jface.viewers.StyledString;
7 |
8 | public abstract class PreconditionViolation {
9 | protected PreconditionViolationType type;
10 | protected List suggestions;
11 |
12 | public PreconditionViolation(PreconditionViolationType type) {
13 | this.type = type;
14 | suggestions = new ArrayList();
15 | }
16 |
17 | public abstract String getViolation();
18 | public abstract StyledString getStyledViolation();
19 |
20 | public List getSuggestions() {
21 | return suggestions;
22 | }
23 |
24 | public void addSuggestion(String suggestionString) {
25 | this.suggestions.add(new Suggestion(suggestionString, this));
26 | }
27 |
28 | public String toString() {
29 | return getViolation() + "\n";
30 | }
31 |
32 | public PreconditionViolationType getType() {
33 | return this.type;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/Suggestion.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | public class Suggestion {
4 |
5 | private String suggestion;
6 | private PreconditionViolation preconditionViolation;
7 |
8 | public Suggestion(String suggestion, PreconditionViolation preconditionViolation){
9 | this.suggestion = suggestion;
10 | this.preconditionViolation = preconditionViolation;
11 | }
12 | public PreconditionViolation getPreconditionViolation(){
13 | return preconditionViolation;
14 | }
15 | public String getSuggestion(){
16 | return suggestion;
17 | }
18 | public void setSuggestion(String suggestion){
19 | this.suggestion = suggestion;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/UncommonSuperclassPreconditionViolation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import org.eclipse.jface.viewers.StyledString;
4 |
5 | public class UncommonSuperclassPreconditionViolation extends PreconditionViolation {
6 |
7 | private String qualifiedType1;
8 | private String qualifiedType2;
9 | public UncommonSuperclassPreconditionViolation(String type1, String type2) {
10 | super(PreconditionViolationType.INFEASIBLE_REFACTORING_DUE_TO_UNCOMMON_SUPERCLASS);
11 | this.qualifiedType1 = type1;
12 | this.qualifiedType2 = type2;
13 | }
14 |
15 | @Override
16 | public String getViolation() {
17 | StringBuilder sb = new StringBuilder();
18 | sb.append("The refactoring of the clones is infeasible, because classes ");
19 | sb.append(qualifiedType1);
20 | sb.append(" and ");
21 | sb.append(qualifiedType2);
22 | sb.append(" do not have a common superclass");
23 | return sb.toString();
24 | }
25 |
26 | @Override
27 | public StyledString getStyledViolation() {
28 | StyledString styledString = new StyledString();
29 | NormalStyler normalStyler = new NormalStyler();
30 | BoldStyler boldStyler = new BoldStyler();
31 | styledString.append("The refactoring of the clones is infeasible, because classes ", normalStyler);
32 | styledString.append(qualifiedType1, boldStyler);
33 | styledString.append(" and ", normalStyler);
34 | styledString.append(qualifiedType2, boldStyler);
35 | styledString.append(" do not have a common superclass", normalStyler);
36 | return styledString;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/cfg/mapping/precondition/ZeroMatchedStatementsPreconditionViolation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.cfg.mapping.precondition;
2 |
3 | import org.eclipse.jface.viewers.StyledString;
4 |
5 | public class ZeroMatchedStatementsPreconditionViolation extends PreconditionViolation {
6 |
7 | public ZeroMatchedStatementsPreconditionViolation() {
8 | super(PreconditionViolationType.INFEASIBLE_REFACTORING_DUE_TO_ZERO_MATCHED_STATEMENTS);
9 | }
10 |
11 | @Override
12 | public String getViolation() {
13 | StringBuilder sb = new StringBuilder();
14 | sb.append("The refactoring of the clones is infeasible, because the number of macthed statements is equal to zero");
15 | return sb.toString();
16 | }
17 |
18 | @Override
19 | public StyledString getStyledViolation() {
20 | StyledString styledString = new StyledString();
21 | NormalStyler normalStyler = new NormalStyler();
22 | styledString.append("The refactoring of the clones is infeasible, because the number of macthed statements is equal to zero", normalStyler);
23 | return styledString;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/Difference.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching;
2 |
3 | public class Difference {
4 | private String firstValue;
5 | private String secondValue;
6 | private DifferenceType type;
7 | private int weight = 1;
8 | private volatile int hashCode = 0;
9 |
10 | public Difference(String firstValue, String secondValue, DifferenceType type) {
11 | this.firstValue = firstValue;
12 | this.secondValue = secondValue;
13 | this.type = type;
14 | }
15 |
16 | public Difference(String firstValue, String secondValue, DifferenceType type, int weight) {
17 | this(firstValue, secondValue, type);
18 | this.weight = weight;
19 | }
20 |
21 | public DifferenceType getType() {
22 | return type;
23 | }
24 |
25 | public String getFirstValue() {
26 | return firstValue;
27 | }
28 |
29 | public String getSecondValue() {
30 | return secondValue;
31 | }
32 |
33 | public int getWeight() {
34 | return weight;
35 | }
36 |
37 | public void setWeight(int weight) {
38 | this.weight = weight;
39 | }
40 |
41 | public boolean equals(Object o) {
42 | if(this == o)
43 | return true;
44 | if(o instanceof Difference) {
45 | Difference other = (Difference)o;
46 | return this.type.equals(other.type) &&
47 | this.firstValue.equals(other.firstValue) &&
48 | this.secondValue.equals(other.secondValue);
49 | }
50 | return false;
51 | }
52 |
53 | public int hashCode() {
54 | if(hashCode == 0) {
55 | int result = 17;
56 | result = 37*result + type.hashCode();
57 | result = 37*result + firstValue.hashCode();
58 | result = 37*result + secondValue.hashCode();
59 | hashCode = result;
60 | }
61 | return hashCode;
62 | }
63 |
64 | public String toString() {
65 | StringBuilder sb = new StringBuilder();
66 | sb.append(firstValue).append("\t").append(secondValue).append("\t").append(type);
67 | return sb.toString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/FieldAccessReplacedWithGetterInvocationDifference.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import gr.uom.java.ast.decomposition.AbstractExpression;
7 |
8 | public class FieldAccessReplacedWithGetterInvocationDifference extends ASTNodeDifference {
9 |
10 | private AbstractExpression invoker1;
11 | private AbstractExpression invoker2;
12 | private String getterMethodName;
13 | private List invokerDifferences;
14 |
15 | public FieldAccessReplacedWithGetterInvocationDifference(AbstractExpression e1, AbstractExpression e2,
16 | String getterMethodName) {
17 | super(e1, e2);
18 | this.getterMethodName = getterMethodName;
19 | this.invokerDifferences = new ArrayList();
20 | }
21 |
22 | public String getGetterMethodName() {
23 | return getterMethodName;
24 | }
25 |
26 | public List getInvokerDifferences() {
27 | return invokerDifferences;
28 | }
29 | public void addInvokerDifference(ASTNodeDifference invokerDifference) {
30 | this.invokerDifferences.add(invokerDifference);
31 | }
32 | public AbstractExpression getInvoker1() {
33 | return invoker1;
34 | }
35 | public void setInvoker1(AbstractExpression invoker1) {
36 | this.invoker1 = invoker1;
37 | }
38 | public AbstractExpression getInvoker2() {
39 | return invoker2;
40 | }
41 | public void setInvoker2(AbstractExpression invoker2) {
42 | this.invoker2 = invoker2;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/NodePair.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching;
2 |
3 | public class NodePair {
4 | private int id1;
5 | private int id2;
6 |
7 | public NodePair(int id1, int id2) {
8 | this.id1 = id1;
9 | this.id2 = id2;
10 | }
11 |
12 | public int hashCode() {
13 | final int prime = 31;
14 | int result = 17;
15 | result = prime * result + id1;
16 | result = prime * result + id2;
17 | return result;
18 | }
19 |
20 | public boolean equals(Object o) {
21 | if (this == o)
22 | return true;
23 | if(o instanceof NodePair) {
24 | NodePair other = (NodePair)o;
25 | return this.id1 == other.id1 && this.id2 == other.id2;
26 | }
27 | return false;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/conditional/AbstractControlCase.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.conditional;
2 |
3 | import gr.uom.java.ast.decomposition.matching.ASTNodeMatcher;
4 |
5 | import java.util.List;
6 |
7 | import org.eclipse.jdt.core.dom.Expression;
8 | import org.eclipse.jdt.core.dom.Statement;
9 |
10 | public abstract class AbstractControlCase
11 | {
12 | protected Expression caseCondition;
13 | protected List body;
14 |
15 | @Override
16 | public String toString()
17 | {
18 | StringBuilder returnString = new StringBuilder();
19 | returnString.append("caseCondition = " + this.caseCondition + "\n");
20 | for (Statement currentStatement : this.body)
21 | {
22 | returnString.append(" " + currentStatement);
23 | }
24 | return returnString.toString();
25 | }
26 |
27 | public void addBodyStatement(Statement statement)
28 | {
29 | this.body.add(statement);
30 | }
31 |
32 | public List getBody()
33 | {
34 | return this.body;
35 | }
36 |
37 | public boolean isDefaultCase()
38 | {
39 | return this.caseCondition == null;
40 | }
41 |
42 | public boolean match(AbstractControlCase otherCase, ASTNodeMatcher matcher)
43 | {
44 | if (otherCase instanceof IfControlCase)
45 | {
46 | return this.match((IfControlCase)otherCase, matcher);
47 | }
48 | else if (otherCase instanceof SwitchControlCase)
49 | {
50 | return this.match((SwitchControlCase)otherCase, matcher);
51 | }
52 | return false;
53 | }
54 |
55 | public abstract boolean match(IfControlCase otherCase, ASTNodeMatcher matcher);
56 | public abstract boolean match(SwitchControlCase otherCase, ASTNodeMatcher matcher);
57 | }
58 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/conditional/AbstractControlStructure.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.conditional;
2 |
3 | import gr.uom.java.ast.decomposition.matching.ASTNodeMatcher;
4 |
5 | import java.util.List;
6 |
7 | import org.eclipse.jdt.core.dom.ASTNode;
8 | import org.eclipse.jdt.core.dom.Statement;
9 |
10 | public abstract class AbstractControlStructure
11 | {
12 | private Statement node;
13 | protected List controlCases;
14 |
15 | public AbstractControlStructure(Statement node)
16 | {
17 | this.node = node;
18 | }
19 |
20 | @Override
21 | public String toString()
22 | {
23 | return node.toString();
24 | }
25 |
26 | public Statement getNode()
27 | {
28 | return node;
29 | }
30 |
31 | public boolean match(AbstractControlStructure otherControlStructure, ASTNodeMatcher matcher)
32 | {
33 | if (otherControlStructure instanceof IfControlStructure)
34 | {
35 | return this.match((IfControlStructure)otherControlStructure, matcher);
36 | }
37 | else if (otherControlStructure instanceof SwitchControlStructure)
38 | {
39 | return this.match((SwitchControlStructure)otherControlStructure, matcher);
40 | }
41 | else if (otherControlStructure instanceof TernaryControlStructure)
42 | {
43 | return this.match((TernaryControlStructure)otherControlStructure, matcher);
44 | }
45 | return false;
46 | }
47 |
48 | public abstract boolean match(IfControlStructure otherStructure, ASTNodeMatcher matcher);
49 | public abstract boolean match(SwitchControlStructure otherStructure, ASTNodeMatcher matcher);
50 | public abstract boolean match(TernaryControlStructure otherStructure, ASTNodeMatcher matcher);
51 | public abstract List getAdditionalFragments();
52 | }
53 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/conditional/IfControlCase.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.conditional;
2 |
3 | import gr.uom.java.ast.decomposition.matching.ASTNodeMatcher;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import org.eclipse.jdt.core.dom.Expression;
9 | import org.eclipse.jdt.core.dom.Statement;
10 |
11 | public class IfControlCase extends AbstractControlCase
12 | {
13 | public IfControlCase(Expression condition, Statement body)
14 | {
15 | this.caseCondition = condition;
16 | List statements = new ArrayList();
17 | statements.add(body);
18 | this.body = AbstractControlStructureUtilities.unBlock(statements);
19 | }
20 |
21 | @Override
22 | public boolean match(IfControlCase otherCase, ASTNodeMatcher matcher)
23 | {
24 | return matcher.safeSubtreeMatch(this.caseCondition, otherCase.caseCondition);
25 | }
26 |
27 | @Override
28 | public boolean match(SwitchControlCase otherCase, ASTNodeMatcher matcher)
29 | {
30 | return false;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/conditional/Pair.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.conditional;
2 |
3 | public class Pair
4 | {
5 | private T first;
6 | private T second;
7 |
8 | public Pair(T first, T second)
9 | {
10 | this.first = first;
11 | this.second = second;
12 | }
13 |
14 | @Override
15 | @SuppressWarnings("unchecked")
16 | public boolean equals(Object other)
17 | {
18 | if (this == other)
19 | {
20 | return true;
21 | }
22 | if (other == null)
23 | {
24 | return false;
25 | }
26 | if (this.getClass() != other.getClass())
27 | {
28 | return false;
29 | }
30 | Pair otherPair = (Pair) other;
31 | return ((this.first == otherPair.first ||
32 | (this.first != null && otherPair.first != null && this.first.equals(otherPair.first)))
33 | &&
34 | (this.second == otherPair.second ||
35 | (this.second != null && otherPair.second != null && this.second.equals(otherPair.second))));
36 | }
37 |
38 | @Override
39 | public int hashCode()
40 | {
41 | final int prime = 31;
42 | int result = 1;
43 | result = prime * result + ((this.first == null) ? 0 : this.first.hashCode());
44 | result = prime * result + ((this.second == null) ? 0 : this.second.hashCode());
45 | return result;
46 | }
47 |
48 | public T getFirst()
49 | {
50 | return this.first;
51 | }
52 |
53 | public void setFirst(T first)
54 | {
55 | this.first = first;
56 | }
57 |
58 | public T getSecond() {
59 | return this.second;
60 | }
61 |
62 | public void setSecond(T second)
63 | {
64 | this.second = second;
65 | }
66 |
67 | @Override
68 | public String toString()
69 | {
70 | return "(" + this.first + ", " + this.second + ")";
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/loop/AbstractControlVariable.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.loop;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.eclipse.jdt.core.dom.Expression;
7 |
8 | public class AbstractControlVariable
9 | {
10 | protected VariableValue startValue;
11 | protected VariableValue endValue;
12 | protected List variableUpdaters;
13 | protected Expression dataStructureExpression;
14 |
15 | public AbstractControlVariable()
16 | {
17 | this.startValue = new VariableValue(VariableValue.ValueType.VARIABLE);
18 | this.endValue = new VariableValue(VariableValue.ValueType.VARIABLE);
19 | this.variableUpdaters = new ArrayList();
20 | }
21 |
22 | public AbstractControlVariable(VariableValue startValue, VariableValue endValue, List variableUpdaters,
23 | Expression dataStructureExpression)
24 | {
25 | this.startValue = startValue;
26 | this.endValue = endValue;
27 | this.variableUpdaters = variableUpdaters;
28 | this.dataStructureExpression = dataStructureExpression;
29 | }
30 |
31 | public List getVariableUpdaters()
32 | {
33 | return variableUpdaters;
34 | }
35 |
36 | public Expression getDataStructureExpression()
37 | {
38 | return dataStructureExpression;
39 | }
40 |
41 | public boolean match(AbstractControlVariable otherControlVariable)
42 | {
43 | return this.startValue.match(otherControlVariable.startValue) &&
44 | this.endValue.match(otherControlVariable.endValue) &&
45 | equalUpdaterLists(this.variableUpdaters, otherControlVariable.variableUpdaters);
46 | }
47 |
48 | private static boolean equalUpdaterLists(List updaters1, List updaters2)
49 | {
50 | if (updaters1.size() != updaters2.size())
51 | {
52 | return false;
53 | }
54 |
55 | // updaters must be in the same order and each pair must have the same update value
56 | for (int i = 0; i < updaters1.size(); i++)
57 | {
58 | VariableUpdater currentUpdater1 = updaters1.get(i);
59 | VariableUpdater currentUpdater2 = updaters2.get(i);
60 |
61 | if (currentUpdater1 != null && currentUpdater2 != null && !currentUpdater1.match(currentUpdater2))
62 | {
63 | return false;
64 | }
65 | }
66 | return true;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/loop/AbstractLoop.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.loop;
2 |
3 | import java.util.List;
4 |
5 | import org.eclipse.jdt.core.dom.ASTNode;
6 | import org.eclipse.jdt.core.dom.DoStatement;
7 | import org.eclipse.jdt.core.dom.EnhancedForStatement;
8 | import org.eclipse.jdt.core.dom.Expression;
9 | import org.eclipse.jdt.core.dom.ForStatement;
10 | import org.eclipse.jdt.core.dom.Statement;
11 | import org.eclipse.jdt.core.dom.WhileStatement;
12 |
13 | public abstract class AbstractLoop
14 | {
15 | private Statement loopStatement;
16 | protected Expression condition;
17 |
18 | public AbstractLoop(Statement loopStatement)
19 | {
20 | this.loopStatement = loopStatement;
21 | }
22 |
23 | public Statement getLoopStatement()
24 | {
25 | return loopStatement;
26 | }
27 |
28 | public Statement getLoopBody()
29 | {
30 | if (loopStatement instanceof WhileStatement)
31 | {
32 | return ((WhileStatement)loopStatement).getBody();
33 | }
34 | else if (loopStatement instanceof ForStatement)
35 | {
36 | return ((ForStatement)loopStatement).getBody();
37 | }
38 | else if (loopStatement instanceof DoStatement)
39 | {
40 | return ((DoStatement)loopStatement).getBody();
41 | }
42 | else if (loopStatement instanceof EnhancedForStatement)
43 | {
44 | return ((EnhancedForStatement)loopStatement).getBody();
45 | }
46 | return null;
47 | }
48 |
49 | public boolean match(AbstractLoop otherLoop, ConditionalLoopASTNodeMatcher matcher)
50 | {
51 | if (otherLoop instanceof ConditionalLoop)
52 | {
53 | return this.match((ConditionalLoop)otherLoop, matcher);
54 | }
55 | if (otherLoop instanceof EnhancedForLoop)
56 | {
57 | return this.match((EnhancedForLoop)otherLoop, matcher);
58 | }
59 | return false;
60 | }
61 |
62 | public abstract boolean match(ConditionalLoop otherLoop, ConditionalLoopASTNodeMatcher matcher);
63 | public abstract boolean match(EnhancedForLoop otherLoop, ConditionalLoopASTNodeMatcher matcher);
64 | public abstract List getAdditionalFragments();
65 | }
66 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/loop/EarliestStartPositionComparator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.loop;
2 |
3 | import java.util.Comparator;
4 |
5 | import org.eclipse.jdt.core.dom.ASTNode;
6 |
7 | public class EarliestStartPositionComparator implements Comparator
8 | {
9 | public int compare(ASTNode node1, ASTNode node2)
10 | {
11 | return Integer.compare(node1.getStartPosition(), node2.getStartPosition());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/loop/VariableUpdater.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.loop;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 |
5 | public class VariableUpdater
6 | {
7 | private Expression updater;
8 | private Integer updateValue;
9 |
10 | public VariableUpdater(Expression updater)
11 | {
12 | this.updater = updater;
13 | this.updateValue = AbstractLoopUtilities.getUpdateValue(updater);
14 | }
15 |
16 | public VariableUpdater(Integer updateValue)
17 | {
18 | this.updater = null;
19 | this.updateValue = updateValue;
20 | }
21 |
22 | public Expression getUpdater()
23 | {
24 | return updater;
25 | }
26 |
27 | public Integer getUpdateValue()
28 | {
29 | return updateValue;
30 | }
31 |
32 | public boolean match(VariableUpdater otherUpdater)
33 | {
34 | return this.updateValue == otherUpdater.updateValue;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/decomposition/matching/loop/VariableValue.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.decomposition.matching.loop;
2 |
3 | public class VariableValue
4 | {
5 | public enum ValueType
6 | {
7 | INTEGER,
8 | VARIABLE,
9 | DATA_STRUCTURE_SIZE
10 | }
11 |
12 | private ValueType type;
13 | private Integer value;
14 |
15 | public VariableValue()
16 | {
17 | this.type = ValueType.VARIABLE;
18 | this.value = null;
19 | }
20 |
21 | public VariableValue(Integer value)
22 | {
23 | this.type = ValueType.INTEGER;
24 | this.value = value;
25 | }
26 |
27 | public VariableValue(ValueType type)
28 | {
29 | this.type = type;
30 | this.value = null;
31 | }
32 |
33 | public ValueType getType()
34 | {
35 | return type;
36 | }
37 |
38 | public void setType(ValueType type)
39 | {
40 | this.type = type;
41 | }
42 |
43 | public Integer getValue()
44 | {
45 | return value;
46 | }
47 |
48 | public void setValue(Integer value)
49 | {
50 | this.value = value;
51 | }
52 |
53 | public boolean match(VariableValue otherVariableValue)
54 | {
55 | return this.type == otherVariableValue.type && this.value == otherVariableValue.value;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/delegation/DelegationDetection.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.delegation;
2 |
3 | import gr.uom.java.ast.ClassObject;
4 | import gr.uom.java.ast.MethodObject;
5 | import gr.uom.java.ast.SystemObject;
6 |
7 | import java.util.List;
8 | import java.util.ArrayList;
9 | import java.util.ListIterator;
10 |
11 | public class DelegationDetection {
12 | private List delegationPathList;
13 |
14 | public DelegationDetection(SystemObject systemObject) {
15 | delegationPathList = new ArrayList();
16 | ListIterator classIt = systemObject.getClassListIterator();
17 | while(classIt.hasNext()) {
18 | ClassObject classObject = classIt.next();
19 | ListIterator methodIt = classObject.getMethodIterator();
20 | while(methodIt.hasNext()) {
21 | MethodObject methodObject = methodIt.next();
22 | DelegationTree tree = new DelegationTree(systemObject,methodObject);
23 | if(tree.getDepth() >= 1) {
24 | delegationPathList.addAll(tree.getDelegationPathList());
25 | }
26 | }
27 | }
28 | }
29 |
30 | public List getAllDelegationPaths() {
31 | return this.delegationPathList;
32 | }
33 |
34 | //size must be >= 2
35 | public List getDelegationPathsOfSize(int size) {
36 | List depthDelegationPathList = new ArrayList();
37 | for(DelegationPath path : delegationPathList) {
38 | if(path.size() == size)
39 | depthDelegationPathList.add(path);
40 | }
41 | return depthDelegationPathList;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/delegation/DelegationPath.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.delegation;
2 |
3 | import gr.uom.java.ast.MethodObject;
4 |
5 | import java.util.List;
6 | import java.util.ArrayList;
7 | import java.util.ListIterator;
8 |
9 | public class DelegationPath {
10 | private List path;
11 |
12 | public DelegationPath() {
13 | path = new ArrayList();
14 | }
15 |
16 | public void addMethodInvocation(MethodObject mio) {
17 | path.add(mio);
18 | }
19 |
20 | public int size() {
21 | return path.size();
22 | }
23 |
24 | public ListIterator getPathIterator() {
25 | return path.listIterator();
26 | }
27 |
28 | public String toString() {
29 | StringBuilder sb = new StringBuilder();
30 | for(int i=0; i");
32 | }
33 | sb.append(path.get(path.size()-1));
34 | return sb.toString();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/ExpressionInstanceChecker.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 |
5 | public interface ExpressionInstanceChecker {
6 | public boolean instanceOf(Expression expression);
7 | }
8 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfArrayAccess.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ArrayAccess;
4 | import org.eclipse.jdt.core.dom.Expression;
5 |
6 | public class InstanceOfArrayAccess implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof ArrayAccess)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfArrayCreation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ArrayCreation;
4 | import org.eclipse.jdt.core.dom.Expression;
5 |
6 | public class InstanceOfArrayCreation implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof ArrayCreation)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfAssignment.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Assignment;
4 | import org.eclipse.jdt.core.dom.Expression;
5 |
6 | public class InstanceOfAssignment implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof Assignment)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfBranchingStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.BreakStatement;
4 | import org.eclipse.jdt.core.dom.ContinueStatement;
5 | import org.eclipse.jdt.core.dom.ReturnStatement;
6 | import org.eclipse.jdt.core.dom.Statement;
7 |
8 | public class InstanceOfBranchingStatement implements StatementInstanceChecker {
9 |
10 | public boolean instanceOf(Statement statement) {
11 | if(statement instanceof BreakStatement || statement instanceof ContinueStatement || statement instanceof ReturnStatement)
12 | return true;
13 | else
14 | return false;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfBreakStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.BreakStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfBreakStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof BreakStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfCastExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.CastExpression;
4 | import org.eclipse.jdt.core.dom.Expression;
5 |
6 | public class InstanceOfCastExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof CastExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfClassInstanceCreation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ClassInstanceCreation;
4 | import org.eclipse.jdt.core.dom.Expression;
5 |
6 | public class InstanceOfClassInstanceCreation implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof ClassInstanceCreation)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfConditionalExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ConditionalExpression;
4 | import org.eclipse.jdt.core.dom.Expression;
5 |
6 | public class InstanceOfConditionalExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof ConditionalExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfConstructorInvocation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ConstructorInvocation;
4 | import org.eclipse.jdt.core.dom.Statement;
5 | import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
6 |
7 | public class InstanceOfConstructorInvocation implements StatementInstanceChecker {
8 |
9 | public boolean instanceOf(Statement statement) {
10 | if(statement instanceof ConstructorInvocation || statement instanceof SuperConstructorInvocation)
11 | return true;
12 | else
13 | return false;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfContinueStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ContinueStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfContinueStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof ContinueStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfDoStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.DoStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfDoStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof DoStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfEnhancedForStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.EnhancedForStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfEnhancedForStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof EnhancedForStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 |
5 | public class InstanceOfExpression implements ExpressionInstanceChecker {
6 |
7 | public boolean instanceOf(Expression expression) {
8 | return true;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfFieldAccess.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.FieldAccess;
5 |
6 | public class InstanceOfFieldAccess implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof FieldAccess)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfForStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ForStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfForStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof ForStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfIfStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.IfStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfIfStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof IfStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfInfixExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.InfixExpression;
5 |
6 | public class InstanceOfInfixExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof InfixExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfInstanceofExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.InstanceofExpression;
5 |
6 | public class InstanceOfInstanceofExpression implements
7 | ExpressionInstanceChecker {
8 |
9 | public boolean instanceOf(Expression expression) {
10 | if(expression instanceof InstanceofExpression)
11 | return true;
12 | else
13 | return false;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfLiteral.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.BooleanLiteral;
4 | import org.eclipse.jdt.core.dom.CharacterLiteral;
5 | import org.eclipse.jdt.core.dom.Expression;
6 | import org.eclipse.jdt.core.dom.NullLiteral;
7 | import org.eclipse.jdt.core.dom.NumberLiteral;
8 | import org.eclipse.jdt.core.dom.StringLiteral;
9 | import org.eclipse.jdt.core.dom.TypeLiteral;
10 |
11 | public class InstanceOfLiteral implements ExpressionInstanceChecker {
12 |
13 | public boolean instanceOf(Expression expression) {
14 | if(expression instanceof BooleanLiteral || expression instanceof CharacterLiteral || expression instanceof StringLiteral ||
15 | expression instanceof NullLiteral || expression instanceof NumberLiteral || expression instanceof TypeLiteral)
16 | return true;
17 | else
18 | return false;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfMethodInvocation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.MethodInvocation;
5 | import org.eclipse.jdt.core.dom.SuperMethodInvocation;
6 |
7 | public class InstanceOfMethodInvocation implements ExpressionInstanceChecker {
8 |
9 | public boolean instanceOf(Expression expression) {
10 | if(expression instanceof MethodInvocation || expression instanceof SuperMethodInvocation)
11 | return true;
12 | else
13 | return false;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfPostfixExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.PostfixExpression;
5 |
6 | public class InstanceOfPostfixExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof PostfixExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfPrefixExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.PrefixExpression;
5 |
6 | public class InstanceOfPrefixExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof PrefixExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfReturnStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.ReturnStatement;
4 | import org.eclipse.jdt.core.dom.Statement;
5 |
6 | public class InstanceOfReturnStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof ReturnStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfSimpleName.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.SimpleName;
5 |
6 | public class InstanceOfSimpleName implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof SimpleName)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfSuperFieldAccess.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.SuperFieldAccess;
5 |
6 | public class InstanceOfSuperFieldAccess implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof SuperFieldAccess)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfSuperMethodInvocation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.SuperMethodInvocation;
5 |
6 | public class InstanceOfSuperMethodInvocation implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof SuperMethodInvocation)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfSwitchStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 | import org.eclipse.jdt.core.dom.SwitchStatement;
5 |
6 | public class InstanceOfSwitchStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof SwitchStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfThisExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.ThisExpression;
5 |
6 | public class InstanceOfThisExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof ThisExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfTryStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 | import org.eclipse.jdt.core.dom.TryStatement;
5 |
6 | public class InstanceOfTryStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof TryStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfTypeDeclarationStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 | import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
5 |
6 | public class InstanceOfTypeDeclarationStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof TypeDeclarationStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfTypeLiteral.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.TypeLiteral;
5 |
6 | public class InstanceOfTypeLiteral implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof TypeLiteral)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfVariableDeclarationExpression.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Expression;
4 | import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
5 |
6 | public class InstanceOfVariableDeclarationExpression implements ExpressionInstanceChecker {
7 |
8 | public boolean instanceOf(Expression expression) {
9 | if(expression instanceof VariableDeclarationExpression)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfVariableDeclarationStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 | import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
5 |
6 | public class InstanceOfVariableDeclarationStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof VariableDeclarationStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfVariableModifier.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Assignment;
4 | import org.eclipse.jdt.core.dom.Expression;
5 | import org.eclipse.jdt.core.dom.MethodInvocation;
6 | import org.eclipse.jdt.core.dom.PostfixExpression;
7 | import org.eclipse.jdt.core.dom.PrefixExpression;
8 |
9 | public class InstanceOfVariableModifier implements ExpressionInstanceChecker {
10 |
11 | public boolean instanceOf(Expression expression) {
12 | if(expression instanceof Assignment || expression instanceof PrefixExpression || expression instanceof PostfixExpression || expression instanceof MethodInvocation)
13 | return true;
14 | else
15 | return false;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/InstanceOfWhileStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 | import org.eclipse.jdt.core.dom.WhileStatement;
5 |
6 | public class InstanceOfWhileStatement implements StatementInstanceChecker {
7 |
8 | public boolean instanceOf(Statement statement) {
9 | if(statement instanceof WhileStatement)
10 | return true;
11 | else
12 | return false;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/StatementInstanceChecker.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import org.eclipse.jdt.core.dom.Statement;
4 |
5 | public interface StatementInstanceChecker {
6 | public boolean instanceOf(Statement statement);
7 | }
8 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/SuperMethodInvocationVisitor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.eclipse.jdt.core.dom.ASTVisitor;
7 | import org.eclipse.jdt.core.dom.SuperMethodInvocation;
8 |
9 | public class SuperMethodInvocationVisitor extends ASTVisitor {
10 | private List superMethodInvocations = new ArrayList();
11 |
12 | public boolean visit(SuperMethodInvocation node) {
13 | superMethodInvocations.add(node);
14 | return super.visit(node);
15 | }
16 |
17 | public List getSuperMethodInvocations() {
18 | return superMethodInvocations;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/ThrownExceptionVisitor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import java.util.LinkedHashSet;
4 | import java.util.Set;
5 |
6 | import org.eclipse.jdt.core.dom.ASTVisitor;
7 | import org.eclipse.jdt.core.dom.ClassInstanceCreation;
8 | import org.eclipse.jdt.core.dom.Expression;
9 | import org.eclipse.jdt.core.dom.IMethodBinding;
10 | import org.eclipse.jdt.core.dom.ITypeBinding;
11 | import org.eclipse.jdt.core.dom.MethodInvocation;
12 | import org.eclipse.jdt.core.dom.SuperMethodInvocation;
13 | import org.eclipse.jdt.core.dom.ThrowStatement;
14 |
15 | public class ThrownExceptionVisitor extends ASTVisitor {
16 | private Set typeBindings = new LinkedHashSet();
17 |
18 | public boolean visit(MethodInvocation node) {
19 | IMethodBinding methodBinding = node.resolveMethodBinding();
20 | for(ITypeBinding exceptionType : methodBinding.getExceptionTypes()) {
21 | typeBindings.add(exceptionType);
22 | }
23 | return super.visit(node);
24 | }
25 |
26 | public boolean visit(SuperMethodInvocation node) {
27 | IMethodBinding methodBinding = node.resolveMethodBinding();
28 | for(ITypeBinding exceptionType : methodBinding.getExceptionTypes()) {
29 | typeBindings.add(exceptionType);
30 | }
31 | return super.visit(node);
32 | }
33 |
34 | public boolean visit(ClassInstanceCreation node) {
35 | IMethodBinding methodBinding = node.resolveConstructorBinding();
36 | for(ITypeBinding exceptionType : methodBinding.getExceptionTypes()) {
37 | typeBindings.add(exceptionType);
38 | }
39 | return super.visit(node);
40 | }
41 |
42 | public boolean visit(ThrowStatement node) {
43 | Expression expression = node.getExpression();
44 | typeBindings.add(expression.resolveTypeBinding());
45 | return super.visit(node);
46 | }
47 |
48 | public Set getTypeBindings() {
49 | return typeBindings;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/TypeVisitor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import org.eclipse.jdt.core.dom.ASTVisitor;
9 | import org.eclipse.jdt.core.dom.IBinding;
10 | import org.eclipse.jdt.core.dom.ITypeBinding;
11 | import org.eclipse.jdt.core.dom.SimpleName;
12 | import org.eclipse.jdt.core.dom.SimpleType;
13 | import org.eclipse.jdt.core.dom.Type;
14 |
15 | public class TypeVisitor extends ASTVisitor {
16 | private Set typeBindings = new LinkedHashSet();
17 | private List types = new ArrayList();
18 |
19 | public boolean visit(SimpleType node) {
20 | ITypeBinding typeBinding = node.resolveBinding();
21 | if(typeBinding != null)
22 | typeBindings.add(typeBinding);
23 | types.add(node);
24 | return super.visit(node);
25 | }
26 |
27 | public boolean visit(SimpleName node) {
28 | IBinding binding = node.resolveBinding();
29 | if(binding != null && binding.getKind() == IBinding.TYPE) {
30 | ITypeBinding typeBinding = (ITypeBinding)binding;
31 | typeBindings.add(typeBinding);
32 | }
33 | return super.visit(node);
34 | }
35 |
36 | public Set getTypeBindings() {
37 | return typeBindings;
38 | }
39 |
40 | public List getTypes() {
41 | return types;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/AdjacencyList.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | import java.util.LinkedHashSet;
4 | import java.util.Map;
5 | import java.util.HashMap;
6 | import java.util.ArrayList;
7 | import java.util.Set;
8 | import java.util.Collection;
9 |
10 | public class AdjacencyList {
11 |
12 | private Map> adjacencies = new HashMap>();
13 |
14 | public void addEdge(Node source, Node target, int weight){
15 | LinkedHashSet list;
16 | if(!adjacencies.containsKey(source)){
17 | list = new LinkedHashSet();
18 | adjacencies.put(source, list);
19 | }else{
20 | list = adjacencies.get(source);
21 | }
22 | list.add(new Edge(source, target, weight));
23 | }
24 |
25 | public LinkedHashSet getAdjacent(Node source){
26 | if(adjacencies.containsKey(source))
27 | return adjacencies.get(source);
28 | else
29 | return new LinkedHashSet();
30 | }
31 |
32 | public void reverseEdge(Edge e){
33 | adjacencies.get(e.from).remove(e);
34 | addEdge(e.to, e.from, e.weight);
35 | }
36 |
37 | public void reverseGraph(){
38 | adjacencies = getReversedList().adjacencies;
39 | }
40 |
41 | public AdjacencyList getReversedList(){
42 | AdjacencyList newlist = new AdjacencyList();
43 | for(LinkedHashSet edges : adjacencies.values()){
44 | for(Edge e : edges){
45 | newlist.addEdge(e.to, e.from, e.weight);
46 | }
47 | }
48 | return newlist;
49 | }
50 |
51 | public Set getSourceNodeSet(){
52 | return adjacencies.keySet();
53 | }
54 |
55 | public Collection getAllEdges(){
56 | ArrayList edges = new ArrayList();
57 | for(LinkedHashSet e : adjacencies.values()){
58 | edges.addAll(e);
59 | }
60 | return edges;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/Cluster.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | import gr.uom.java.distance.Entity;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class Cluster {
8 |
9 | private ArrayList entities;
10 | private int hashCode;
11 |
12 | public Cluster() {
13 | entities = new ArrayList();
14 | }
15 |
16 | public Cluster(ArrayList entities) {
17 | this.entities = new ArrayList(entities);
18 | }
19 |
20 | public void addEntity(Entity entity) {
21 | if (!entities.contains(entity)) {
22 | entities.add(entity);
23 | }
24 | }
25 |
26 | public ArrayList getEntities() {
27 | return entities;
28 | }
29 |
30 | public void addEntities(ArrayList entities) {
31 | if (!this.entities.containsAll(entities)) {
32 | this.entities.addAll(entities);
33 | }
34 | }
35 |
36 | public boolean equals(Object o) {
37 | Cluster c = (Cluster)o;
38 | return this.entities.equals(c.entities);
39 | }
40 |
41 | public int hashCode() {
42 | if(hashCode == 0) {
43 | int result = 17;
44 | for(Entity entity : entities) {
45 | result = 37*result + entity.hashCode();
46 | }
47 | hashCode = result;
48 | }
49 | return hashCode;
50 | }
51 |
52 | public String toString() {
53 | String s = "{";
54 |
55 | for(Entity entity : entities) {
56 | s+=entity+", ";
57 | }
58 | return s+="}";
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/Clustering.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | import gr.uom.java.distance.Entity;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashSet;
7 |
8 | public abstract class Clustering {
9 |
10 | protected ArrayList> distanceList;
11 | protected double[][] distanceMatrix;
12 |
13 | public static Clustering getInstance(int type, double[][] distanceMatrix) {
14 | switch(type) {
15 | case 0:
16 | return new Hierarchical(distanceMatrix);
17 | default:
18 | return null;
19 | }
20 | }
21 |
22 | public abstract HashSet clustering(ArrayList entities);
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/Edge.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | public class Edge implements Comparable {
4 |
5 | protected final Node from, to;
6 | protected final int weight;
7 | private volatile int hashCode = 0;
8 |
9 | public Edge(final Node argFrom, final Node argTo, final int argWeight){
10 | from = argFrom;
11 | to = argTo;
12 | weight = argWeight;
13 | }
14 |
15 | public Node getSource() {
16 | return from;
17 | }
18 |
19 | public Node getTarget() {
20 | return to;
21 | }
22 |
23 | public boolean equals(Object o) {
24 | if(this == o)
25 | return true;
26 |
27 | if(o instanceof Edge) {
28 | Edge edge = (Edge)o;
29 | return this.from.equals(edge.from) && this.to.equals(edge.to);
30 | }
31 | return false;
32 | }
33 |
34 | public int hashCode() {
35 | if(hashCode == 0) {
36 | int result = 17;
37 | result = 37*result + from.hashCode();
38 | result = 37*result + to.hashCode();
39 | hashCode = result;
40 | }
41 | return hashCode;
42 | }
43 |
44 | public String toString() {
45 | return from + " -> " + to;
46 | }
47 |
48 | public int compareTo(final Edge argEdge){
49 | return weight - argEdge.weight;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/LevenshteinDistance.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | public class LevenshteinDistance {
4 | private static int minimum(int a, int b, int c) {
5 | return Math.min(Math.min(a, b), c);
6 | }
7 |
8 | public static int computeLevenshteinDistance(CharSequence str1,
9 | CharSequence str2) {
10 | int[][] distance = new int[str1.length() + 1][str2.length() + 1];
11 |
12 | for (int i = 0; i <= str1.length(); i++)
13 | distance[i][0] = i;
14 | for (int j = 1; j <= str2.length(); j++)
15 | distance[0][j] = j;
16 |
17 | for (int i = 1; i <= str1.length(); i++)
18 | for (int j = 1; j <= str2.length(); j++)
19 | distance[i][j] = minimum(
20 | distance[i - 1][j] + 1,
21 | distance[i][j - 1] + 1,
22 | distance[i - 1][j - 1]
23 | + ((str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0
24 | : 1));
25 | return distance[str1.length()][str2.length()];
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/Node.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | public class Node implements Comparable {
4 |
5 | protected final String name;
6 | protected boolean visited = false; // used for Kosaraju's algorithm and Edmonds's algorithm
7 | protected int lowlink = -1; // used for Tarjan's algorithm
8 | protected int index = -1; // used for Tarjan's algorithm
9 | private volatile int hashCode = 0;
10 |
11 | public Node(final String argName) {
12 | name = argName;
13 | }
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public boolean equals(Object o) {
20 | if(this == o)
21 | return true;
22 |
23 | if(o instanceof Node) {
24 | Node node = (Node)o;
25 | return this.name.equals(node.name);
26 | }
27 | return false;
28 | }
29 |
30 | public int hashCode() {
31 | if(hashCode == 0) {
32 | int result = 17;
33 | result = 37*result + name.hashCode();
34 | hashCode = result;
35 | }
36 | return hashCode;
37 | }
38 |
39 | public String toString() {
40 | return name;
41 | }
42 |
43 | public int compareTo(final Node argNode) {
44 | return argNode.equals(this) ? 0 : -1;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/util/math/TarjanAlgorithm.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.util.math;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashSet;
5 |
6 | public class TarjanAlgorithm {
7 | private int index = 0;
8 | private ArrayList stack = new ArrayList();
9 | private AdjacencyList list;
10 | private LinkedHashSet> SCC = new LinkedHashSet>();
11 |
12 | public TarjanAlgorithm(AdjacencyList list) {
13 | this.list = list;
14 | for(Node v : list.getSourceNodeSet())
15 | if(v.index == -1)
16 | tarjan(v);
17 | }
18 |
19 | private void tarjan(Node v){
20 | v.index = index;
21 | v.lowlink = index;
22 | index++;
23 | stack.add(0, v);
24 | for(Edge e : list.getAdjacent(v)){
25 | Node n = e.to;
26 | if(n.index == -1){
27 | tarjan(n);
28 | v.lowlink = Math.min(v.lowlink, n.lowlink);
29 | }else if(stack.contains(n)){
30 | v.lowlink = Math.min(v.lowlink, n.index);
31 | }
32 | }
33 | if(v.lowlink == v.index){
34 | Node n;
35 | LinkedHashSet component = new LinkedHashSet();
36 | do{
37 | n = stack.remove(0);
38 | component.add(n);
39 | }while(n != v);
40 | SCC.add(component);
41 | }
42 | }
43 |
44 | public boolean belongToTheSameStronglyConnectedComponent(String s1, String s2) {
45 | Node n1 = new Node(s1);
46 | Node n2 = new Node(s2);
47 | for(LinkedHashSet component : SCC) {
48 | if(component.contains(n1) && component.contains(n2))
49 | return true;
50 | }
51 | return false;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/CompartmentFigure.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 |
4 | import org.eclipse.draw2d.*;
5 |
6 |
7 |
8 | public class CompartmentFigure extends Figure {
9 | public CompartmentFigure() {
10 | //setFont( Display.getCurrent().getSystemFont() );
11 |
12 | ToolbarLayout layout = new ToolbarLayout();
13 | layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
14 | layout.setStretchMinorAxis(true);
15 | layout.setSpacing(5);
16 | setLayoutManager(layout);
17 |
18 | setBorder(new CompoundBorder (new MarginBorder(3,3,3,3), new CompartmentFigureBorder()));
19 |
20 | setOpaque(true);
21 | }
22 |
23 | //adds EntityFigure with different color and border
24 | public void addFigure(Figure figure){
25 | figure.setBackgroundColor(DecorationConstants.entityColor);
26 | figure.setBorder(new CompoundBorder( new LineBorder(1), new MarginBorder(3,3,3,3)));
27 | add(figure);
28 | }
29 |
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/CompartmentFigureBorder.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.AbstractBorder;
4 | import org.eclipse.draw2d.Graphics;
5 | import org.eclipse.draw2d.IFigure;
6 | import org.eclipse.draw2d.geometry.Insets;
7 |
8 | public class CompartmentFigureBorder extends AbstractBorder{
9 | public Insets getInsets(IFigure figure) {
10 | return new Insets(5,5,5,5);
11 | }
12 | public void paint(IFigure figure, Graphics graphics, Insets insets) {
13 | graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(),
14 | tempRect.getTopRight());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/ConnectionType.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | public enum ConnectionType {
4 |
5 | READ_FIELD_SOURCE, WRITE_FIELD_SOURCE, READ_FIELD_TARGET, WRITE_FIELD_TARGET, METHOD_CALL_SOURCE, METHOD_CALL_TARGET;
6 | }
7 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/DecorationConstants.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.jdt.ui.ISharedImages;
4 | import org.eclipse.jdt.ui.JavaUI;
5 | import org.eclipse.swt.SWT;
6 | import org.eclipse.swt.graphics.Color;
7 | import org.eclipse.swt.graphics.Font;
8 | import org.eclipse.swt.graphics.Image;
9 |
10 | public class DecorationConstants {
11 |
12 | public static final Font normalFont = new Font(null, "Arial", 10, SWT.BOLD);
13 | public static final Font highlightFont = new Font(null, "Arial", 14 , SWT.BOLD);
14 | public static final Color entityColor = new Color(null,255,255,240);
15 | public static final Image FIELD = JavaUI.getSharedImages().getImage(ISharedImages.IMG_FIELD_PRIVATE);
16 | public static final Image METHOD = JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PUBLIC);
17 | public static final Image PACKAGE = JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKAGE);
18 | public static final Color methodToMethodColor = new Color(null,60,179,113);
19 | public static final int NO_OCCURENCES = -1;
20 | public static final Color classColor = new Color(null,255,255,206);
21 | public static final Image CLASS = JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS);
22 | public static final Font classFont = new Font(null, "Arial", 12, SWT.BOLD);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/FeatureEnviedMethodInformationControlCreator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.jface.action.ToolBarManager;
4 | import org.eclipse.jface.text.IInformationControl;
5 | import org.eclipse.swt.widgets.Shell;
6 |
7 | public class FeatureEnviedMethodInformationControlCreator implements
8 | ICustomInformationControlCreator {
9 |
10 | public IInformationControl createInformationControl(Shell parent) {
11 | //return new InformationControl(parent, true);
12 | ToolBarManager manager = new ToolBarManager();
13 | return new FeatureEnviedMethodInformationControl(parent, manager);
14 | }
15 |
16 | public boolean isSupported(Object info) {
17 | return PMClassFigure.class.isInstance(info);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/GodClassInformationControlCreator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.jface.action.ToolBarManager;
4 | import org.eclipse.jface.text.IInformationControl;
5 | import org.eclipse.swt.widgets.Shell;
6 |
7 | public class GodClassInformationControlCreator implements
8 | ICustomInformationControlCreator {
9 |
10 | public IInformationControl createInformationControl(Shell parent) {
11 | ToolBarManager manager = new ToolBarManager();
12 | return new GodClassInformationControl(parent, manager);
13 | }
14 |
15 | public boolean isSupported(Object info) {
16 | return PMClassFigure.class.isInstance(info);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/ICustomInformationControlCreator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.jface.text.IInformationControlCreator;
4 |
5 | /**
6 | * {@link IInformationControlCreator} for custom information inputs.
7 | */
8 | public interface ICustomInformationControlCreator extends IInformationControlCreator {
9 |
10 | /**
11 | * Returns whether the given information input is supported by this control creator or not.
12 | * @param info the information input
13 | * @return true
if the given information input is supported, false
otherwise
14 | */
15 | boolean isSupported(Object info);
16 | }
17 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/IInformationProvider.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.swt.graphics.Point;
4 | import org.eclipse.swt.graphics.Rectangle;
5 |
6 | /**
7 | * Information provider interface to get information about elements under the mouse cursor.
8 | * This interface is analog to {@link org.eclipse.jface.text.information.IInformationProvider} in
9 | * {@link org.eclipse.jface.text.information.InformationPresenter}.
10 | */
11 | public interface IInformationProvider {
12 |
13 | /**
14 | * Returns information about the element at the specified location.
15 | * The information returned is used to display an appropriate tooltip.
16 | * @param location the location of the element (the coordinate is in the receiver's coordinate system)
17 | * @return information about the element, or null
if none is available
18 | */
19 | PMClassFigure getInformation(Point location);
20 |
21 | /**
22 | * Returns the area of the element at the specified location.
23 | * The area returned is used to place an appropriate tooltip.
24 | * @param location the location of the element (the coordinate is in the receiver's coordinate system)
25 | * @return the area of the element, or null
if none is available
26 | */
27 | Rectangle getArea(Point location);
28 | }
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/LeftAnchor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.AbstractConnectionAnchor;
4 | import org.eclipse.draw2d.Figure;
5 | import org.eclipse.draw2d.geometry.Point;
6 |
7 | public class LeftAnchor extends AbstractConnectionAnchor {
8 |
9 | public LeftAnchor(Figure owner){
10 | super(owner);
11 | }
12 |
13 |
14 | public Point getLocation(Point reference) {
15 | Point point = getOwner().getBounds().getLeft();
16 | getOwner().translateToAbsolute(point);
17 | return point;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/MethodClassSection.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.CompoundBorder;
4 | import org.eclipse.draw2d.Figure;
5 | import org.eclipse.draw2d.LineBorder;
6 | import org.eclipse.draw2d.MarginBorder;
7 | import org.eclipse.draw2d.ToolbarLayout;
8 |
9 | public class MethodClassSection extends Figure {
10 |
11 | private int numOfMethods=0;
12 |
13 | public MethodClassSection(){
14 | //setFont( Display.getCurrent().getSystemFont() );
15 | ToolbarLayout layout = new ToolbarLayout();
16 | layout.setSpacing(5);
17 | layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
18 | layout.setStretchMinorAxis(true);
19 | setLayoutManager(layout);
20 |
21 | }
22 |
23 | public int getNumOfMethods() {
24 | return numOfMethods;
25 | }
26 |
27 | public void addFigure(Figure figure){
28 | this.add(figure);
29 | figure.setBackgroundColor(DecorationConstants.entityColor);
30 | figure.setBorder(new CompoundBorder( new LineBorder(1), new MarginBorder(3,3,3,3)));
31 | numOfMethods++;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/MyContentProposalProvider.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.eclipse.jface.fieldassist.ContentProposal;
6 | import org.eclipse.jface.fieldassist.IContentProposal;
7 | import org.eclipse.jface.fieldassist.IContentProposalProvider;
8 |
9 | public class MyContentProposalProvider implements IContentProposalProvider {
10 |
11 | private String[] proposals;
12 |
13 | public MyContentProposalProvider(String[] classNames){
14 | super();
15 | this.proposals= classNames;
16 | }
17 |
18 | public IContentProposal[] getProposals(String contents, int position) {
19 |
20 | ArrayList list = new ArrayList();
21 | for (int i = 0; i < proposals.length; i++) {
22 | //if (proposals[i].length() >= contents.length() && proposals[i].substring(0, contents.length()).equalsIgnoreCase(contents) ) {
23 | if(proposals[i].toLowerCase().contains(contents.toLowerCase())){
24 | list.add(new ContentProposal(proposals[i]));
25 | }
26 | }
27 | return (IContentProposal[]) list.toArray(new IContentProposal[list.size()]);
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/PackageMapDiagramInformationProvider.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import gr.uom.java.jdeodorant.refactoring.views.CodeSmellPackageExplorer;
4 | import org.eclipse.swt.graphics.Point;
5 | import org.eclipse.swt.graphics.Rectangle;
6 |
7 |
8 | public class PackageMapDiagramInformationProvider implements IInformationProvider {
9 |
10 | private final PackageMapDiagram diagram;
11 |
12 | public PackageMapDiagramInformationProvider(PackageMapDiagram diagram){
13 | this.diagram = diagram;
14 | }
15 |
16 | public PMClassFigure getInformation(Point location) {
17 | PMClassFigure classFigure = diagram.getSelectedClass();
18 | if(classFigure != null){
19 |
20 | return classFigure;
21 | }
22 | return null;
23 | }
24 |
25 | public Rectangle getArea(Point location) {
26 | // TODO Auto-generated method stub
27 | PMClassFigure classFigure = diagram.getSelectedClass();
28 |
29 | if(classFigure != null){
30 | org.eclipse.draw2d.geometry.Rectangle bounds = classFigure.getBounds();
31 | double scaleFactor = CodeSmellPackageExplorer.SCALE_FACTOR;
32 | Rectangle rect;
33 | org.eclipse.draw2d.geometry.Point figureLocation = classFigure.getLocation();
34 | classFigure.translateToAbsolute(figureLocation);
35 |
36 | if(scaleFactor <1)
37 | rect = new Rectangle((int) (figureLocation.x*scaleFactor), (int) (figureLocation.y*scaleFactor), (int) (bounds.width*scaleFactor), (int) (bounds.height*scaleFactor));
38 | else
39 | rect = new Rectangle(figureLocation.x,figureLocation.y, bounds.width, bounds.height);
40 | return rect;
41 | }
42 | return null;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/PackageMapFigure.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.RectangleFigure;
4 |
5 | public abstract class PackageMapFigure extends RectangleFigure implements Comparable {
6 |
7 |
8 | public abstract void draw();
9 |
10 | public abstract int numberOfClasses();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/RightAnchor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.AbstractConnectionAnchor;
4 | import org.eclipse.draw2d.Figure;
5 | import org.eclipse.draw2d.geometry.Point;
6 |
7 | public class RightAnchor extends AbstractConnectionAnchor {
8 |
9 | public RightAnchor(Figure owner){
10 | super(owner);
11 | }
12 |
13 |
14 | public Point getLocation(Point reference) {
15 | Point point = getOwner().getBounds().getRight();
16 | getOwner().translateToAbsolute(point);
17 | return point;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/SearchInputAction.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import java.util.ArrayList;
4 | import org.eclipse.draw2d.ColorConstants;
5 | import org.eclipse.jface.action.Action;
6 | import org.eclipse.jface.window.Window;
7 | import org.eclipse.swt.widgets.Shell;
8 | import org.eclipse.ui.PlatformUI;
9 | import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
10 |
11 | public class SearchInputAction extends Action implements IWorkbenchAction {
12 |
13 | public static final String ID = "gr.uom.java.ast.visualiztion.SearchInputAction";
14 |
15 |
16 |
17 | public void run() {
18 |
19 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
20 | SearchDialog dialog = new SearchDialog(shell);
21 |
22 |
23 | if(dialog.open() == Window.OK){
24 |
25 | String value = dialog.getClassName();
26 |
27 | if(value != null){
28 | ArrayList classFigures = (ArrayList) PackageMapDiagram.allClassFigures;
29 |
30 | for(PMClassFigure figure: classFigures){
31 | figure.setBackgroundColor(figure.getOriginalColor());
32 | //if(figure.getName().toLowerCase().contains(value.toLowerCase())){
33 | if(figure.getName().toLowerCase().equals(value.toLowerCase())){
34 | figure.setBackgroundColor(ColorConstants.blue);
35 | }
36 | }
37 |
38 |
39 | }
40 | }
41 | }
42 |
43 | public void dispose() {
44 | // TODO Auto-generated method stub
45 |
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/SectionCompartment.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.Figure;
4 | import org.eclipse.draw2d.GridData;
5 | import org.eclipse.draw2d.GridLayout;
6 |
7 | public class SectionCompartment extends Figure {
8 | private MethodClassSection sectionOne = new MethodClassSection();
9 | private MethodClassSection sectionTwo= new MethodClassSection();
10 | private MethodClassSection sectionThree= new MethodClassSection();
11 |
12 | public SectionCompartment(int columns) {
13 |
14 | //setFont( Display.getCurrent().getSystemFont() );
15 | GridLayout layout = new GridLayout(columns,true);
16 |
17 | setLayoutManager(layout);
18 | setBorder(new CompartmentFigureBorder());
19 |
20 | this.add(sectionOne, new GridData(GridData.FILL_HORIZONTAL) );
21 |
22 | if( columns == 2 )
23 | this.add(sectionTwo, new GridData(GridData.FILL_HORIZONTAL));
24 | if(columns == 3){
25 | this.add(sectionTwo, new GridData(GridData.FILL_HORIZONTAL));
26 | this.add(sectionThree, new GridData(GridData.FILL_HORIZONTAL));
27 | }
28 | }
29 |
30 | public MethodClassSection getSectionOne() {
31 | return sectionOne;
32 | }
33 |
34 | public MethodClassSection getSectionTwo() {
35 | return sectionTwo;
36 | }
37 |
38 | public MethodClassSection getSectionThree() {
39 | return sectionThree;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/VisualizationData.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | public interface VisualizationData {
4 | public int getDistinctSourceDependencies();
5 | public int getDistinctTargetDependencies();
6 | }
7 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/ZoomAction.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 |
3 | import org.eclipse.draw2d.FreeformViewport;
4 | import org.eclipse.draw2d.ScalableFreeformLayeredPane;
5 | import org.eclipse.draw2d.ScalableLayeredPane;
6 | import org.eclipse.draw2d.geometry.Rectangle;
7 | import org.eclipse.jface.action.Action;
8 | import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
9 |
10 | public class ZoomAction extends Action implements IWorkbenchAction {
11 |
12 | private static final String ID = "gr.uom.java.ast.visualization.ZoomAction";
13 | private double scale;
14 | private ScalableFreeformLayeredPane freeformRoot= null;
15 | private ScalableLayeredPane root= null;
16 | private boolean isFreeform= true;
17 |
18 |
19 | public ZoomAction(ScalableLayeredPane root, double scale){
20 | setId(ID);
21 |
22 | this.scale = scale;
23 | this.root = root;
24 | isFreeform = false;
25 | }
26 | public ZoomAction(ScalableFreeformLayeredPane root, double scale){
27 | setId(ID);
28 |
29 | this.scale = scale;
30 | this.freeformRoot = root;
31 | }
32 |
33 | public void run() {
34 |
35 | if(freeformRoot != null || root!=null){
36 | if(scale!= 0){
37 | if(isFreeform)
38 | this.freeformRoot.setScale(this.scale);
39 | else
40 | this.root.setScale(this.scale);
41 | }
42 | else
43 | scaleToFit();
44 | }
45 |
46 | }
47 |
48 | public void dispose() {
49 |
50 | }
51 |
52 | private void scaleToFit(){
53 | if(isFreeform){
54 | FreeformViewport viewport = (FreeformViewport) freeformRoot.getParent();
55 | Rectangle viewArea = viewport.getClientArea();
56 |
57 | this.freeformRoot.setScale(1);
58 | Rectangle rootArea = freeformRoot.getFreeformExtent().union(0,0);
59 |
60 | double wScale = ((double) viewArea.width)/rootArea.width;
61 | double hScale = ((double) viewArea.height)/rootArea.height;
62 | double newScale = Math.min(wScale, hScale);
63 |
64 | this.freeformRoot.setScale(newScale);
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/gr/uom/java/ast/visualization/ZoomInputAction.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.ast.visualization;
2 | import gr.uom.java.jdeodorant.refactoring.views.ZoomValueValidator;
3 |
4 | import org.eclipse.draw2d.ScalableFreeformLayeredPane;
5 | import org.eclipse.draw2d.ScalableLayeredPane;
6 | import org.eclipse.jface.action.Action;
7 | import org.eclipse.jface.dialogs.InputDialog;
8 | import org.eclipse.jface.window.Window;
9 | import org.eclipse.swt.widgets.Shell;
10 | import org.eclipse.ui.PlatformUI;
11 | import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
12 |
13 | public class ZoomInputAction extends Action implements IWorkbenchAction{
14 |
15 | private static final String ID = "gr.uom.java.ast.visualiztion.ZoomInputAction";
16 | private ScalableFreeformLayeredPane root;
17 | private ScalableLayeredPane root2;
18 | private boolean isFreeform= true;
19 |
20 | public ZoomInputAction(ScalableLayeredPane root){
21 | setId(ID);
22 | this.root2 = root;
23 | isFreeform = false;
24 | }
25 |
26 | public ZoomInputAction(ScalableFreeformLayeredPane root){
27 | setId(ID);
28 | this.root = root;
29 | }
30 |
31 | public void run() {
32 |
33 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
34 | String dialogBoxTitle = "Custom Zoom";
35 | String message = "Enter Zoom Value (in percent): ";
36 | String initialValue = "";
37 |
38 |
39 | InputDialog dialog = new InputDialog(shell, dialogBoxTitle, message, initialValue, new ZoomValueValidator() );
40 | if(dialog.open() == Window.OK){
41 | String value = dialog.getValue();
42 | if(value != null && (root != null || root2!= null)){
43 | if(isFreeform)
44 | this.root.setScale(Double.parseDouble(value)/100);
45 | else
46 | this.root2.setScale(Double.parseDouble(value)/100);
47 | }
48 | }
49 | }
50 |
51 | public void dispose() {}
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/CandidateRefactoring.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 | import java.util.Set;
8 |
9 | import org.eclipse.core.resources.IFile;
10 | import org.eclipse.jdt.core.dom.TypeDeclaration;
11 | import org.eclipse.jface.text.Position;
12 |
13 | public abstract class CandidateRefactoring {
14 | public abstract String getSourceEntity();
15 | public abstract String getSource();
16 | public abstract String getTarget();
17 | public abstract Set getEntitySet();
18 | public abstract TypeDeclaration getSourceClassTypeDeclaration();
19 | public abstract TypeDeclaration getTargetClassTypeDeclaration();
20 | public abstract IFile getSourceIFile();
21 | public abstract IFile getTargetIFile();
22 | public abstract List getPositions();
23 | public abstract int getDistinctSourceDependencies();
24 | public abstract int getDistinctTargetDependencies();
25 |
26 | public String getAnnotationText() {
27 | Map> accessMap = new LinkedHashMap>();
28 | for(String entity : getEntitySet()) {
29 | String[] tokens = entity.split("::");
30 | String classOrigin = tokens[0];
31 | String entityName = tokens[1];
32 | if(accessMap.containsKey(classOrigin)) {
33 | ArrayList list = accessMap.get(classOrigin);
34 | list.add(entityName);
35 | }
36 | else {
37 | ArrayList list = new ArrayList();
38 | list.add(entityName);
39 | accessMap.put(classOrigin, list);
40 | }
41 | }
42 |
43 | StringBuilder sb = new StringBuilder();
44 | Set keySet = accessMap.keySet();
45 | int i = 0;
46 | for(String key : keySet) {
47 | ArrayList entities = accessMap.get(key);
48 | sb.append(key + ": " + entities.size());
49 | if(i < keySet.size()-1)
50 | sb.append(" | ");
51 | i++;
52 | }
53 | return sb.toString();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/ClusterSizeComparator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | import java.util.Comparator;
4 |
5 | public class ClusterSizeComparator implements Comparator {
6 |
7 | public int compare(ExtractClassCandidateRefactoring o1,
8 | ExtractClassCandidateRefactoring o2) {
9 | if(o1.getExtractedEntities().size() > o2.getExtractedEntities().size()) {
10 | return -1;
11 | }
12 | else if(o1.getExtractedEntities().size() < o2.getExtractedEntities().size()) {
13 | return 1;
14 | }
15 | else {
16 | return 0;
17 | }
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/DistanceCalculator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | import java.util.Set;
4 | import java.util.HashSet;
5 |
6 | public class DistanceCalculator {
7 |
8 | public static double getDistance(Set set1, Set set2) {
9 | if(set1.isEmpty() && set2.isEmpty())
10 | return 1.0;
11 | return 1.0 - (double)intersection(set1,set2).size()/(double)union(set1,set2).size();
12 | }
13 |
14 | public static Set union(Set set1, Set set2) {
15 | Set set = new HashSet();
16 | set.addAll(set1);
17 | set.addAll(set2);
18 | return set;
19 | }
20 |
21 | public static Set intersection(Set set1, Set set2) {
22 | Set set = new HashSet();
23 | set.addAll(set1);
24 | set.retainAll(set2);
25 | return set;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/Entity.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | import java.util.Set;
4 |
5 | public abstract class Entity {
6 |
7 | public abstract Set getEntitySet();
8 | public abstract Set getFullEntitySet();
9 | public abstract String getClassOrigin();
10 | }
11 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/ExtractedConcept.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | import gr.uom.java.ast.util.TopicFinder;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashSet;
7 | import java.util.List;
8 | import java.util.Set;
9 | import java.util.TreeSet;
10 |
11 | public class ExtractedConcept implements Comparable {
12 |
13 | private Set conceptClusters;
14 | private Set conceptEntities;
15 | private String sourceClass;
16 | private List topics;
17 |
18 | public ExtractedConcept(Set conceptEntities, String sourceClass) {
19 | this.conceptEntities = conceptEntities;
20 | this.conceptClusters = new HashSet();
21 | this.sourceClass = sourceClass;
22 | this.topics = new ArrayList();
23 | }
24 |
25 | public List getTopics() {
26 | return topics;
27 | }
28 |
29 | public String getSourceClass() {
30 | return sourceClass;
31 | }
32 |
33 | public Set getConceptEntities() {
34 | return conceptEntities;
35 | }
36 |
37 | public Set getConceptClusters() {
38 | return conceptClusters;
39 | }
40 |
41 | public void addConceptCluster(ExtractClassCandidateRefactoring candidate) {
42 | this.conceptClusters.add(candidate);
43 | }
44 |
45 | public void findTopics() {
46 | List codeElements = new ArrayList();
47 | for (Entity entity : this.getConceptEntities()) {
48 | if (entity instanceof MyAttribute) {
49 | MyAttribute attribute = (MyAttribute) entity;
50 | codeElements.add(attribute.getName());
51 | }
52 | else if (entity instanceof MyMethod) {
53 | MyMethod method = (MyMethod) entity;
54 | codeElements.add(method.getMethodName());
55 | }
56 | }
57 | this.topics = TopicFinder.findTopics(codeElements);
58 | }
59 |
60 | public int compareTo(ExtractedConcept other) {
61 | TreeSet thisSet = new TreeSet(this.conceptClusters);
62 | TreeSet otherSet = new TreeSet(other.conceptClusters);
63 | ExtractClassCandidateRefactoring thisFirst = thisSet.first();
64 | ExtractClassCandidateRefactoring otherFirst = otherSet.first();
65 | return thisFirst.compareTo(otherFirst);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/MyAttributeInstruction.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | public class MyAttributeInstruction {
4 |
5 | private String classOrigin;
6 | private String classType;
7 | private String name;
8 | private boolean reference;
9 |
10 | public MyAttributeInstruction(String classOrigin, String classType, String name) {
11 | this.classOrigin = classOrigin;
12 | this.classType = classType;
13 | this.name = name;
14 | this.reference = false;
15 | }
16 |
17 | public boolean isReference() {
18 | return reference;
19 | }
20 |
21 | public void setReference(boolean reference) {
22 | this.reference = reference;
23 | }
24 |
25 | public String getClassOrigin() {
26 | return classOrigin;
27 | }
28 |
29 | public void setClassOrigin(String classOrigin) {
30 | this.classOrigin = classOrigin;
31 | }
32 |
33 | public String getClassType() {
34 | return classType;
35 | }
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public boolean equals(Object o) {
42 | if(this == o) {
43 | return true;
44 | }
45 |
46 | if (o instanceof MyAttributeInstruction) {
47 | MyAttributeInstruction attribute = (MyAttributeInstruction)o;
48 | return this.classOrigin.equals(attribute.classOrigin) && this.classType.equals(attribute.classType) &&
49 | this.name.equals(attribute.name);
50 | }
51 | return false;
52 | }
53 |
54 | public String toString() {
55 | StringBuilder sb = new StringBuilder();
56 | sb.append(classOrigin).append("::");
57 | sb.append(classType).append(" ");
58 | sb.append(name);
59 | return sb.toString();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/gr/uom/java/distance/MyStatement.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.distance;
2 |
3 | import gr.uom.java.ast.decomposition.AbstractStatement;
4 |
5 | public class MyStatement extends MyAbstractStatement {
6 |
7 | public MyStatement(AbstractStatement statement) {
8 | super(statement);
9 | }
10 |
11 | public MyStatement(MyMethodInvocation methodInvocation) {
12 | super(methodInvocation);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/gr/uom/java/history/Evolution.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.history;
2 |
3 | import java.util.Set;
4 | import java.util.Map.Entry;
5 |
6 | public interface Evolution {
7 |
8 | public Set> getSimilarityEntries();
9 |
10 | public Set> getChangeEntries();
11 |
12 | public String getCode(ProjectVersion projectVersion);
13 | }
14 |
--------------------------------------------------------------------------------
/src/gr/uom/java/history/ProjectEvolution.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.history;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Map;
6 | import java.util.Map.Entry;
7 | import java.util.TreeMap;
8 |
9 | import org.eclipse.core.resources.IProject;
10 | import org.eclipse.core.resources.IWorkspaceRoot;
11 | import org.eclipse.core.resources.ResourcesPlugin;
12 | import org.eclipse.core.runtime.CoreException;
13 | import org.eclipse.jdt.core.IJavaProject;
14 | import org.eclipse.jdt.core.JavaCore;
15 |
16 | public class ProjectEvolution {
17 | private Map relevantProjectMap;
18 |
19 | public ProjectEvolution(IJavaProject selectedProject) {
20 | IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
21 | IProject[] projects = root.getProjects();
22 | List javaProjects = new ArrayList();
23 | for(IProject project : projects) {
24 | try {
25 | if(project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
26 | IJavaProject javaProject = JavaCore.create(project);
27 | javaProjects.add(javaProject);
28 | }
29 | } catch (CoreException e) {
30 | e.printStackTrace();
31 | }
32 | }
33 | String selectedProjectName = selectedProject.getElementName();
34 | String projectPrefix = null;
35 | for(int i=0; i();
42 | for(IJavaProject javaProject : javaProjects) {
43 | String javaProjectName = javaProject.getElementName();
44 | if(javaProjectName.startsWith(projectPrefix)) {
45 | String version = javaProjectName.substring(projectPrefix.length(), javaProjectName.length());
46 | ProjectVersion projectVersion = new ProjectVersion(version);
47 | relevantProjectMap.put(projectVersion, javaProject);
48 | }
49 | }
50 | }
51 |
52 | public List> getProjectEntries() {
53 | return new ArrayList>(relevantProjectMap.entrySet());
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/gr/uom/java/history/ProjectVersionPair.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.history;
2 |
3 | public class ProjectVersionPair {
4 | private ProjectVersion fromVersion;
5 | private ProjectVersion toVersion;
6 |
7 | public ProjectVersionPair(ProjectVersion fromVersion, ProjectVersion toVersion) {
8 | this.fromVersion = fromVersion;
9 | this.toVersion = toVersion;
10 | }
11 |
12 | public ProjectVersion getFromVersion() {
13 | return fromVersion;
14 | }
15 |
16 | public ProjectVersion getToVersion() {
17 | return toVersion;
18 | }
19 |
20 | public String toString() {
21 | return fromVersion.toString() + "-" + toVersion.toString();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/preferences/PreferenceConstants.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.preferences;
2 |
3 | /**
4 | * Constant definitions for plug-in preferences
5 | */
6 | public class PreferenceConstants {
7 |
8 | public static final String P_MINIMUM_SLICE_SIZE = "minimumSliceSizePreference";
9 |
10 | public static final String P_MAXIMUM_SLICE_SIZE = "maximumSliceSizePreference";
11 |
12 | public static final String P_MAXIMUM_DUPLICATION = "maximumDuplicationPreference";
13 |
14 | public static final String P_MAXIMUM_RATIO_OF_DUPLICATED_TO_EXTRACTED = "maximumRatioOfDuplicatedToExtractedPreference";
15 |
16 | public static final String P_MINIMUM_METHOD_SIZE = "minimumMethodSizePreference";
17 |
18 | public static final String P_MAXIMUM_CALL_GRAPH_ANALYSIS_DEPTH = "maximumCallGraphAnalysisDepthPreference";
19 |
20 | public static final String P_ENABLE_ALIAS_ANALYSIS = "enableAliasAnalysisPreference";
21 |
22 | public static final String P_PROJECT_COMPILATION_UNIT_CACHE_SIZE = "projectCompilationUnitCacheSize";
23 |
24 | public static final String P_LIBRARY_COMPILATION_UNIT_CACHE_SIZE = "libraryCompilationUnitCacheSize";
25 |
26 | public static final String P_ENABLE_USAGE_REPORTING = "enableUsageReporting";
27 |
28 | public static final String P_ENABLE_SOURCE_CODE_REPORTING = "enableSourceCodeReporting";
29 |
30 | public static final String P_MAXIMUM_NUMBER_OF_SOURCE_CLASS_MEMBERS_ACCESSED_BY_MOVE_METHOD_CANDIDATE = "maximumNumberOfSourceClassMembersAccessedByMoveMethodCandidatePreference";
31 |
32 | public static final String P_MAXIMUM_NUMBER_OF_SOURCE_CLASS_MEMBERS_ACCESSED_BY_EXTRACT_CLASS_CANDIDATE = "maximumNumberOfSourceClassMembersAccessedByExtractClassCandidatePreference";
33 | }
34 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/preferences/PreferenceInitializer.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.preferences;
2 |
3 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
4 | import org.eclipse.jface.preference.IPreferenceStore;
5 |
6 | import gr.uom.java.jdeodorant.refactoring.Activator;
7 |
8 | /**
9 | * Class used to initialize default preference values.
10 | */
11 | public class PreferenceInitializer extends AbstractPreferenceInitializer {
12 |
13 | /*
14 | * (non-Javadoc)
15 | *
16 | * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
17 | */
18 | public void initializeDefaultPreferences() {
19 | IPreferenceStore store = Activator.getDefault().getPreferenceStore();
20 | store.setDefault(PreferenceConstants.P_MINIMUM_SLICE_SIZE, 0);
21 | store.setDefault(PreferenceConstants.P_MAXIMUM_SLICE_SIZE, 0);
22 | store.setDefault(PreferenceConstants.P_MAXIMUM_DUPLICATION, 100);
23 | store.setDefault(PreferenceConstants.P_MAXIMUM_RATIO_OF_DUPLICATED_TO_EXTRACTED, 1.0);
24 | store.setDefault(PreferenceConstants.P_MINIMUM_METHOD_SIZE, 0);
25 | store.setDefault(PreferenceConstants.P_MAXIMUM_CALL_GRAPH_ANALYSIS_DEPTH, 3);
26 | store.setDefault(PreferenceConstants.P_ENABLE_ALIAS_ANALYSIS, true);
27 | store.setDefault(PreferenceConstants.P_PROJECT_COMPILATION_UNIT_CACHE_SIZE, 20);
28 | store.setDefault(PreferenceConstants.P_LIBRARY_COMPILATION_UNIT_CACHE_SIZE, 50);
29 | store.setDefault(PreferenceConstants.P_ENABLE_USAGE_REPORTING, true);
30 | store.setDefault(PreferenceConstants.P_ENABLE_SOURCE_CODE_REPORTING, false);
31 | store.setDefault(PreferenceConstants.P_MAXIMUM_NUMBER_OF_SOURCE_CLASS_MEMBERS_ACCESSED_BY_MOVE_METHOD_CANDIDATE, 2);
32 | store.setDefault(PreferenceConstants.P_MAXIMUM_NUMBER_OF_SOURCE_CLASS_MEMBERS_ACCESSED_BY_EXTRACT_CLASS_CANDIDATE, 2);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/Activator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring;
2 |
3 | import org.eclipse.jface.resource.ImageDescriptor;
4 | import org.eclipse.ui.plugin.AbstractUIPlugin;
5 | import org.osgi.framework.BundleContext;
6 |
7 | /**
8 | * The activator class controls the plug-in life cycle
9 | */
10 | public class Activator extends AbstractUIPlugin {
11 |
12 | // The plug-in ID
13 | public static final String PLUGIN_ID = "gr.uom.java.jdeodorant";
14 |
15 | // The shared instance
16 | private static Activator plugin;
17 |
18 | public static final String RANK_URL = "http://users.encs.concordia.ca/~nikolaos/jdeodorant/rank.php";
19 |
20 | /**
21 | * The constructor
22 | */
23 | public Activator() {
24 | plugin = this;
25 | }
26 |
27 | /*
28 | * (non-Javadoc)
29 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
30 | */
31 | public void start(BundleContext context) throws Exception {
32 | super.start(context);
33 | }
34 |
35 | /*
36 | * (non-Javadoc)
37 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
38 | */
39 | public void stop(BundleContext context) throws Exception {
40 | plugin = null;
41 | super.stop(context);
42 | }
43 |
44 | /**
45 | * Returns the shared instance
46 | *
47 | * @return the shared instance
48 | */
49 | public static Activator getDefault() {
50 | return plugin;
51 | }
52 |
53 | /**
54 | * Returns an image descriptor for the image file at the given
55 | * plug-in relative path
56 | *
57 | * @param path the path
58 | * @return the image descriptor
59 | */
60 | public static ImageDescriptor getImageDescriptor(String path) {
61 | return imageDescriptorFromPlugin(PLUGIN_ID, path);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoringDescriptor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.manipulators;
2 |
3 | import java.util.List;
4 |
5 | import gr.uom.java.ast.decomposition.cfg.mapping.DivideAndConquerMatcher;
6 |
7 | import org.eclipse.core.runtime.CoreException;
8 | import org.eclipse.ltk.core.refactoring.Refactoring;
9 | import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
10 | import org.eclipse.ltk.core.refactoring.RefactoringStatus;
11 |
12 | public class ExtractCloneRefactoringDescriptor extends RefactoringDescriptor {
13 |
14 | public static final String REFACTORING_ID = "org.eclipse.extract.clone";
15 | private List extends DivideAndConquerMatcher> mappers;
16 |
17 | protected ExtractCloneRefactoringDescriptor(String project,
18 | String description, String comment, List extends DivideAndConquerMatcher> mappers) {
19 | super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
20 | this.mappers = mappers;
21 | }
22 |
23 | @Override
24 | public Refactoring createRefactoring(RefactoringStatus status)
25 | throws CoreException {
26 | Refactoring refactoring = new ExtractCloneRefactoring(mappers);
27 | RefactoringStatus refStatus = new RefactoringStatus();
28 | status.merge(refStatus);
29 | return refactoring;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractMethodRefactoringDescriptor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.manipulators;
2 |
3 | import org.eclipse.core.runtime.CoreException;
4 | import org.eclipse.jdt.core.dom.CompilationUnit;
5 | import org.eclipse.ltk.core.refactoring.Refactoring;
6 | import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
7 | import org.eclipse.ltk.core.refactoring.RefactoringStatus;
8 |
9 | public class ExtractMethodRefactoringDescriptor extends RefactoringDescriptor {
10 |
11 | public static final String REFACTORING_ID = "org.eclipse.extract.method";
12 | private CompilationUnit sourceCompilationUnit;
13 | private ASTSlice slice;
14 |
15 | protected ExtractMethodRefactoringDescriptor(String project, String description, String comment,
16 | CompilationUnit sourceCompilationUnit, ASTSlice slice) {
17 | super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
18 | this.sourceCompilationUnit = sourceCompilationUnit;
19 | this.slice = slice;
20 | }
21 |
22 | @Override
23 | public Refactoring createRefactoring(RefactoringStatus status)
24 | throws CoreException {
25 | Refactoring refactoring = new ExtractMethodRefactoring(sourceCompilationUnit, slice);
26 | RefactoringStatus refStatus = new RefactoringStatus();
27 | status.merge(refStatus);
28 | return refactoring;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/manipulators/ReplaceConditionalWithPolymorphismDescriptor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.manipulators;
2 |
3 | import org.eclipse.core.resources.IFile;
4 | import org.eclipse.core.runtime.CoreException;
5 | import org.eclipse.jdt.core.dom.CompilationUnit;
6 | import org.eclipse.jdt.core.dom.TypeDeclaration;
7 | import org.eclipse.ltk.core.refactoring.Refactoring;
8 | import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
9 | import org.eclipse.ltk.core.refactoring.RefactoringStatus;
10 |
11 | public class ReplaceConditionalWithPolymorphismDescriptor extends RefactoringDescriptor {
12 |
13 | public static final String REFACTORING_ID = "org.eclipse.replace.conditional.with.polymorphism";
14 | private IFile sourceFile;
15 | private CompilationUnit sourceCompilationUnit;
16 | private TypeDeclaration sourceTypeDeclaration;
17 | private TypeCheckElimination typeCheckElimination;
18 |
19 | protected ReplaceConditionalWithPolymorphismDescriptor(String project, String description, String comment,
20 | IFile sourceFile, CompilationUnit sourceCompilationUnit,
21 | TypeDeclaration sourceTypeDeclaration, TypeCheckElimination typeCheckElimination) {
22 | super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
23 | this.sourceFile = sourceFile;
24 | this.sourceCompilationUnit = sourceCompilationUnit;
25 | this.sourceTypeDeclaration = sourceTypeDeclaration;
26 | this.typeCheckElimination = typeCheckElimination;
27 | }
28 |
29 | @Override
30 | public Refactoring createRefactoring(RefactoringStatus status)
31 | throws CoreException {
32 | Refactoring refactoring = new ReplaceConditionalWithPolymorphism(sourceFile, sourceCompilationUnit, sourceTypeDeclaration, typeCheckElimination);
33 | RefactoringStatus refStatus = new RefactoringStatus();
34 | status.merge(refStatus);
35 | return refactoring;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/manipulators/ReplaceTypeCodeWithStateStrategyDescriptor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.manipulators;
2 |
3 | import org.eclipse.core.resources.IFile;
4 | import org.eclipse.core.runtime.CoreException;
5 | import org.eclipse.jdt.core.dom.CompilationUnit;
6 | import org.eclipse.jdt.core.dom.TypeDeclaration;
7 | import org.eclipse.ltk.core.refactoring.Refactoring;
8 | import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
9 | import org.eclipse.ltk.core.refactoring.RefactoringStatus;
10 |
11 | public class ReplaceTypeCodeWithStateStrategyDescriptor extends RefactoringDescriptor {
12 |
13 | public static final String REFACTORING_ID = "org.eclipse.replace.type.code.with.state.strategy";
14 | private IFile sourceFile;
15 | private CompilationUnit sourceCompilationUnit;
16 | private TypeDeclaration sourceTypeDeclaration;
17 | private TypeCheckElimination typeCheckElimination;
18 |
19 | protected ReplaceTypeCodeWithStateStrategyDescriptor(String project, String description, String comment,
20 | IFile sourceFile, CompilationUnit sourceCompilationUnit,
21 | TypeDeclaration sourceTypeDeclaration, TypeCheckElimination typeCheckElimination) {
22 | super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
23 | this.sourceFile = sourceFile;
24 | this.sourceCompilationUnit = sourceCompilationUnit;
25 | this.sourceTypeDeclaration = sourceTypeDeclaration;
26 | this.typeCheckElimination = typeCheckElimination;
27 | }
28 |
29 | @Override
30 | public Refactoring createRefactoring(RefactoringStatus status)
31 | throws CoreException {
32 | Refactoring refactoring = new ReplaceTypeCodeWithStateStrategy(sourceFile, sourceCompilationUnit, sourceTypeDeclaration, typeCheckElimination);
33 | RefactoringStatus refStatus = new RefactoringStatus();
34 | status.merge(refStatus);
35 | return refactoring;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/CloneDiffContentProvider.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import gr.uom.java.ast.decomposition.cfg.mapping.CloneStructureNode;
4 |
5 | import java.util.Set;
6 |
7 | import org.eclipse.jface.viewers.ArrayContentProvider;
8 | import org.eclipse.jface.viewers.ITreeContentProvider;
9 |
10 | public class CloneDiffContentProvider extends ArrayContentProvider
11 | implements ITreeContentProvider {
12 |
13 | public Object[] getChildren(Object parentElement) {
14 | CloneStructureNode cloneStructureNode = (CloneStructureNode) parentElement;
15 | Set children = cloneStructureNode.getChildren();
16 | return children.toArray();
17 | }
18 |
19 | public Object getParent(Object element) {
20 | CloneStructureNode cloneStructureNode = (CloneStructureNode) element;
21 | return cloneStructureNode.getParent();
22 | }
23 |
24 | public boolean hasChildren(Object element) {
25 | CloneStructureNode cloneStructureNode = (CloneStructureNode) element;
26 | Set children = cloneStructureNode.getChildren();
27 | if (children.size() > 0){
28 | return true;
29 | }
30 | else
31 | return false;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/CloneDiffSide.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | public enum CloneDiffSide {
4 |
5 | LEFT, RIGHT;
6 | }
7 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/CodeSmellVisualizationDataSingleton.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import gr.uom.java.ast.visualization.VisualizationData;
4 | import gr.uom.java.distance.CandidateRefactoring;
5 |
6 | public class CodeSmellVisualizationDataSingleton {
7 | private static VisualizationData data;
8 | private static CandidateRefactoring[] candidates;
9 |
10 |
11 | public static CandidateRefactoring[] getCandidates() {
12 | return candidates;
13 | }
14 |
15 | public static void setCandidates(CandidateRefactoring[] candidates) {
16 | CodeSmellVisualizationDataSingleton.candidates = candidates;
17 | }
18 |
19 | public static VisualizationData getData() {
20 | return data;
21 | }
22 |
23 | public static void setData(VisualizationData data) {
24 | CodeSmellVisualizationDataSingleton.data = data;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/ElementChangedListener.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import gr.uom.java.ast.CompilationUnitCache;
4 |
5 | import org.eclipse.jdt.core.ElementChangedEvent;
6 | import org.eclipse.jdt.core.ICompilationUnit;
7 | import org.eclipse.jdt.core.IElementChangedListener;
8 | import org.eclipse.jdt.core.IJavaElement;
9 | import org.eclipse.jdt.core.IJavaElementDelta;
10 |
11 | public class ElementChangedListener implements IElementChangedListener {
12 | private static ElementChangedListener instance;
13 |
14 | public static ElementChangedListener getInstance() {
15 | if(instance == null) {
16 | instance = new ElementChangedListener();
17 | }
18 | return instance;
19 | }
20 |
21 | public void elementChanged(ElementChangedEvent event) {
22 | IJavaElementDelta javaElementDelta = event.getDelta();
23 | processDelta(javaElementDelta);
24 | }
25 |
26 | private void processDelta(IJavaElementDelta delta) {
27 | IJavaElement javaElement = delta.getElement();
28 | switch(javaElement.getElementType()) {
29 | case IJavaElement.JAVA_MODEL:
30 | case IJavaElement.JAVA_PROJECT:
31 | case IJavaElement.PACKAGE_FRAGMENT_ROOT:
32 | case IJavaElement.PACKAGE_FRAGMENT:
33 | IJavaElementDelta[] affectedChildren = delta.getAffectedChildren();
34 | for(IJavaElementDelta affectedChild : affectedChildren) {
35 | processDelta(affectedChild);
36 | }
37 | break;
38 | case IJavaElement.COMPILATION_UNIT:
39 | ICompilationUnit compilationUnit = (ICompilationUnit)javaElement;
40 | if(delta.getKind() == IJavaElementDelta.ADDED) {
41 | CompilationUnitCache.getInstance().compilationUnitAdded(compilationUnit);
42 | }
43 | else if(delta.getKind() == IJavaElementDelta.REMOVED) {
44 | CompilationUnitCache.getInstance().compilationUnitRemoved(compilationUnit);
45 | }
46 | else if(delta.getKind() == IJavaElementDelta.CHANGED) {
47 | if((delta.getFlags() & IJavaElementDelta.F_FINE_GRAINED) != 0) {
48 | CompilationUnitCache.getInstance().compilationUnitChanged(compilationUnit);
49 | }
50 | }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/EvolutionRow.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import gr.uom.java.history.ProjectVersionPair;
4 |
5 | public class EvolutionRow {
6 | private ProjectVersionPair projectVersionPair;
7 | private String percentage;
8 |
9 | public EvolutionRow(ProjectVersionPair projectVersionPair, String percentage) {
10 | this.projectVersionPair = projectVersionPair;
11 | this.percentage = percentage;
12 | }
13 |
14 | public ProjectVersionPair getProjectVersionPair() {
15 | return projectVersionPair;
16 | }
17 |
18 | public String getPercentage() {
19 | return percentage;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/LabelControlContribution.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import org.eclipse.jface.action.ControlContribution;
4 | import org.eclipse.swt.SWT;
5 | import org.eclipse.swt.graphics.Font;
6 | import org.eclipse.swt.widgets.Composite;
7 | import org.eclipse.swt.widgets.Control;
8 | import org.eclipse.swt.widgets.Label;
9 |
10 | public class LabelControlContribution extends ControlContribution
11 | {
12 | private String name;
13 | private Font font;
14 | private static final Font CONSOLAS_BOLD_FONT = new Font(null, "Consolas", 10, SWT.BOLD);
15 | private Label label;
16 |
17 | protected LabelControlContribution(String id, String name, Font font)
18 | {
19 | super(id);
20 | this.name= name;
21 | this.font= font;
22 | }
23 |
24 | protected LabelControlContribution(String id, String name)
25 | {
26 | super(id);
27 | this.name= name;
28 | this.font= CONSOLAS_BOLD_FONT;
29 | }
30 |
31 | @Override
32 | protected Control createControl(Composite parent)
33 | {
34 | label= new Label(parent, SWT.CENTER);
35 | label.setText(name);
36 | if(font != null)
37 | label.setFont(font);
38 | return label;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/MethodNameValidator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | import org.eclipse.jface.dialogs.IInputValidator;
6 |
7 | public class MethodNameValidator implements IInputValidator {
8 |
9 | public String isValid(String newText) {
10 | String pattern = "[a-zA-Z\\$_][a-zA-Z0-9\\$_]*";
11 | if(Pattern.matches(pattern, newText)) {
12 | return null;
13 | }
14 | else {
15 | return "Invalid method name";
16 | }
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/MultilineButton.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import org.eclipse.swt.SWT;
4 | import org.eclipse.swt.graphics.GC;
5 | import org.eclipse.swt.graphics.Point;
6 | import org.eclipse.swt.widgets.Button;
7 | import org.eclipse.swt.widgets.Composite;
8 |
9 |
10 | public class MultilineButton extends Button {
11 |
12 | public MultilineButton(Composite parent, int style) {
13 | super(parent, style);
14 | }
15 |
16 | @Override
17 | protected void checkSubclass() {
18 | }
19 |
20 | @Override
21 | public Point computeSize(int wHint, int hHint, boolean changed) {
22 | final Point size = super.computeSize(wHint, hHint, changed);
23 | final GC gc = new GC(this);
24 |
25 | final String multiLineText = this.getText();
26 | final Point multiLineTextSize = gc.textExtent(multiLineText, SWT.DRAW_DELIMITER);
27 |
28 | final String flatText = multiLineText.replace('\n', ' ');
29 | final Point flatTextSize = gc.textExtent(flatText);
30 |
31 | gc.dispose();
32 |
33 | size.x -= flatTextSize.x - multiLineTextSize.x;
34 | size.y += multiLineTextSize.y - flatTextSize.y;
35 |
36 | return size;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/MyComboBoxCellEditor.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import org.eclipse.jface.viewers.ComboBoxCellEditor;
4 | import org.eclipse.swt.custom.CCombo;
5 | import org.eclipse.swt.events.SelectionAdapter;
6 | import org.eclipse.swt.events.SelectionEvent;
7 | import org.eclipse.swt.widgets.Composite;
8 | import org.eclipse.swt.widgets.Control;
9 |
10 | public class MyComboBoxCellEditor extends ComboBoxCellEditor {
11 |
12 | public MyComboBoxCellEditor(Composite parent, String[] items, int style) {
13 | super(parent, items, style);
14 | }
15 |
16 | protected Control createControl(Composite parent) {
17 | CCombo control = (CCombo)super.createControl(parent);
18 | control.addSelectionListener(new SelectionAdapter() {
19 | public void widgetSelected(SelectionEvent event) {
20 | focusLost();
21 | }
22 | });
23 | return control;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/SliceAnnotation.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import org.eclipse.jface.text.source.Annotation;
4 |
5 | public class SliceAnnotation extends Annotation {
6 | public static final String EXTRACTION = "gr.uom.java.jdeodorant.extractionAnnotation";
7 | public static final String DUPLICATION = "gr.uom.java.jdeodorant.duplicationAnnotation";
8 |
9 | public SliceAnnotation(String type, String text) {
10 | super(type, false, text);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/SliceProfileRow.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import gr.uom.java.ast.decomposition.cfg.PlainVariable;
4 |
5 | import java.util.LinkedHashMap;
6 | import java.util.Map;
7 | import java.util.Set;
8 |
9 | public class SliceProfileRow {
10 |
11 | private int statementID;
12 | private Map sliceCoverageMap;
13 |
14 | public SliceProfileRow(int statementID) {
15 | this.statementID = statementID;
16 | this.sliceCoverageMap = new LinkedHashMap();
17 | }
18 |
19 | public int getStatementID() {
20 | return statementID;
21 | }
22 |
23 | public void put(PlainVariable variable, boolean value) {
24 | sliceCoverageMap.put(variable, value);
25 | }
26 |
27 | public boolean getValue(PlainVariable variable) {
28 | return sliceCoverageMap.get(variable);
29 | }
30 |
31 | public boolean statementBelongsToAllSlices(Set variables) {
32 | if(variables.isEmpty())
33 | return false;
34 | for(PlainVariable variable : variables) {
35 | if(sliceCoverageMap.get(variable) == false)
36 | return false;
37 | }
38 | return true;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/StringCompareEditorInput.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.InputStream;
5 | import java.lang.reflect.InvocationTargetException;
6 |
7 | import org.eclipse.compare.CompareConfiguration;
8 | import org.eclipse.compare.CompareEditorInput;
9 | import org.eclipse.compare.IStreamContentAccessor;
10 | import org.eclipse.compare.ITypedElement;
11 | import org.eclipse.compare.structuremergeviewer.Differencer;
12 | import org.eclipse.core.runtime.CoreException;
13 | import org.eclipse.core.runtime.IProgressMonitor;
14 | import org.eclipse.core.runtime.NullProgressMonitor;
15 | import org.eclipse.swt.graphics.Image;
16 |
17 | public class StringCompareEditorInput extends CompareEditorInput {
18 | private String input1;
19 | private String input2;
20 |
21 | public StringCompareEditorInput(CompareConfiguration configuration, String input1, String input2) {
22 | super(configuration);
23 | this.input1 = input1;
24 | this.input2 = input2;
25 | }
26 |
27 | @Override
28 | protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
29 | Differencer d = new Differencer();
30 | Object diff = d.findDifferences(false, new NullProgressMonitor(), null, null, new Input(input1), new Input(input2));
31 | return diff;
32 | }
33 |
34 | private class Input implements ITypedElement, IStreamContentAccessor {
35 | String fContent;
36 | public Input(String s) {
37 | fContent = s;
38 | }
39 |
40 | public String getName() {
41 | return "name";
42 | }
43 |
44 | public Image getImage() {
45 | return null;
46 | }
47 |
48 | public String getType() {
49 | return "txt";
50 | }
51 |
52 | public InputStream getContents() throws CoreException {
53 | return new ByteArrayInputStream(fContent.getBytes());
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/gr/uom/java/jdeodorant/refactoring/views/ZoomValueValidator.java:
--------------------------------------------------------------------------------
1 | package gr.uom.java.jdeodorant.refactoring.views;
2 |
3 | import org.eclipse.jface.dialogs.IInputValidator;
4 |
5 | public class ZoomValueValidator implements IInputValidator {
6 |
7 | public String isValid(String newText) {
8 | try{
9 | int value = Integer.parseInt(newText);
10 | if (value>0)
11 | return null;
12 | else
13 | return "Zoom value should be a positive integer";
14 | } catch(NumberFormatException exception){
15 | return "Zoom value should be a positive integer";
16 | }
17 |
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------