001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.ui.text.java;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IPath;
014: import org.eclipse.core.runtime.IProgressMonitor;
015: import org.eclipse.core.runtime.MultiStatus;
016:
017: import org.eclipse.swt.graphics.Image;
018:
019: import org.eclipse.ltk.core.refactoring.Change;
020:
021: import org.eclipse.jdt.core.IClasspathEntry;
022: import org.eclipse.jdt.core.IJavaProject;
023: import org.eclipse.jdt.core.JavaConventions;
024: import org.eclipse.jdt.core.JavaModelException;
025:
026: import org.eclipse.jdt.internal.corext.refactoring.changes.ClasspathChange;
027:
028: import org.eclipse.jdt.internal.ui.text.correction.ClasspathFixProcessorDescriptor;
029:
030: /**
031: * Class to be implemented by contributors to the extension point
032: * <code>org.eclipse.jdt.ui.classpathFixProcessors</code>.
033: *
034: * <strong>EXPERIMENTAL</strong> This class or interface has been added as part
035: * of a work in progress. We are interested in feedback (bug 196141) . This API may still change.
036: *
037: * @since 3.4
038: */
039: public abstract class ClasspathFixProcessor {
040:
041: /**
042: * A proposal to fix a class path issue.
043: */
044: public static abstract class ClasspathFixProposal {
045:
046: /**
047: * A helper method to create a {@link Change} that modifies a class path.
048: *
049: * @param project the project to change
050: * @param newClasspath the new class path
051: * @param outputLocation the new output location
052: *
053: * @return the {@link Change} to change the class path or <code>null</code> if the class path is
054: * not valid (See {@link JavaConventions#validateClasspath(IJavaProject, IClasspathEntry[], IPath)}).
055: */
056: public static Change newClasspathChange(IJavaProject project,
057: IClasspathEntry[] newClasspath, IPath outputLocation) {
058: return ClasspathChange.newChange(project, newClasspath,
059: outputLocation);
060: }
061:
062: /**
063: * A helper method to create a {@link Change} that adds an entry to the class path.
064: *
065: * @param project the project to change
066: * @param entryToAdd the entry to add to the class path
067: *
068: * @return the {@link Change} to change the class path or <code>null</code> if the class path is
069: * not valid (See {@link JavaConventions#validateClasspath(IJavaProject, IClasspathEntry[], IPath)}).
070: * @throws JavaModelException thrown if accessing the project failed.
071: */
072: public static Change newAddClasspathChange(
073: IJavaProject project, IClasspathEntry entryToAdd)
074: throws JavaModelException {
075: return ClasspathChange.addEntryChange(project, entryToAdd);
076: }
077:
078: /**
079: * Returns the change to invoke when the proposal is selected.
080: *
081: * @param monitor the progress monitor
082: * @return the change
083: * @throws CoreException thrown when the creation of the change failed
084: */
085: public abstract Change createChange(IProgressMonitor monitor)
086: throws CoreException;
087:
088: /**
089: * Returns the string to be displayed in a list of proposals.
090: *
091: * @return the string to be displayed
092: */
093: public abstract String getDisplayString();
094:
095: /**
096: * Returns optional additional information about the proposal. The additional information will
097: * be presented to assist the user in deciding if the selected proposal is the desired choice.
098: *
099: * @return the additional information or <code>null</code>
100: */
101: public abstract String getAdditionalProposalInfo();
102:
103: /**
104: * Returns the image to be displayed in the list of completion proposals.
105: * The image would typically be shown to the left of the display string.
106: *
107: * @return the image to be shown or <code>null</code> if no image is desired
108: */
109: public abstract Image getImage();
110:
111: /**
112: * Returns the relevance of this completion proposal.
113: * <p>
114: * The relevance is used to determine if this proposal is more
115: * relevant than another proposal.</p>
116: *
117: * @return the relevance of this completion proposal in the range of [0, 100]
118: */
119: public abstract int getRelevance();
120: }
121:
122: /**
123: * Returns proposal that can fix non-resolvable imports.
124: *
125: * @param project the current project
126: * @param name the missing type to be added to the class path. The entries can be either a
127: * <ul><li>qualified type name, like 'junit.framework.Test'</li>
128: * <li>simple type name, like 'TestCase'</li>
129: * <li>on demand import name, like 'org.junit.*'</li></ul>
130: * @return returns proposals to fix the class path so that the missing types are found. If no proposals can be offered,
131: * either <code>null</code> or the empty array can be returned. If <code>null</code> is returned, also the processors
132: * overridden by this processor are asked. If a non null result is returned, all overridden processors are skipped.
133: *
134: * @throws CoreException thrown when the creation of the proposals fails
135: */
136: public abstract ClasspathFixProposal[] getFixImportProposals(
137: IJavaProject project, String name) throws CoreException;
138:
139: /**
140: * Evaluates all contributed proposals that can fix non-resolvable imports.
141: *
142: * @param project the current project
143: * @param name the missing type to be added to the class path. The entries can be either a
144: * <ul><li>qualified type name, like 'junit.framework.Test'</li>
145: * <li>simple type name, like 'TestCase'</li>
146: * <li>on demand import name, like 'org.junit.*'</li></ul>
147: * @param status a {@link MultiStatus} to collect the resulting status or <code>null</code> to not collect status.
148: * @return returns proposals to fix the class path so that the missing types are found.
149: */
150: public static ClasspathFixProposal[] getContributedFixImportProposals(
151: IJavaProject project, String name, MultiStatus status) {
152: return ClasspathFixProcessorDescriptor.getProposals(project,
153: name, status);
154: }
155:
156: }
|