View | Details | Raw Unified | Return to bug 96962 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+2 lines)
Lines 1606-1611 Link Here
1606
	public static String FeatureImportWizard_operation_multiProblem;
1606
	public static String FeatureImportWizard_operation_multiProblem;
1607
	public static String FeatureImportWizard_operation_creating2;
1607
	public static String FeatureImportWizard_operation_creating2;
1608
1608
1609
	public static String ForbiddenAccessProposal_quickfixMessage;
1610
1609
	public static String UpdateBuildpathWizard_wtitle;
1611
	public static String UpdateBuildpathWizard_wtitle;
1610
	public static String UpdateBuildpathWizard_title;
1612
	public static String UpdateBuildpathWizard_title;
1611
	public static String UpdateBuildpathWizard_desc;
1613
	public static String UpdateBuildpathWizard_desc;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+1 lines)
Lines 1120-1125 Link Here
1120
FeatureImportWizard_operation_creating = Creating projects from features...
1120
FeatureImportWizard_operation_creating = Creating projects from features...
1121
FeatureImportWizard_operation_multiProblem = Problems detected while importing features
1121
FeatureImportWizard_operation_multiProblem = Problems detected while importing features
1122
FeatureImportWizard_operation_creating2 = Creating ''{0}''...
1122
FeatureImportWizard_operation_creating2 = Creating ''{0}''...
1123
ForbiddenAccessProposal_quickfixMessage=Export the ''{0}'' package from the ''{1}'' plug-in
1123
1124
1124
UpdateBuildpathWizard_wtitle = Java Classpath
1125
UpdateBuildpathWizard_wtitle = Java Classpath
1125
UpdateBuildpathWizard_title = Update Java class path
1126
UpdateBuildpathWizard_title = Update Java class path
(-)plugin.xml (+7 lines)
Lines 1753-1756 Link Here
1753
                parentId="org.eclipse.ui.textEditorScope">
1753
                parentId="org.eclipse.ui.textEditorScope">
1754
          </context>
1754
          </context>
1755
       </extension>
1755
       </extension>
1756
       <extension
1757
             point="org.eclipse.jdt.ui.quickFixProcessors">
1758
          <quickFixProcessor
1759
                class="org.eclipse.pde.internal.ui.correction.java.QuickFixProcessor"
1760
                id="org.eclipse.jdt.ui.text.correction.QuickFixProcessor">
1761
          </quickFixProcessor>
1762
       </extension>
