]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / text / java / ProposalInfo.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2010 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.ui.text.java;
12
13import org.eclipse.core.runtime.IProgressMonitor;
14
15import org.eclipse.jdt.core.CompletionProposal;
16import org.eclipse.jdt.core.IJavaElement;
17import org.eclipse.jdt.core.IMember;
18import org.eclipse.jdt.core.JavaModelException;
19
20import org.eclipse.jdt.internal.ui.JavaPlugin;
21import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
22
23
24public class ProposalInfo {
25
26 private boolean fJavadocResolved= false;
27 private String fJavadoc= null;
28
29 protected IJavaElement fElement;
30
31 public ProposalInfo(IMember member) {
32 fElement= member;
33 }
34
35 protected ProposalInfo() {
36 fElement= null;
37 }
38
39 /**
40 * Returns the Java element.
41 *
42 * @throws JavaModelException if accessing the java model fails
43 * @return the Java element
44 */
45 public IJavaElement getJavaElement() throws JavaModelException {
46 return fElement;
47 }
48
49 /**
50 * Gets the text for this proposal info formatted as HTML, or
51 * <code>null</code> if no text is available.
52 *
53 * @param monitor a progress monitor
54 * @return the additional info text
55 */
56 public final String getInfo(IProgressMonitor monitor) {
57 if (!fJavadocResolved) {
58 fJavadocResolved= true;
59 fJavadoc= computeInfo(monitor);
60 }
61 return fJavadoc;
62 }
63
64 /**
65 * Gets the text for this proposal info formatted as HTML, or
66 * <code>null</code> if no text is available.
67 *
68 * @param monitor a progress monitor
69 * @return the additional info text
70 */
71 private String computeInfo(IProgressMonitor monitor) {
72 try {
73 final IJavaElement javaElement= getJavaElement();
74 if (javaElement instanceof IMember) {
75 IMember member= (IMember) javaElement;
76 return extractJavadoc(member, monitor);
77 }
78 } catch (JavaModelException e) {
79 JavaPlugin.log(e);
80 }
81 return null;
82 }
83
84 /**
85 * Extracts the javadoc for the given <code>IMember</code> and returns it
86 * as HTML.
87 *
88 * @param member the member to get the documentation for
89 * @param monitor a progress monitor
90 * @return the javadoc for <code>member</code> or <code>null</code> if
91 * it is not available
92 * @throws JavaModelException if accessing the javadoc fails
93 */
94 private String extractJavadoc(IMember member, IProgressMonitor monitor) throws JavaModelException {
95 if (member != null) {
96 return JavadocContentAccess2.getHTMLContent(member, true);
97 }
98 return null;
99 }
100
101 public boolean generated_5860057895832307195(AbstractJavaCompletionProposal abstractjavacompletionproposal) {
102 if (!(this instanceof MemberProposalInfo || this instanceof AnonymousTypeProposalInfo))
103 return false;
104
105 CompletionProposal proposal= ((MemberProposalInfo)this).fProposal;
106 return proposal != null && (proposal.getKind() == CompletionProposal.METHOD_REF || proposal.getKind() == CompletionProposal.FIELD_REF || proposal.getKind() == CompletionProposal.TYPE_REF || proposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION);
107 }
108
109}