01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.text.java;
11:
12: import org.eclipse.core.runtime.Assert;
13:
14: import org.eclipse.jdt.core.CompletionProposal;
15: import org.eclipse.jdt.core.IJavaElement;
16: import org.eclipse.jdt.core.IJavaProject;
17: import org.eclipse.jdt.core.IMember;
18: import org.eclipse.jdt.core.JavaModelException;
19:
20: /**
21: * Proposal info that computes the javadoc lazily when it is queried.
22: *
23: * @since 3.1
24: */
25: public abstract class MemberProposalInfo extends ProposalInfo {
26: /* configuration */
27: protected final IJavaProject fJavaProject;
28: protected final CompletionProposal fProposal;
29:
30: /* cache filled lazily */
31: private boolean fJavaElementResolved = false;
32:
33: /**
34: * Creates a new proposal info.
35: *
36: * @param project the java project to reference when resolving types
37: * @param proposal the proposal to generate information for
38: */
39: public MemberProposalInfo(IJavaProject project,
40: CompletionProposal proposal) {
41: Assert.isNotNull(project);
42: Assert.isNotNull(proposal);
43: fJavaProject = project;
44: fProposal = proposal;
45: }
46:
47: /**
48: * Returns the java element that this computer corresponds to, possibly <code>null</code>.
49: *
50: * @return the java element that this computer corresponds to, possibly <code>null</code>
51: * @throws JavaModelException
52: */
53: public IJavaElement getJavaElement() throws JavaModelException {
54: if (!fJavaElementResolved) {
55: fJavaElementResolved = true;
56: fElement = resolveMember();
57: }
58: return fElement;
59: }
60:
61: /**
62: * Resolves the member described by the receiver and returns it if found.
63: * Returns <code>null</code> if no corresponding member can be found.
64: *
65: * @return the resolved member or <code>null</code> if none is found
66: * @throws JavaModelException if accessing the java model fails
67: */
68: protected abstract IMember resolveMember()
69: throws JavaModelException;
70:
71: }
|