]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/javadocexport/JavadocLinkRef.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / javadocexport / JavadocLinkRef.java
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  *******************************************************************************/
11
12 package org.eclipse.jdt.internal.ui.javadocexport;
13
14 import java.net.URL;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 import org.eclipse.jdt.core.IClasspathEntry;
21 import org.eclipse.jdt.core.IJavaProject;
22
23 import org.eclipse.jdt.ui.JavaUI;
24
25 import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
26 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
27
28
29 public class JavadocLinkRef {
30         private final IJavaProject fProject;
31         private final IPath fContainerPath;
32         private IClasspathEntry fClasspathEntry;
33
34         public JavadocLinkRef(IPath containerPath, IClasspathEntry classpathEntry, IJavaProject project) {
35                 fContainerPath= containerPath;
36                 fProject= project;
37                 fClasspathEntry= classpathEntry;
38         }
39
40         public JavadocLinkRef(IJavaProject project) {
41                 this(null, null, project);
42         }
43
44         public boolean isProjectRef() {
45                 return fClasspathEntry == null;
46         }
47
48         public IPath getFullPath() {
49                 return isProjectRef() ? fProject.getPath() : fClasspathEntry.getPath();
50         }
51
52         public URL getURL() {
53                 if (isProjectRef()) {
54                         return JavaUI.getProjectJavadocLocation(fProject);
55                 } else {
56                         return JavaUI.getLibraryJavadocLocation(fClasspathEntry);
57                 }
58         }
59
60         public void setURL(URL url, IProgressMonitor monitor) throws CoreException {
61                 if (isProjectRef()) {
62                         JavaUI.setProjectJavadocLocation(fProject, url);
63                 } else {
64                         CPListElement element= CPListElement.createFromExisting(fClasspathEntry, fProject);
65                         String location= url != null ? url.toExternalForm() : null;
66                         element.setAttribute(CPListElement.JAVADOC, location);
67                         String[] changedAttributes= { CPListElement.JAVADOC };
68                         BuildPathSupport.modifyClasspathEntry(null, element.getClasspathEntry(), changedAttributes, fProject, fContainerPath, fClasspathEntry.getReferencingEntry() != null, monitor);
69                         fClasspathEntry= element.getClasspathEntry();
70                 }
71         }
72
73         @Override
74         public boolean equals(Object obj) {
75                 if (obj != null && obj.getClass().equals(getClass())) {
76                         JavadocLinkRef other= (JavadocLinkRef) obj;
77                         if (!fProject.equals(other.fProject) || isProjectRef() != other.isProjectRef()) {
78                                 return false;
79                         }
80                         if (!isProjectRef()) {
81                                 return fClasspathEntry.equals(other.fClasspathEntry);
82                         } else {
83                                 return true;
84                         }
85                 }
86                 return false;
87         }
88
89         @Override
90         public int hashCode() {
91                 if (isProjectRef()) {
92                         return fProject.hashCode();
93                 } else {
94                         return fProject.hashCode() + fClasspathEntry.hashCode();
95                 }
96
97         }
98 }