]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/core extension/org/eclipse/jdt/internal/corext/buildpath/CPJavaProject.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / core extension / org / eclipse / jdt / internal / corext / buildpath / CPJavaProject.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.corext.buildpath;
12
13import java.util.ArrayList;
14import java.util.Iterator;
15import java.util.List;
16
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.core.runtime.IPath;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.SubProgressMonitor;
22
23import org.eclipse.jdt.core.IClasspathEntry;
24import org.eclipse.jdt.core.IJavaProject;
25import org.eclipse.jdt.core.IPackageFragmentRoot;
26import org.eclipse.jdt.core.JavaModelException;
27
28import org.eclipse.jdt.internal.ui.JavaPlugin;
29import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
30import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
31import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
32import org.eclipse.jdt.internal.ui.wizards.buildpaths.OutputLocationDialog;
33
34public class CPJavaProject {
35
36 public static CPJavaProject createFromExisting(IJavaProject javaProject) throws CoreException {
37 List<CPListElement> classpathEntries= ClasspathModifier.getExistingEntries(javaProject);
38 return new CPJavaProject(javaProject, classpathEntries, javaProject.getOutputLocation());
39 }
40
41 private final IJavaProject fJavaProject;
42 private final List<CPListElement> fCPListElements;
43 private IPath fDefaultOutputLocation;
44
45 public CPJavaProject(IJavaProject javaProject, List<CPListElement> cpListElements, IPath defaultOutputLocation) {
46 fJavaProject= javaProject;
47 fCPListElements= cpListElements;
48 fDefaultOutputLocation= defaultOutputLocation;
49 }
50
51 public CPJavaProject createWorkingCopy() {
52 List<CPListElement> newList= new ArrayList<CPListElement>(fCPListElements.size());
53 for (Iterator<CPListElement> iterator= fCPListElements.iterator(); iterator.hasNext();) {
54 CPListElement element= iterator.next();
55 newList.add(element.copy());
56 }
57 return new CPJavaProject(fJavaProject, newList, fDefaultOutputLocation);
58 }
59
60 public CPListElement get(int index) {
61 return fCPListElements.get(index);
62 }
63
64 public IClasspathEntry[] getClasspathEntries() {
65 IClasspathEntry[] result= new IClasspathEntry[fCPListElements.size()];
66 int i= 0;
67 for (Iterator<CPListElement> iterator= fCPListElements.iterator(); iterator.hasNext();) {
68 CPListElement element= iterator.next();
69 result[i]= element.getClasspathEntry();
70 i++;
71 }
72 return result;
73 }
74
75 public CPListElement getCPElement(CPListElement element) {
76 return ClasspathModifier.getClasspathEntry(fCPListElements, element);
77 }
78
79 public List<CPListElement> getCPListElements() {
80 return fCPListElements;
81 }
82
83 public IPath getDefaultOutputLocation() {
84 return fDefaultOutputLocation;
85 }
86
87 public IJavaProject getJavaProject() {
88 return fJavaProject;
89 }
90
91 public int indexOf(CPListElement element) {
92 return fCPListElements.indexOf(element);
93 }
94
95 public void setDefaultOutputLocation(IPath path) {
96 fDefaultOutputLocation= path;
97 }
98
99 public void generated_1803604505418629662(OutputLocationDialog outputlocationdialog, String pathStr) {
100 if (pathStr.length() == 0) {
101 outputlocationdialog.fContainerFieldStatus= new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
102 return;
103 }
104
105 IPath projectPath= getJavaProject().getProject().getFullPath();
106 IPath outputPath= projectPath.append(pathStr);
107
108 try {
109 outputlocationdialog.fContainerFieldStatus= ClasspathModifier.checkSetOutputLocationPrecondition(outputlocationdialog.fEntryToEdit, outputPath, outputlocationdialog.fAllowInvalidClasspath, this);
110 if (outputlocationdialog.fContainerFieldStatus.getSeverity() != IStatus.ERROR) {
111 outputlocationdialog.fOutputLocation= outputPath;
112 }
113 } catch (CoreException e) {
114 JavaPlugin.log(e);
115 }
116 }
117
118 public BuildpathDelta generated_2728894491202302561(final IJavaProject project, final List<Object> elementsToRemove, IProgressMonitor monitor)
119 throws JavaModelException {
120 CPListElement[] toRemove= new CPListElement[elementsToRemove.size()];
121 int i= 0;
122 for (Iterator<Object> iterator= elementsToRemove.iterator(); iterator.hasNext();) {
123 Object element= iterator.next();
124 if (element instanceof IJavaProject) {
125 toRemove[i]= ClasspathModifier.getListElement(((IJavaProject)element).getPath(), getCPListElements());
126 } else if (element instanceof IPackageFragmentRoot) {
127 toRemove[i]= CPListElement.createFromExisting(((IPackageFragmentRoot)element).getRawClasspathEntry(), project);
128 } else {
129 toRemove[i]= CPListElement.createFromExisting(((ClassPathContainer)element).getClasspathEntry(), project);
130 }
131 i++;
132 }
133
134 BuildpathDelta delta= ClasspathModifier.removeFromBuildpath(toRemove, this);
135 ClasspathModifier.commitClassPath(this, new SubProgressMonitor(monitor, 10));
136 return delta;
137 }
138
139 public BuildpathDelta generated_4221408716956340203(IPath[] jarPaths, IProgressMonitor monitor) throws JavaModelException {
140 BuildpathDelta delta= ClasspathModifier.addExternalJars(jarPaths, this);
141 ClasspathModifier.commitClassPath(this, new SubProgressMonitor(monitor, 4));
142 return delta;
143 }
144
145 public BuildpathDelta generated_2854853818809277972(final CPListElement element, final OutputLocationDialog dialog) throws CoreException {
146 final BuildpathDelta delta= ClasspathModifier.setOutputLocation(getCPElement(element), dialog.getOutputLocation(), false, this);
147 return delta;
148 }
149}