Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e27a7091c6d65a4cd0ebabc96af5f469be95be7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import org.eclipse.core.resources.IResource;

import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.CopyArguments;
import org.eclipse.ltk.core.refactoring.participants.CopyParticipant;

import org.eclipse.jdt.core.IJavaElement;

import org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping;

public class TestCopyParticipantSingle extends CopyParticipant {

	static List<TestCopyParticipantSingle> fgInstances= new ArrayList<>();

	private Object fElement;
	private String fHandle;

	@Override
	public boolean initialize(Object element) {
		fgInstances.add(this);
		fElement= element;
		if (fElement instanceof IJavaElement) {
			fHandle= ((IJavaElement)fElement).getHandleIdentifier();
		} else if (fElement instanceof IResource) {
			fHandle= ((IResource)fElement).getFullPath().toString();
		} else if (element instanceof JavaElementResourceMapping) {
			fHandle= ((JavaElementResourceMapping)element).
				getJavaElement().getHandleIdentifier() + "_mapping";
		}
		return true;
	}

	@Override
	public String getName() {
		return getClass().getName();
	}

	@Override
	public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) {
		return new RefactoringStatus();
	}

	@Override
	public Change createChange(IProgressMonitor pm) throws CoreException {
		return null;
	}

	public static void testNumberOfInstances(int instances) {
		Assert.assertEquals(instances, fgInstances.size());
	}

	public static void testElements(String[] handles) {
		testNumberOfInstances(handles.length);
		List<String> l1= new ArrayList<>(Arrays.asList(handles));
		for (int i= 0; i < l1.size(); i++) {
			Assert.assertTrue(l1.contains(getInstance(i).fHandle));
		}
	}

	public static void testArguments(CopyArguments[] args) {
		testNumberOfInstances(args.length);
		for (int i= 0; i < args.length; i++) {
			CopyArguments expected= args[i];
			CopyArguments actual= getInstance(i).getArguments();
			TestCopyParticipantShared.compareArguments(expected, actual);
		}
	}

	public static void reset() {
		fgInstances= new ArrayList<>();
	}

	private static TestCopyParticipantSingle getInstance(int i) {
		return fgInstances.get(i);
	}
}

Back to the top