1756
</plugin>
1763
</plugin>
(-)src/org/eclipse/pde/internal/ui/correction/java/ForbiddenAccessProposal.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
package org.eclipse.pde.internal.ui.correction.java;
12
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.NullProgressMonitor;
17
import org.eclipse.jdt.core.IPackageFragment;
18
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.contentassist.IContextInformation;
21
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.pde.core.IBaseModel;
23
import org.eclipse.pde.internal.core.ibundle.IBundle;
24
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
25
import org.eclipse.pde.internal.core.text.bundle.ExportPackageHeader;
26
import org.eclipse.pde.internal.core.text.bundle.ExportPackageObject;
27
import org.eclipse.pde.internal.ui.PDEPluginImages;
28
import org.eclipse.pde.internal.ui.PDEUIMessages;
29
import org.eclipse.pde.internal.ui.util.ModelModification;
30
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
31
import org.eclipse.swt.graphics.Image;
32
import org.eclipse.swt.graphics.Point;
33
import org.osgi.framework.Constants;
34
35
public class ForbiddenAccessProposal implements IJavaCompletionProposal {
36
37
	private IProject fProject;
38
	private IPackageFragment fFragment;
39
	
40
	public ForbiddenAccessProposal(IPackageFragment fragment, IProject project) {
41
		fProject = project;
42
		fFragment = fragment;
43
	}
44
45
	public void apply(IDocument document) {
46
		ModelModification mod = new ModelModification(fProject){
47
			protected void modifyModel(IBaseModel model,
48
					IProgressMonitor monitor) throws CoreException {
49
				if (model instanceof IBundlePluginModelBase) {
50
					IBundle bundle = ((IBundlePluginModelBase)model).getBundleModel().getBundle();
51
52
					ExportPackageHeader header = (ExportPackageHeader)bundle.getManifestHeader(Constants.EXPORT_PACKAGE);
53
					if (header == null) {
54
						bundle.setHeader(Constants.EXPORT_PACKAGE, ""); //$NON-NLS-1$
55
						header = (ExportPackageHeader)bundle.getManifestHeader(Constants.EXPORT_PACKAGE);
56
					}
57
					header.addPackage(new ExportPackageObject(header, fFragment, Constants.VERSION_ATTRIBUTE));
58
				}
59
			}
60
		};
61
		PDEModelUtility.modifyModel(mod, new NullProgressMonitor());
62
	}
63
	
64
	public String getDisplayString() {
65
		return NLS.bind(PDEUIMessages.ForbiddenAccessProposal_quickfixMessage, new String[] {fFragment.getElementName(), fProject.getName()});
66
	}
67
	
68
	// Assume that JDT will dispose this image when the quickfix menu is closed
69
	public Image getImage() {
70
		return PDEPluginImages.DESC_BUNDLE_OBJ.createImage();
71
	}
72
	
73
	public int getRelevance() {
74
		return 100;
75
	}
76
	
77
	public String getAdditionalProposalInfo() {
78
		return null;
79
	}
80
	public IContextInformation getContextInformation() {
81
		return null;
82
	}
83
	public Point getSelection(IDocument document) {
84
		return null;
85
	}
86
}
(-)src/org/eclipse/pde/internal/ui/correction/java/QuickFixProcessor.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
package org.eclipse.pde.internal.ui.correction.java;
12
13
import java.util.ArrayList;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IJavaElement;
18
import org.eclipse.jdt.core.IJavaProject;
19
import org.eclipse.jdt.core.IPackageFragment;
20
import org.eclipse.jdt.core.compiler.IProblem;
21
import org.eclipse.jdt.core.dom.ASTNode;
22
import org.eclipse.jdt.core.dom.IBinding;
23
import org.eclipse.jdt.core.dom.Name;
24
import org.eclipse.jdt.core.dom.Type;
25
import org.eclipse.jdt.ui.text.java.IInvocationContext;
26
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
27
import org.eclipse.jdt.ui.text.java.IProblemLocation;
28
import org.eclipse.jdt.ui.text.java.IQuickFixProcessor;
29
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
30
import org.eclipse.pde.core.plugin.IPluginModelBase;
31
import org.eclipse.pde.internal.core.PDECore;
32
import org.eclipse.pde.internal.core.WorkspaceModelManager;
33
34
public class QuickFixProcessor implements IQuickFixProcessor {
35
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.jdt.ui.text.java.IQuickFixProcessor#getCorrections(org.eclipse.jdt.ui.text.java.IInvocationContext, org.eclipse.jdt.ui.text.java.IProblemLocation[])
38
	 */
39
	public IJavaCompletionProposal[] getCorrections(IInvocationContext context,
40
			IProblemLocation[] locations) throws CoreException {
41
		ArrayList results = new ArrayList();
42
		for (int i = 0; i < locations.length; i++) {
43
			int id = locations[i].getProblemId();
44
			switch (id) {
45
				case IProblem.ForbiddenReference:
46
					handleAccessRestrictionProblem(context, locations[i], results);
47
				default:
48
			}
49
		}
50
		return (IJavaCompletionProposal[])results.toArray(new IJavaCompletionProposal[results.size()]);
51
	}
52
	
53
	private void handleAccessRestrictionProblem(IInvocationContext context,
54
			IProblemLocation location, ArrayList results) {
55
		IBinding referencedElement= null;
56
		ASTNode node= location.getCoveredNode(context.getASTRoot());
57
		if (node instanceof Type) {
58
			referencedElement= ((Type) node).resolveBinding();
59
		} else if (node instanceof Name) {
60
			referencedElement= ((Name) node).resolveBinding();
61
		}
62
		if (referencedElement != null) {
63
			// get the project that contains the reference element
64
			// ensure it exists in the workspace and is a plug-in project
65
			IJavaProject referencedJavaProject = referencedElement.getJavaElement().getJavaProject();
66
			if (referencedJavaProject != null && WorkspaceModelManager.isPluginProject(referencedJavaProject.getProject())) {
67
				// get the packages exported by the referenced plug-in project
68
				IPluginModelBase referencedModel = PDECore.getDefault().getModelManager().findModel(referencedJavaProject.getProject());
69
				ExportPackageDescription[] exportPackages = referencedModel.getBundleDescription().getExportPackages();
70
				// check if the required package is exported already
71
				boolean packageExported = false;
72
				IPackageFragment referencedPackage = (IPackageFragment)referencedElement.getJavaElement().getAncestor(IJavaElement.PACKAGE_FRAGMENT);
73
				if (referencedPackage != null) {
74
					for (int i = 0; i < exportPackages.length; i++) {
75
						if (exportPackages[i].getName().equals(referencedPackage.getElementName())){
76
							packageExported = true;
77
							break;
78
						}
79
					}
80
					// if the package is not exported, add the quickfix
81
					if (!packageExported) {
82
						results.add(new ForbiddenAccessProposal(referencedPackage, referencedJavaProject.getProject()));
83
					}
84
				}
85
			}
86
		}
87
	}
88
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.jdt.ui.text.java.IQuickFixProcessor#hasCorrections(org.eclipse.jdt.core.ICompilationUnit, int)
91
	 */
92
	public boolean hasCorrections(ICompilationUnit unit, int problemId) {
93
		switch (problemId) {
94
			case IProblem.ForbiddenReference:
95
				IJavaElement parent = unit.getParent();
96
				if (parent != null) {
97
					IJavaProject project = parent.getJavaProject();
98
					if (project != null)
99
						return WorkspaceModelManager.isPluginProject(project.getProject());
100
				}
101
			default:
102
		}
103
		return false;
104
	}
105
106
}

Return to bug 96962