KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > FieldProposalInfo


1 /*******************************************************************************
2  * Copyright (c) 2005 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.jdt.internal.ui.text.java;
12
13 import org.eclipse.jdt.core.CompletionProposal;
14 import org.eclipse.jdt.core.IField;
15 import org.eclipse.jdt.core.IJavaProject;
16 import org.eclipse.jdt.core.IMember;
17 import org.eclipse.jdt.core.IType;
18 import org.eclipse.jdt.core.JavaModelException;
19
20 import org.eclipse.jdt.internal.corext.template.java.SignatureUtil;
21
22
23 /**
24  * Proposal info that computes the javadoc lazily when it is queried.
25  *
26  * @since 3.1
27  */

28 public final class FieldProposalInfo extends MemberProposalInfo {
29
30     /**
31      * Creates a new proposal info.
32      *
33      * @param project the java project to reference when resolving types
34      * @param proposal the proposal to generate information for
35      */

36     public FieldProposalInfo(IJavaProject project, CompletionProposal proposal) {
37         super(project, proposal);
38     }
39
40     /**
41      * Resolves the member described by the receiver and returns it if found.
42      * Returns <code>null</code> if no corresponding member can be found.
43      *
44      * @return the resolved member or <code>null</code> if none is found
45      * @throws JavaModelException if accessing the java model fails
46      */

47     protected IMember resolveMember() throws JavaModelException {
48         char[] declarationSignature= fProposal.getDeclarationSignature();
49         // for synthetic fields on arrays, declaration signatures may be null
50
// TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
51
if (declarationSignature == null)
52             return null;
53         String JavaDoc typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
54         IType type= fJavaProject.findType(typeName);
55         if (type != null) {
56             String JavaDoc name= String.valueOf(fProposal.getName());
57             IField field= type.getField(name);
58             if (field.exists())
59                 return field;
60         }
61
62         return null;
63     }
64 }
65
Popular Tags