Source Code Cross Referenced for ManifestContentAssistProcessor.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » contentassist » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.ui.editor.contentassist 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*******************************************************************************
0002:         * Copyright (c) 2006, 2007 IBM Corporation and others.
0003:         * All rights reserved. This program and the accompanying materials
0004:         * are made available under the terms of the Eclipse Public License v1.0
0005:         * which accompanies this distribution, and is available at
0006:         * http://www.eclipse.org/legal/epl-v10.html
0007:         *
0008:         * Contributors:
0009:         *     IBM Corporation - initial API and implementation
0010:         *     Brock Janiczak (brockj@tpg.com.au) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=197410
0011:         *******************************************************************************/package org.eclipse.pde.internal.ui.editor.contentassist;
0012:
0013:        import java.util.ArrayList;
0014:        import java.util.Arrays;
0015:        import java.util.Collection;
0016:        import java.util.Comparator;
0017:        import java.util.HashMap;
0018:        import java.util.HashSet;
0019:        import java.util.Map;
0020:        import java.util.StringTokenizer;
0021:
0022:        import org.eclipse.core.resources.IProject;
0023:        import org.eclipse.jdt.core.IJavaProject;
0024:        import org.eclipse.jdt.core.IPackageFragment;
0025:        import org.eclipse.jdt.core.JavaCore;
0026:        import org.eclipse.jdt.core.search.IJavaSearchConstants;
0027:        import org.eclipse.jdt.launching.JavaRuntime;
0028:        import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
0029:        import org.eclipse.jface.resource.ImageDescriptor;
0030:        import org.eclipse.jface.text.BadLocationException;
0031:        import org.eclipse.jface.text.IDocument;
0032:        import org.eclipse.jface.text.IRegion;
0033:        import org.eclipse.jface.text.ITextViewer;
0034:        import org.eclipse.jface.text.contentassist.ContentAssistEvent;
0035:        import org.eclipse.jface.text.contentassist.ICompletionListener;
0036:        import org.eclipse.jface.text.contentassist.ICompletionProposal;
0037:        import org.eclipse.osgi.service.resolver.BundleDescription;
0038:        import org.eclipse.osgi.service.resolver.ExportPackageDescription;
0039:        import org.eclipse.osgi.util.ManifestElement;
0040:        import org.eclipse.pde.core.IBaseModel;
0041:        import org.eclipse.pde.core.plugin.IPluginModelBase;
0042:        import org.eclipse.pde.core.plugin.ModelEntry;
0043:        import org.eclipse.pde.core.plugin.PluginRegistry;
0044:        import org.eclipse.pde.internal.core.ICoreConstants;
0045:        import org.eclipse.pde.internal.core.ibundle.IBundleModel;
0046:        import org.eclipse.pde.internal.core.util.HeaderMap;
0047:        import org.eclipse.pde.internal.core.util.PDEJavaHelper;
0048:        import org.eclipse.pde.internal.ui.PDEPluginImages;
0049:        import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
0050:        import org.eclipse.pde.internal.ui.editor.PDESourcePage;
0051:        import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
0052:        import org.eclipse.pde.internal.ui.util.ImageOverlayIcon;
0053:        import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI;
0054:        import org.eclipse.swt.graphics.Image;
0055:        import org.osgi.framework.BundleException;
0056:        import org.osgi.framework.Constants;
0057:        import org.osgi.framework.Version;
0058:
0059:        public class ManifestContentAssistProcessor extends
0060:                TypePackageCompletionProcessor implements  ICompletionListener {
0061:
0062:            protected PDESourcePage fSourcePage;
0063:            private IJavaProject fJP;
0064:
0065:            // if we order the headers alphabetically in the array, there is no need to sort and we can save time
0066:            private static final String[] fHeader = {
0067:                    Constants.BUNDLE_ACTIVATIONPOLICY,
0068:                    Constants.BUNDLE_ACTIVATOR, Constants.BUNDLE_CATEGORY,
0069:                    Constants.BUNDLE_CLASSPATH,
0070:                    Constants.BUNDLE_CONTACTADDRESS,
0071:                    Constants.BUNDLE_COPYRIGHT, Constants.BUNDLE_DESCRIPTION,
0072:                    Constants.BUNDLE_DOCURL, Constants.BUNDLE_LOCALIZATION,
0073:                    Constants.BUNDLE_MANIFESTVERSION, Constants.BUNDLE_NAME,
0074:                    Constants.BUNDLE_NATIVECODE,
0075:                    Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,
0076:                    Constants.BUNDLE_SYMBOLICNAME,
0077:                    Constants.BUNDLE_UPDATELOCATION, Constants.BUNDLE_VENDOR,
0078:                    Constants.BUNDLE_VERSION, Constants.DYNAMICIMPORT_PACKAGE,
0079:                    ICoreConstants.ECLIPSE_BUDDY_POLICY,
0080:                    ICoreConstants.ECLIPSE_GENERIC_CAPABILITY,
0081:                    ICoreConstants.ECLIPSE_GENERIC_REQUIRED,
0082:                    ICoreConstants.ECLIPSE_LAZYSTART,
0083:                    ICoreConstants.PLATFORM_FILTER,
0084:                    ICoreConstants.ECLIPSE_REGISTER_BUDDY,
0085:                    Constants.EXPORT_PACKAGE, ICoreConstants.EXPORT_SERVICE,
0086:                    Constants.FRAGMENT_HOST, Constants.IMPORT_PACKAGE,
0087:                    ICoreConstants.IMPORT_SERVICE, Constants.REQUIRE_BUNDLE };
0088:
0089:            private static final String BAUMAN = "Brian Bauman"; //$NON-NLS-1$
0090:            private static final String ANISZCZYK = "Chris Aniszczyk"; //$NON-NLS-1$
0091:            private static final String LASOCKI_BICZYSKO = "Janek Lasocki-Biczysko"; //$NON-NLS-1$
0092:            private static final String PAWLOWSKI = "Mike Pawlowski"; //$NON-NLS-1$
0093:            private static final String MELHEM = "Wassim Melhem"; //$NON-NLS-1$
0094:
0095:            private static final String[] fNames = { BAUMAN, ANISZCZYK,
0096:                    LASOCKI_BICZYSKO, PAWLOWSKI, MELHEM };
0097:
0098:            protected static final short F_TYPE_HEADER = 0, // header proposal
0099:                    F_TYPE_PKG = 1, // package proposal
0100:                    F_TYPE_BUNDLE = 2, // bundle proposal
0101:                    F_TYPE_CLASS = 3, // class proposal
0102:                    F_TYPE_DIRECTIVE = 4, // directive proposal
0103:                    F_TYPE_ATTRIBUTE = 5, // attribute proposal
0104:                    F_TYPE_VALUE = 6, // value of attribute or directive proposal
0105:                    F_TYPE_EXEC_ENV = 7, // value of execution env., added since we use a unique icon for exec envs.
0106:
0107:                    F_TOTAL_TYPES = 8;
0108:
0109:            private final Image[] fImages = new Image[F_TOTAL_TYPES];
0110:
0111:            private static final String[] fExecEnvs;
0112:            static {
0113:                IExecutionEnvironment[] envs = JavaRuntime
0114:                        .getExecutionEnvironmentsManager()
0115:                        .getExecutionEnvironments();
0116:                fExecEnvs = new String[envs.length];
0117:                for (int i = 0; i < envs.length; i++)
0118:                    fExecEnvs[i] = envs[i].getId();
0119:                Arrays.sort(fExecEnvs, new Comparator() {
0120:                    public int compare(Object o1, Object o2) {
0121:                        return ((String) o1).compareToIgnoreCase((String) o2);
0122:                    }
0123:                });
0124:            }
0125:
0126:            Map fHeaders;
0127:
0128:            public ManifestContentAssistProcessor(PDESourcePage sourcePage) {
0129:                fSourcePage = sourcePage;
0130:            }
0131:
0132:            public ICompletionProposal[] computeCompletionProposals(
0133:                    ITextViewer viewer, int offset) {
0134:                IDocument doc = fSourcePage.getDocumentProvider().getDocument(
0135:                        fSourcePage.getInputContext().getInput());
0136:                if (fHeaders == null) {
0137:                    parseDocument(doc);
0138:                }
0139:                try {
0140:                    int lineNum = doc.getLineOfOffset(offset);
0141:                    int lineStart = doc.getLineOffset(lineNum);
0142:                    return computeCompletionProposals(doc, lineStart, offset);
0143:                } catch (BadLocationException e) {
0144:                }
0145:                return null;
0146:            }
0147:
0148:            protected final void parseDocument(IDocument doc) {
0149:                fHeaders = new HeaderMap();
0150:                int numLines = doc.getNumberOfLines();
0151:                int offset = 0;
0152:                for (int i = 0; i < numLines; i++) {
0153:                    try {
0154:                        IRegion line = doc.getLineInformation(i);
0155:                        String value = doc.get(offset, line.getOffset()
0156:                                + line.getLength() - offset);
0157:                        if (value.indexOf(':') != value.lastIndexOf(':')
0158:                                || i == (numLines - 1)) {
0159:                            value = doc.get(offset,
0160:                                    line.getOffset() - offset - 1).trim();
0161:                            int index = value.indexOf(':');
0162:                            String header = (index == -1) ? value : value
0163:                                    .substring(0, index);
0164:                            try {
0165:                                if (value.endsWith(",")) //$NON-NLS-1$
0166:                                    value = value.substring(0,
0167:                                            value.length() - 1);
0168:                                ManifestElement[] elems = ManifestElement
0169:                                        .parseHeader(header, value
0170:                                                .substring(index + 1));
0171:                                if (shouldStoreSet(header)) {
0172:                                    HashSet set = new HashSet((4 / 3)
0173:                                            * elems.length + 1);
0174:                                    for (int j = 0; j < elems.length; j++)
0175:                                        set.add(elems[j].getValue());
0176:                                    fHeaders.put(header, set);
0177:                                } else
0178:                                    fHeaders.put(header, elems);
0179:                            } catch (BundleException e) {
0180:                            }
0181:                            offset = line.getOffset();
0182:                        }
0183:                    } catch (BadLocationException e) {
0184:                    }
0185:                }
0186:            }
0187:
0188:            protected final boolean shouldStoreSet(String header) {
0189:                return header.equalsIgnoreCase(Constants.IMPORT_PACKAGE)
0190:                        || header.equalsIgnoreCase(Constants.EXPORT_PACKAGE)
0191:                        || header.equalsIgnoreCase(Constants.REQUIRE_BUNDLE)
0192:                        || header
0193:                                .equalsIgnoreCase(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
0194:            }
0195:
0196:            protected ICompletionProposal[] computeCompletionProposals(
0197:                    IDocument doc, int startOffset, int offset) {
0198:                try {
0199:                    if (!isHeader(doc, startOffset, offset))
0200:                        return computeValue(doc, startOffset, offset);
0201:                    return computeHeader(doc.get(startOffset, offset
0202:                            - startOffset), startOffset, offset);
0203:                } catch (BadLocationException e) {
0204:                }
0205:                return new ICompletionProposal[0];
0206:            }
0207:
0208:            protected final boolean isHeader(IDocument doc, int startOffset,
0209:                    int offset) throws BadLocationException {
0210:                String value = doc.get(startOffset, offset - startOffset);
0211:                if (value.indexOf(':') != -1)
0212:                    return false;
0213:                for (--startOffset; startOffset >= 0; --startOffset) {
0214:                    char ch = doc.getChar(startOffset);
0215:                    if (!Character.isWhitespace(ch))
0216:                        return ch != ',' && ch != ':' && ch != ';';
0217:                }
0218:                return true;
0219:            }
0220:
0221:            protected ICompletionProposal[] computeHeader(String currentValue,
0222:                    int startOffset, int offset) {
0223:                ArrayList completions = new ArrayList();
0224:                IBaseModel model = fSourcePage.getInputContext().getModel();
0225:                int length = fHeader.length;
0226:                if (model instanceof  IBundleModel
0227:                        && !((IBundleModel) model).isFragmentModel())
0228:                    --length;
0229:                for (int i = 0; i < fHeader.length; i++) {
0230:                    if (fHeader[i].regionMatches(true, 0, currentValue, 0,
0231:                            currentValue.length())
0232:                            && fHeaders.get(fHeader[i]) == null) {
0233:                        TypeCompletionProposal proposal = new TypeCompletionProposal(
0234:                                fHeader[i] + ": ", getImage(F_TYPE_HEADER), //$NON-NLS-1$
0235:                                fHeader[i], startOffset, currentValue.length());
0236:                        proposal
0237:                                .setAdditionalProposalInfo(getJavaDoc(fHeader[i]));
0238:                        completions.add(proposal); //$NON-NLS-1$
0239:                    }
0240:                }
0241:                return (ICompletionProposal[]) completions
0242:                        .toArray(new ICompletionProposal[completions.size()]);
0243:            }
0244:
0245:            protected ICompletionProposal[] computeValue(IDocument doc,
0246:                    int startOffset, int offset) throws BadLocationException {
0247:                String value = doc.get(startOffset, offset - startOffset);
0248:                int lineNum = doc.getLineOfOffset(startOffset) - 1;
0249:                int index;
0250:                while ((index = value.indexOf(':')) == -1
0251:                        || ((value.length() - 1 != index) && (value
0252:                                .charAt(index + 1) == '='))) {
0253:                    int startLine = doc.getLineOffset(lineNum);
0254:                    value = doc.get(startLine, offset - startLine);
0255:                    lineNum--;
0256:                }
0257:
0258:                int length = value.length();
0259:                if (value.regionMatches(true, 0, Constants.IMPORT_PACKAGE, 0,
0260:                        Math.min(length, Constants.IMPORT_PACKAGE.length())))
0261:                    return handleImportPackageCompletion(value
0262:                            .substring(Constants.IMPORT_PACKAGE.length() + 1),
0263:                            offset);
0264:                if (value.regionMatches(true, 0, Constants.FRAGMENT_HOST, 0,
0265:                        Math.min(length, Constants.FRAGMENT_HOST.length())))
0266:                    return handleFragmentHostCompletion(value
0267:                            .substring(Constants.FRAGMENT_HOST.length() + 1),
0268:                            offset);
0269:                if (value.regionMatches(true, 0, Constants.REQUIRE_BUNDLE, 0,
0270:                        Math.min(length, Constants.REQUIRE_BUNDLE.length())))
0271:                    return handleRequireBundleCompletion(value
0272:                            .substring(Constants.REQUIRE_BUNDLE.length() + 1),
0273:                            offset);
0274:                if (value.regionMatches(true, 0, Constants.EXPORT_PACKAGE, 0,
0275:                        Math.min(length, Constants.EXPORT_PACKAGE.length())))
0276:                    return handleExportPackageCompletion(value
0277:                            .substring(Constants.EXPORT_PACKAGE.length() + 1),
0278:                            offset);
0279:                if (value.regionMatches(true, 0, Constants.BUNDLE_ACTIVATOR, 0,
0280:                        Math.min(length, Constants.BUNDLE_ACTIVATOR.length())))
0281:                    return handleBundleActivatorCompletion(
0282:                            removeLeadingSpaces(value
0283:                                    .substring(Constants.BUNDLE_ACTIVATOR
0284:                                            .length() + 1)), offset);
0285:                if (value.regionMatches(true, 0, Constants.BUNDLE_SYMBOLICNAME,
0286:                        0, Math.min(length, Constants.BUNDLE_SYMBOLICNAME
0287:                                .length())))
0288:                    return handleBundleSymbolicNameCompletion(
0289:                            value.substring(Constants.BUNDLE_SYMBOLICNAME
0290:                                    .length() + 1), offset);
0291:                if (value.regionMatches(true, 0,
0292:                        Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, 0,
0293:                        Math.min(length,
0294:                                Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT
0295:                                        .length())))
0296:                    return handleRequiredExecEnv(
0297:                            value
0298:                                    .substring(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT
0299:                                            .length() + 1), offset);
0300:                if (value.regionMatches(true, 0,
0301:                        ICoreConstants.ECLIPSE_LAZYSTART, 0, Math.min(length,
0302:                                ICoreConstants.ECLIPSE_LAZYSTART.length())))
0303:                    return handleTrueFalseValue(value
0304:                            .substring(ICoreConstants.ECLIPSE_LAZYSTART
0305:                                    .length() + 1), offset);
0306:                if (value.regionMatches(true, 0, Constants.BUNDLE_NAME, 0, Math
0307:                        .min(length, Constants.BUNDLE_NAME.length())))
0308:                    return handleBundleNameCompletion(value
0309:                            .substring(Constants.BUNDLE_NAME.length() + 1),
0310:                            offset);
0311:                if (value.regionMatches(true, 0,
0312:                        Constants.BUNDLE_ACTIVATIONPOLICY, 0, Math.min(length,
0313:                                Constants.BUNDLE_ACTIVATIONPOLICY.length())))
0314:                    return handleBundleActivationPolicyCompletion(value
0315:                            .substring(Constants.BUNDLE_ACTIVATIONPOLICY
0316:                                    .length() + 1), offset);
0317:                if (value.regionMatches(true, 0,
0318:                        ICoreConstants.ECLIPSE_BUDDY_POLICY, 0, Math.min(
0319:                                length, ICoreConstants.ECLIPSE_BUDDY_POLICY
0320:                                        .length())))
0321:                    return handleBuddyPolicyCompletion(value
0322:                            .substring(ICoreConstants.ECLIPSE_BUDDY_POLICY
0323:                                    .length() + 1), offset);
0324:                return new ICompletionProposal[0];
0325:            }
0326:
0327:            /*
0328:             * Easter Egg
0329:             */
0330:            protected ICompletionProposal[] handleBundleNameCompletion(
0331:                    String currentValue, int offset) {
0332:                currentValue = removeLeadingSpaces(currentValue);
0333:                int length = currentValue.length();
0334:
0335:                // only show when there is no bundle name
0336:                if (length == 0) {
0337:                    return new ICompletionProposal[] {
0338:                            new TypeCompletionProposal(BAUMAN, null, BAUMAN,
0339:                                    offset - length, length),
0340:                            new TypeCompletionProposal(ANISZCZYK, null,
0341:                                    ANISZCZYK, offset - length, length),
0342:                            new TypeCompletionProposal(LASOCKI_BICZYSKO, null,
0343:                                    LASOCKI_BICZYSKO, offset - length, length),
0344:                            new TypeCompletionProposal(PAWLOWSKI, null,
0345:                                    PAWLOWSKI, offset - length, length),
0346:                            new TypeCompletionProposal(MELHEM, null, MELHEM,
0347:                                    offset - length, length) };
0348:                }
0349:
0350:                // only show when we are trying to complete a name
0351:                for (int i = 0; i < fNames.length; i++) {
0352:                    StringTokenizer tokenizer = new StringTokenizer(
0353:                            currentValue, " "); //$NON-NLS-1$
0354:                    while (tokenizer.hasMoreTokens()) {
0355:                        String token = tokenizer.nextToken();
0356:                        if (fNames[i].regionMatches(true, 0, token, 0, token
0357:                                .length())) {
0358:                            return new ICompletionProposal[] { new TypeCompletionProposal(
0359:                                    fNames[i], null, fNames[i], offset
0360:                                            - token.length(), token.length()) };
0361:                        }
0362:                    }
0363:                }
0364:                return new ICompletionProposal[0];
0365:            }
0366:
0367:            protected ICompletionProposal[] handleImportPackageCompletion(
0368:                    String currentValue, int offset) {
0369:                int comma = currentValue.lastIndexOf(',');
0370:                int semicolon = currentValue.lastIndexOf(';');
0371:                String value = comma != -1 ? currentValue.substring(comma + 1)
0372:                        : currentValue;
0373:                if (comma > semicolon || comma == semicolon) {
0374:                    HashSet set = (HashSet) fHeaders
0375:                            .get(Constants.IMPORT_PACKAGE);
0376:                    if (set == null)
0377:                        set = parseHeaderForValues(currentValue, offset);
0378:                    HashSet importedBundles = (HashSet) fHeaders
0379:                            .get(Constants.REQUIRE_BUNDLE);
0380:                    if (importedBundles == null)
0381:                        importedBundles = new HashSet(0);
0382:                    value = removeLeadingSpaces(value);
0383:                    int length = value.length();
0384:                    set.remove(value);
0385:                    ArrayList completions = new ArrayList();
0386:                    IPluginModelBase[] bases = PluginRegistry.getActiveModels();
0387:
0388:                    for (int j = 0; j < bases.length; j++) { // Remove any packages already imported through Require-Bundle
0389:                        BundleDescription desc = bases[j]
0390:                                .getBundleDescription();
0391:                        if (desc == null
0392:                                || importedBundles.contains(desc
0393:                                        .getSymbolicName()))
0394:                            continue;
0395:                        ExportPackageDescription[] expPkgs = desc
0396:                                .getExportPackages();
0397:                        for (int i = 0; i < expPkgs.length; i++) {
0398:                            String pkgName = expPkgs[i].getName();
0399:                            if (pkgName
0400:                                    .regionMatches(true, 0, value, 0, length)
0401:                                    && !set.contains(pkgName)) {
0402:                                completions.add(new TypeCompletionProposal(
0403:                                        pkgName, getImage(F_TYPE_PKG), pkgName,
0404:                                        offset - length, length));
0405:                                set.add(pkgName);
0406:                            }
0407:                        }
0408:                    }
0409:                    ICompletionProposal[] proposals = (ICompletionProposal[]) completions
0410:                            .toArray(new ICompletionProposal[completions.size()]);
0411:                    sortCompletions(proposals);
0412:                    return proposals;
0413:                }
0414:                int equals = currentValue.lastIndexOf('=');
0415:                if (equals == -1 || semicolon > equals) {
0416:                    String[] validAtts = new String[] {
0417:                            Constants.RESOLUTION_DIRECTIVE,
0418:                            Constants.VERSION_ATTRIBUTE };
0419:                    Integer[] validTypes = new Integer[] {
0420:                            new Integer(F_TYPE_DIRECTIVE),
0421:                            new Integer(F_TYPE_ATTRIBUTE) };
0422:                    return handleAttrsAndDirectives(value,
0423:                            initializeNewList(validAtts),
0424:                            initializeNewList(validTypes), offset);
0425:                }
0426:                String attributeValue = removeLeadingSpaces(currentValue
0427:                        .substring(semicolon + 1));
0428:                if (Constants.RESOLUTION_DIRECTIVE.regionMatches(true, 0,
0429:                        attributeValue, 0, Constants.RESOLUTION_DIRECTIVE
0430:                                .length()))
0431:                    return matchValueCompletion(currentValue
0432:                            .substring(equals + 1), new String[] {
0433:                            Constants.RESOLUTION_MANDATORY,
0434:                            Constants.RESOLUTION_OPTIONAL }, new int[] {
0435:                            F_TYPE_VALUE, F_TYPE_VALUE }, offset, "RESOLUTION_"); //$NON-NLS-1$
0436:                if (Constants.VERSION_ATTRIBUTE
0437:                        .regionMatches(true, 0, attributeValue, 0,
0438:                                Constants.VERSION_ATTRIBUTE.length())) {
0439:                    value = removeLeadingSpaces(currentValue
0440:                            .substring(equals + 1));
0441:                    if (value.length() == 0)
0442:                        return new ICompletionProposal[] { new TypeCompletionProposal(
0443:                                "\"\"", getImage(F_TYPE_VALUE), "\"\"", offset, 0) }; //$NON-NLS-1$ //$NON-NLS-2$
0444:                }
0445:                return new ICompletionProposal[0];
0446:            }
0447:
0448:            private ICompletionProposal[] handleXFriendsCompletion(
0449:                    String value, final int offset) {
0450:                ManifestElement[] elems = (ManifestElement[]) fHeaders
0451:                        .get(Constants.BUNDLE_SYMBOLICNAME);
0452:                HashSet set = new HashSet();
0453:                if (elems != null && elems.length > 0)
0454:                    set.add(elems[0].getValue());
0455:                value = removeLeadingSpaces(value);
0456:                if (value.length() == 0)
0457:                    return new ICompletionProposal[] { new TypeCompletionProposal(
0458:                            "\"\"", getImage(F_TYPE_VALUE), "\"\"", offset, 0) }; //$NON-NLS-1$ //$NON-NLS-2$
0459:                if (value.charAt(0) == '"')
0460:                    value = value.substring(1);
0461:                int index = value.lastIndexOf(',');
0462:                StringTokenizer tokenizer = new StringTokenizer(value, ","); //$NON-NLS-1$
0463:                while (tokenizer.hasMoreTokens())
0464:                    set.add(tokenizer.nextToken());
0465:                return handleBundleCompletions(value
0466:                        .substring((index == -1) ? 0 : index + 1), set,
0467:                        F_TYPE_VALUE, offset, true);
0468:            }
0469:
0470:            protected ICompletionProposal[] handleFragmentHostCompletion(
0471:                    String currentValue, int offset) {
0472:                int index = currentValue.lastIndexOf(';');
0473:                if (index == -1) {
0474:                    HashMap completions = new HashMap();
0475:                    IPluginModelBase base = PluginRegistry
0476:                            .findModel(((ManifestEditor) fSourcePage
0477:                                    .getEditor()).getCommonProject());
0478:                    BundleDescription desc = base.getBundleDescription();
0479:                    String currentId = desc != null ? desc.getSymbolicName()
0480:                            : null;
0481:
0482:                    String pluginStart = removeLeadingSpaces(currentValue);
0483:                    int length = pluginStart.length();
0484:                    IPluginModelBase[] bases = PluginRegistry.getActiveModels();
0485:                    for (int i = 0; i < bases.length; i++) {
0486:                        desc = bases[i].getBundleDescription();
0487:                        if (desc != null && desc.getHost() == null) {
0488:                            String pluginID = bases[i].getBundleDescription()
0489:                                    .getSymbolicName();
0490:                            if (!completions.containsKey(pluginID)
0491:                                    && pluginID.regionMatches(true, 0,
0492:                                            pluginStart, 0, length)
0493:                                    && !pluginID.equals(currentId))
0494:                                completions.put(pluginID,
0495:                                        new TypeCompletionProposal(pluginID,
0496:                                                getImage(F_TYPE_BUNDLE),
0497:                                                pluginID, offset - length,
0498:                                                length));
0499:                        }
0500:                    }
0501:                    return (ICompletionProposal[]) completions
0502:                            .values()
0503:                            .toArray(
0504:                                    new ICompletionProposal[completions.size()]);
0505:                }
0506:                int equals = currentValue.lastIndexOf('=');
0507:                if (equals == -1 || index > equals)
0508:                    return matchValueCompletion(
0509:                            removeLeadingSpaces(currentValue
0510:                                    .substring(index + 1)),
0511:                            new String[] { Constants.BUNDLE_VERSION_ATTRIBUTE },
0512:                            new int[] { F_TYPE_ATTRIBUTE }, offset);
0513:                String attributeValue = removeLeadingSpaces(currentValue
0514:                        .substring(index + 1));
0515:                if (Constants.BUNDLE_VERSION_ATTRIBUTE.regionMatches(true, 0,
0516:                        attributeValue, 0, Constants.BUNDLE_VERSION_ATTRIBUTE
0517:                                .length())) {
0518:                    return getBundleVersionCompletions(currentValue.substring(
0519:                            0, index).trim(), removeLeadingSpaces(currentValue
0520:                            .substring(equals + 1)), offset);
0521:                }
0522:                return new ICompletionProposal[0];
0523:            }
0524:
0525:            protected ICompletionProposal[] handleRequireBundleCompletion(
0526:                    String currentValue, int offset) {
0527:                int comma = currentValue.lastIndexOf(',');
0528:                int semicolon = currentValue.lastIndexOf(';');
0529:                String value = comma != -1 ? currentValue.substring(comma + 1)
0530:                        : currentValue;
0531:                if (comma > semicolon || comma == semicolon) {
0532:                    HashSet set = (HashSet) fHeaders
0533:                            .get(Constants.REQUIRE_BUNDLE);
0534:                    if (set == null)
0535:                        set = parseHeaderForValues(currentValue, offset);
0536:                    return handleBundleCompletions(value, set, F_TYPE_BUNDLE,
0537:                            offset, false);
0538:                }
0539:                int equals = currentValue.lastIndexOf('=');
0540:                if (equals == -1 || semicolon > equals) {
0541:                    String[] validAttrs = new String[] {
0542:                            Constants.BUNDLE_VERSION_ATTRIBUTE,
0543:                            Constants.RESOLUTION_DIRECTIVE,
0544:                            Constants.VISIBILITY_DIRECTIVE };
0545:                    Integer[] validTypes = new Integer[] {
0546:                            new Integer(F_TYPE_ATTRIBUTE),
0547:                            new Integer(F_TYPE_DIRECTIVE),
0548:                            new Integer(F_TYPE_DIRECTIVE) };
0549:                    return handleAttrsAndDirectives(value,
0550:                            initializeNewList(validAttrs),
0551:                            initializeNewList(validTypes), offset);
0552:                }
0553:                String attributeValue = removeLeadingSpaces(currentValue
0554:                        .substring(semicolon + 1));
0555:                if (Constants.VISIBILITY_DIRECTIVE.regionMatches(true, 0,
0556:                        attributeValue, 0, Constants.VISIBILITY_DIRECTIVE
0557:                                .length()))
0558:                    return matchValueCompletion(currentValue
0559:                            .substring(equals + 1), new String[] {
0560:                            Constants.VISIBILITY_PRIVATE,
0561:                            Constants.VISIBILITY_REEXPORT }, new int[] {
0562:                            F_TYPE_VALUE, F_TYPE_VALUE }, offset, "VISIBILITY_"); //$NON-NLS-1$
0563:                if (Constants.RESOLUTION_DIRECTIVE.regionMatches(true, 0,
0564:                        attributeValue, 0, Constants.RESOLUTION_DIRECTIVE
0565:                                .length()))
0566:                    return matchValueCompletion(currentValue
0567:                            .substring(equals + 1), new String[] {
0568:                            Constants.RESOLUTION_MANDATORY,
0569:                            Constants.RESOLUTION_OPTIONAL }, new int[] {
0570:                            F_TYPE_VALUE, F_TYPE_VALUE }, offset, "RESOLUTION_"); //$NON-NLS-1$
0571:                if (Constants.BUNDLE_VERSION_ATTRIBUTE.regionMatches(true, 0,
0572:                        attributeValue, 0, Constants.RESOLUTION_DIRECTIVE
0573:                                .length())) {
0574:                    String pluginId = removeLeadingSpaces(currentValue
0575:                            .substring((comma == -1) ? 0 : comma + 1, semicolon));
0576:                    return getBundleVersionCompletions(pluginId,
0577:                            removeLeadingSpaces(currentValue
0578:                                    .substring(equals + 1)), offset);
0579:                }
0580:                return new ICompletionProposal[0];
0581:            }
0582:
0583:            private ICompletionProposal[] getBundleVersionCompletions(
0584:                    String pluginID, String existingValue, int offset) {
0585:                ModelEntry entry = PluginRegistry.findEntry(pluginID);
0586:                if (entry != null) {
0587:                    IPluginModelBase[] hosts = entry.getActiveModels();
0588:                    ArrayList proposals = new ArrayList(hosts.length);
0589:                    for (int i = 0; i < hosts.length; i++) {
0590:                        String proposalValue = getVersionProposal(hosts[i]);
0591:                        if (proposalValue.regionMatches(0, existingValue, 0,
0592:                                existingValue.length()))
0593:                            proposals.add(new TypeCompletionProposal(
0594:                                    proposalValue.substring(existingValue
0595:                                            .length()), getImage(F_TYPE_VALUE),
0596:                                    proposalValue, offset, 0));
0597:                    }
0598:                    return (ICompletionProposal[]) proposals
0599:                            .toArray(new ICompletionProposal[proposals.size()]);
0600:                } else if (existingValue.length() == 0)
0601:                    return new ICompletionProposal[] { new TypeCompletionProposal(
0602:                            "\"\"", getImage(F_TYPE_VALUE), "\"\"", offset, 0) }; //$NON-NLS-1$ //$NON-NLS-2$
0603:                return new ICompletionProposal[0];
0604:            }
0605:
0606:            private String getVersionProposal(IPluginModelBase base) {
0607:                StringBuffer buffer = new StringBuffer("\""); //$NON-NLS-1$
0608:                BundleDescription desc = base.getBundleDescription();
0609:                if (desc != null) {
0610:                    Version version = desc.getVersion();
0611:                    buffer.append(version.getMajor());
0612:                    buffer.append('.');
0613:                    buffer.append(version.getMinor());
0614:                    buffer.append('.');
0615:                    buffer.append(version.getMicro());
0616:                } else {
0617:                    char[] chars = base.getPluginBase().getVersion()
0618:                            .toCharArray();
0619:                    int periodCount = 0;
0620:                    for (int i = 0; i < chars.length; i++) {
0621:                        if (chars[i] == '.') {
0622:                            if (periodCount == 2)
0623:                                break;
0624:                            ++periodCount;
0625:                        }
0626:                        buffer.append(chars[i]);
0627:                    }
0628:                }
0629:                return buffer.append('\"').toString();
0630:            }
0631:
0632:            private ICompletionProposal[] handleBundleCompletions(String value,
0633:                    Collection doNotInclude, int type, int offset,
0634:                    boolean includeFragments) {
0635:                value = removeLeadingSpaces(value);
0636:                int length = value.length();
0637:                doNotInclude.remove(value);
0638:                ArrayList completions = new ArrayList();
0639:                IPluginModelBase[] bases = PluginRegistry.getActiveModels();
0640:                for (int i = 0; i < bases.length; i++) {
0641:                    BundleDescription desc = bases[i].getBundleDescription();
0642:                    if (desc != null) {
0643:                        if (!includeFragments && desc.getHost() != null)
0644:                            continue;
0645:                        String bundleId = desc.getSymbolicName();
0646:                        if (bundleId.regionMatches(true, 0, value, 0, value
0647:                                .length())
0648:                                && !doNotInclude.contains(bundleId))
0649:                            completions.add(new TypeCompletionProposal(
0650:                                    bundleId, getImage(type), bundleId, offset
0651:                                            - length, length));
0652:                    }
0653:                }
0654:                return (ICompletionProposal[]) completions
0655:                        .toArray(new ICompletionProposal[completions.size()]);
0656:            }
0657:
0658:            protected ICompletionProposal[] handleExportPackageCompletion(
0659:                    String currentValue, int offset) {
0660:                int comma = currentValue.lastIndexOf(',');
0661:                int semicolon = currentValue.lastIndexOf(';');
0662:                ArrayList list = new ArrayList();
0663:                if (!insideQuotes(currentValue) && comma > semicolon
0664:                        || comma == semicolon) {
0665:                    String value = comma != -1 ? currentValue
0666:                            .substring(comma + 1) : currentValue;
0667:                    HashSet set = (HashSet) fHeaders
0668:                            .get(Constants.EXPORT_PACKAGE);
0669:                    if (set == null)
0670:                        set = parseHeaderForValues(currentValue, offset);
0671:                    value = removeLeadingSpaces(value);
0672:                    int length = value.length();
0673:                    IProject proj = ((PDEFormEditor) fSourcePage.getEditor())
0674:                            .getCommonProject();
0675:                    if (proj != null) {
0676:                        IJavaProject jp = JavaCore.create(proj);
0677:                        IPackageFragment[] frags = PDEJavaHelper
0678:                                .getPackageFragments(jp, set, false);
0679:                        for (int i = 0; i < frags.length; i++) {
0680:                            String name = frags[i].getElementName();
0681:                            if (name.regionMatches(true, 0, value, 0, length))
0682:                                list.add(new TypeCompletionProposal(name,
0683:                                        getImage(F_TYPE_PKG), name, offset
0684:                                                - length, length));
0685:                        }
0686:                    }
0687:                } else {
0688:                    String value = currentValue;
0689:                    if (comma > 0) {
0690:                        do {
0691:                            String prefix = currentValue.substring(0, comma);
0692:                            if (!insideQuotes(prefix)) {
0693:                                value = currentValue.substring(comma + 1);
0694:                                break;
0695:                            }
0696:                            comma = currentValue.lastIndexOf(',', comma - 1);
0697:                        } while (comma > 0);
0698:                    }
0699:                    int equals = currentValue.lastIndexOf('=');
0700:                    if (equals == -1 || semicolon > equals) {
0701:                        String[] validAttrs = new String[] {
0702:                                Constants.VERSION_ATTRIBUTE,
0703:                                ICoreConstants.INTERNAL_DIRECTIVE,
0704:                                ICoreConstants.FRIENDS_DIRECTIVE };
0705:                        Integer[] validTypes = new Integer[] {
0706:                                new Integer(F_TYPE_ATTRIBUTE),
0707:                                new Integer(F_TYPE_DIRECTIVE),
0708:                                new Integer(F_TYPE_DIRECTIVE) };
0709:                        return handleAttrsAndDirectives(value,
0710:                                initializeNewList(validAttrs),
0711:                                initializeNewList(validTypes), offset);
0712:                    }
0713:                    String attributeValue = removeLeadingSpaces(currentValue
0714:                            .substring(semicolon + 1));
0715:                    if (ICoreConstants.FRIENDS_DIRECTIVE.regionMatches(true, 0,
0716:                            attributeValue, 0, ICoreConstants.FRIENDS_DIRECTIVE
0717:                                    .length()))
0718:                        return handleXFriendsCompletion(currentValue
0719:                                .substring(equals + 1), offset);
0720:                    if (ICoreConstants.INTERNAL_DIRECTIVE.regionMatches(true,
0721:                            0, attributeValue, 0,
0722:                            ICoreConstants.INTERNAL_DIRECTIVE.length()))
0723:                        return handleTrueFalseValue(currentValue
0724:                                .substring(equals + 1), offset);
0725:                    if (Constants.VERSION_ATTRIBUTE.regionMatches(true, 0,
0726:                            attributeValue, 0, Constants.VERSION_ATTRIBUTE
0727:                                    .length())) {
0728:                        value = removeLeadingSpaces(currentValue
0729:                                .substring(equals + 1));
0730:                        if (value.length() == 0)
0731:                            return new ICompletionProposal[] { new TypeCompletionProposal(
0732:                                    "\"\"", getImage(F_TYPE_VALUE), "\"\"", offset, 0) }; //$NON-NLS-1$ //$NON-NLS-2$
0733:                    }
0734:                }
0735:                return (ICompletionProposal[]) list
0736:                        .toArray(new ICompletionProposal[list.size()]);
0737:            }
0738:
0739:            protected ICompletionProposal[] handleBundleActivatorCompletion(
0740:                    final String currentValue, final int offset) {
0741:                ArrayList completions = new ArrayList();
0742:                IProject project = ((PDEFormEditor) fSourcePage.getEditor())
0743:                        .getCommonProject();
0744:                int startOffset = offset - currentValue.length();
0745:                generateTypePackageProposals(currentValue, project,
0746:                        completions, startOffset, IJavaSearchConstants.CLASS);
0747:                ICompletionProposal[] proposals = (ICompletionProposal[]) completions
0748:                        .toArray(new ICompletionProposal[completions.size()]);
0749:                sortCompletions(proposals);
0750:                return proposals;
0751:            }
0752:
0753:            protected ICompletionProposal[] handleBundleSymbolicNameCompletion(
0754:                    String currentValue, int offset) {
0755:                int semicolon = currentValue.indexOf(';');
0756:                if (semicolon != -1) {
0757:                    int equals = currentValue.indexOf('=');
0758:                    if (equals == -1) {
0759:                        String attribute = currentValue
0760:                                .substring(semicolon + 1);
0761:                        attribute = removeLeadingSpaces(attribute);
0762:                        Object o = fHeaders
0763:                                .get(Constants.BUNDLE_MANIFESTVERSION);
0764:                        int type = (o == null || o.toString().equals("1")) ? F_TYPE_ATTRIBUTE : F_TYPE_DIRECTIVE;//$NON-NLS-1$
0765:                        if (Constants.SINGLETON_DIRECTIVE.regionMatches(true,
0766:                                0, attribute, 0, attribute.length())) {
0767:                            int length = attribute.length();
0768:                            TypeCompletionProposal proposal = new TypeCompletionProposal(
0769:                                    Constants.SINGLETON_DIRECTIVE + ":=", //$NON-NLS-1$
0770:                                    getImage(type),
0771:                                    Constants.SINGLETON_DIRECTIVE, offset
0772:                                            - length, length);
0773:                            proposal
0774:                                    .setAdditionalProposalInfo(getJavaDoc("SINGLETON_DIRECTIVE")); //$NON-NLS-1$
0775:                            return new ICompletionProposal[] { proposal };
0776:                        }
0777:                    } else if (equals > semicolon)
0778:                        return handleTrueFalseValue(currentValue
0779:                                .substring(equals + 1), offset);
0780:                }
0781:                return new ICompletionProposal[0];
0782:            }
0783:
0784:            protected ICompletionProposal[] handleBundleActivationPolicyCompletion(
0785:                    final String currentValue, final int offset) {
0786:                int comma = currentValue.lastIndexOf(',');
0787:                int semicolon = currentValue.lastIndexOf(';');
0788:                if (!insideQuotes(currentValue) && comma > semicolon
0789:                        || comma == semicolon) {
0790:                    String value = removeLeadingSpaces(currentValue);
0791:                    String lazyValue = "lazy"; //$NON-NLS-1$
0792:                    int length = value.length();
0793:                    if (lazyValue.regionMatches(0, value, 0, length))
0794:                        return new ICompletionProposal[] { new TypeCompletionProposal(
0795:                                lazyValue, null, lazyValue, offset - length,
0796:                                length) };
0797:                }
0798:                return new ICompletionProposal[0];
0799:            }
0800:
0801:            protected ICompletionProposal[] handleBuddyPolicyCompletion(
0802:                    String currentValue, int offset) {
0803:                String value = removeLeadingSpaces(currentValue);
0804:                // values from bug 178517 comment #7
0805:                ArrayList validValues = initializeNewList(new String[] {
0806:                        "dependent", "global", "registered", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0807:                        "app", "ext", "boot", "parent" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
0808:                ArrayList types = initializeNewList(new Object[] {
0809:                        new Integer(F_TYPE_VALUE), new Integer(F_TYPE_VALUE),
0810:                        new Integer(F_TYPE_VALUE), new Integer(F_TYPE_VALUE),
0811:                        new Integer(F_TYPE_VALUE), new Integer(F_TYPE_VALUE),
0812:                        new Integer(F_TYPE_VALUE) });
0813:                return handleAttrsAndDirectives(value, validValues, types,
0814:                        offset);
0815:            }
0816:
0817:            protected ICompletionProposal[] handleRequiredExecEnv(
0818:                    String currentValue, int offset) {
0819:                int comma = currentValue.lastIndexOf(',');
0820:                if (comma != -1)
0821:                    currentValue = currentValue.substring(comma + 1);
0822:                currentValue = removeLeadingSpaces(currentValue);
0823:                ArrayList completions = new ArrayList();
0824:                HashSet set = (HashSet) fHeaders
0825:                        .get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
0826:                if (set == null)
0827:                    set = new HashSet(0);
0828:                int length = currentValue.length();
0829:                for (int i = 0; i < fExecEnvs.length; i++)
0830:                    if (fExecEnvs[i].regionMatches(true, 0, currentValue, 0,
0831:                            length)
0832:                            && !set.contains(fExecEnvs[i]))
0833:                        completions.add(new TypeCompletionProposal(
0834:                                fExecEnvs[i], getImage(F_TYPE_EXEC_ENV),
0835:                                fExecEnvs[i], offset - length, length));
0836:                return (ICompletionProposal[]) completions
0837:                        .toArray(new ICompletionProposal[completions.size()]);
0838:            }
0839:
0840:            protected ICompletionProposal[] handleTrueFalseValue(
0841:                    String currentValue, int offset) {
0842:                currentValue = removeLeadingSpaces(currentValue);
0843:                int length = currentValue.length();
0844:                if (length == 0)
0845:                    return new ICompletionProposal[] {
0846:                            new TypeCompletionProposal(
0847:                                    "true", getImage(F_TYPE_VALUE), "true", offset, 0), //$NON-NLS-1$ //$NON-NLS-2$
0848:                            new TypeCompletionProposal(
0849:                                    "false", getImage(F_TYPE_VALUE), "false", offset, 0) //$NON-NLS-1$ //$NON-NLS-2$
0850:                    };
0851:                else if (length < 5
0852:                        && "true".regionMatches(true, 0, currentValue, 0, length)) //$NON-NLS-1$
0853:                    return new ICompletionProposal[] { new TypeCompletionProposal(
0854:                            "true", getImage(F_TYPE_VALUE), "true", offset - length, length) //$NON-NLS-1$ //$NON-NLS-2$
0855:                    };
0856:                else if (length < 6
0857:                        && "false".regionMatches(true, 0, currentValue, 0, length)) //$NON-NLS-1$
0858:                    return new ICompletionProposal[] { new TypeCompletionProposal(
0859:                            "false", getImage(F_TYPE_VALUE), "false", offset - length, length) //$NON-NLS-1$ //$NON-NLS-2$
0860:                    };
0861:                return new ICompletionProposal[0];
0862:            }
0863:
0864:            protected ICompletionProposal[] matchValueCompletion(String value,
0865:                    String[] attrs, int[] types, int offset) {
0866:                return matchValueCompletion(value, attrs, types, offset, ""); //$NON-NLS-1$
0867:            }
0868:
0869:            protected ICompletionProposal[] matchValueCompletion(String value,
0870:                    String[] attrs, int[] types, int offset,
0871:                    String prefixCostant) {
0872:                ArrayList list = new ArrayList();
0873:                int length = value.length();
0874:                TypeCompletionProposal proposal = null;
0875:                for (int i = 0; i < attrs.length; i++)
0876:                    if (attrs[i].regionMatches(true, 0, value, 0, length)) {
0877:                        if (types[i] == F_TYPE_ATTRIBUTE) {
0878:                            proposal = new TypeCompletionProposal(
0879:                                    attrs[i] + "=", getImage(F_TYPE_ATTRIBUTE), attrs[i], offset - length, length); //$NON-NLS-1$
0880:                            proposal
0881:                                    .setAdditionalProposalInfo(getJavaDoc(attrs[i]
0882:                                            + "_ATTRIBUTE")); //$NON-NLS-1$
0883:                        } else if (types[i] == F_TYPE_DIRECTIVE) {
0884:                            proposal = new TypeCompletionProposal(
0885:                                    attrs[i] + ":=", getImage(F_TYPE_DIRECTIVE), attrs[i], offset - length, length); //$NON-NLS-1$
0886:                            proposal
0887:                                    .setAdditionalProposalInfo(getJavaDoc(attrs[i]
0888:                                            + "_DIRECTIVE")); //$NON-NLS-1$
0889:                        } else {
0890:                            proposal = new TypeCompletionProposal(attrs[i],
0891:                                    getImage(types[i]), attrs[i], offset
0892:                                            - length, length);
0893:                            proposal
0894:                                    .setAdditionalProposalInfo(getJavaDoc(prefixCostant
0895:                                            + attrs[i]));
0896:                        }
0897:                        list.add(proposal);
0898:                    }
0899:                return (ICompletionProposal[]) list
0900:                        .toArray(new ICompletionProposal[list.size()]);
0901:            }
0902:
0903:            protected ICompletionProposal[] handleAttrsAndDirectives(
0904:                    String value, ArrayList attrs, ArrayList types, int offset) {
0905:                String fullValue = findFullLine(value, offset, false);
0906:                int semicolon = value.lastIndexOf(';');
0907:                value = removeLeadingSpaces(value.substring(semicolon + 1));
0908:                StringTokenizer tokenizer = new StringTokenizer(fullValue, ";"); //$NON-NLS-1$
0909:                tokenizer.nextToken();
0910:                while (tokenizer.hasMoreTokens()) {
0911:                    String tokenValue = removeLeadingSpaces(tokenizer
0912:                            .nextToken());
0913:                    int index = tokenValue.indexOf('=');
0914:                    if (index == -1)
0915:                        continue;
0916:                    if (tokenValue.charAt(index - 1) == ':')
0917:                        --index;
0918:                    tokenValue = tokenValue.substring(0, index);
0919:                    int indexOfObject = attrs.indexOf(tokenValue);
0920:                    if (indexOfObject >= 0) {
0921:                        attrs.remove(indexOfObject);
0922:                        types.remove(indexOfObject);
0923:                    }
0924:                }
0925:                return matchValueCompletion(value, (String[]) attrs
0926:                        .toArray(new String[attrs.size()]), toIntArray(types),
0927:                        offset);
0928:            }
0929:
0930:            private HashSet parseHeaderForValues(String currentValue, int offset) {
0931:                HashSet set = new HashSet();
0932:                String fullValue = findFullLine(currentValue, offset, true);
0933:                StringTokenizer tokenizer = new StringTokenizer(fullValue, ","); //$NON-NLS-1$
0934:                while (tokenizer.hasMoreTokens()) {
0935:                    String pkgValue = tokenizer.nextToken();
0936:                    int index = pkgValue.indexOf(';');
0937:                    set.add(index == -1 ? pkgValue.trim() : pkgValue.substring(
0938:                            0, index).trim());
0939:                }
0940:                return set;
0941:            }
0942:
0943:            private String findFullLine(String value, int offset,
0944:                    boolean entireHeader) {
0945:                IDocument doc = fSourcePage.getDocumentProvider().getDocument(
0946:                        fSourcePage.getInputContext().getInput());
0947:                try {
0948:                    int line = doc.getLineOfOffset(offset);
0949:                    String newValue = ""; //$NON-NLS-1$
0950:                    int startOfLine = 0;
0951:                    int colon = -1;
0952:                    do {
0953:                        startOfLine = doc.getLineOffset(line);
0954:                        newValue = doc.get(offset, doc.getLineLength(line)
0955:                                - offset + startOfLine);
0956:                        ++line;
0957:                        colon = newValue.lastIndexOf(':');
0958:                    } while ((colon == -1 || (newValue.length() > colon && newValue
0959:                            .charAt(colon + 1) == '='))
0960:                            && (entireHeader || newValue.indexOf(',') == -1)
0961:                            && !(doc.getNumberOfLines() == line));
0962:                    if (colon > 0 && newValue.charAt(colon + 1) != '=') {
0963:                        newValue = doc.get(offset, startOfLine - 1 - offset);
0964:                    } else {
0965:                        int comma = newValue.indexOf(',');
0966:                        newValue = (comma != -1) ? newValue.substring(0, comma)
0967:                                : newValue;
0968:                    }
0969:                    return value.concat(newValue);
0970:                } catch (BadLocationException e) {
0971:                }
0972:                return ""; //$NON-NLS-1$
0973:            }
0974:
0975:            private int[] toIntArray(ArrayList list) {
0976:                int[] result = new int[list.size()];
0977:                int i = -1;
0978:                while (++i < result.length) {
0979:                    Object o = list.get(i);
0980:                    if (!(o instanceof  Integer))
0981:                        return new int[0];
0982:                    result[i] = ((Integer) o).intValue();
0983:                }
0984:                return result;
0985:            }
0986:
0987:            // if you use java.util.Arrays.asList(), we get an UnsupportedOperation later in the code
0988:            protected final ArrayList initializeNewList(Object[] values) {
0989:                ArrayList list = new ArrayList(values.length);
0990:                for (int i = 0; i < values.length; i++)
0991:                    list.add(values[i]);
0992:                return list;
0993:            }
0994:
0995:            private boolean insideQuotes(String value) {
0996:                char[] chars = value.toCharArray();
0997:                int numOfQuotes = 0;
0998:                for (int i = 0; i < chars.length; i++)
0999:                    if (chars[i] == '\"')
1000:                        ++numOfQuotes;
1001:                int j = numOfQuotes % 2;
1002:                return j == 1;
1003:            }
1004:
1005:            public void assistSessionEnded(ContentAssistEvent event) {
1006:                fHeaders = null;
1007:            }
1008:
1009:            public void assistSessionStarted(ContentAssistEvent event) {
1010:            }
1011:
1012:            public void selectionChanged(ICompletionProposal proposal,
1013:                    boolean smartToggle) {
1014:            }
1015:
1016:            public Image getImage(int type) {
1017:                if (type >= 0 && type < F_TOTAL_TYPES)
1018:                    if (fImages[type] == null) {
1019:                        switch (type) {
1020:                        case F_TYPE_HEADER:
1021:                            return fImages[type] = PDEPluginImages.DESC_BUILD_VAR_OBJ
1022:                                    .createImage();
1023:                        case F_TYPE_PKG:
1024:                            return PDEPluginImages
1025:                                    .get(PDEPluginImages.OBJ_DESC_PACKAGE);
1026:                        case F_TYPE_BUNDLE:
1027:                            return fImages[type] = PDEPluginImages.DESC_PLUGIN_OBJ
1028:                                    .createImage();
1029:                        case F_TYPE_CLASS:
1030:                            return PDEPluginImages
1031:                                    .get(PDEPluginImages.OBJ_DESC_GENERATE_CLASS);
1032:                        case F_TYPE_ATTRIBUTE:
1033:                            return fImages[type] = PDEPluginImages.DESC_ATT_URI_OBJ
1034:                                    .createImage();
1035:                        case F_TYPE_DIRECTIVE:
1036:                            fImages[F_TYPE_ATTRIBUTE] = PDEPluginImages.DESC_ATT_URI_OBJ
1037:                                    .createImage();
1038:                            ImageOverlayIcon icon = new ImageOverlayIcon(
1039:                                    fImages[F_TYPE_ATTRIBUTE],
1040:                                    new ImageDescriptor[][] {
1041:                                            new ImageDescriptor[] { PDEPluginImages.DESC_DOC_CO },
1042:                                            null, null, null });
1043:                            return fImages[type] = icon.createImage();
1044:                        case F_TYPE_EXEC_ENV:
1045:                            return fImages[type] = PDEPluginImages.DESC_JAVA_LIB_OBJ
1046:                                    .createImage();
1047:                        case F_TYPE_VALUE:
1048:                            return null;
1049:                        }
1050:                    } else
1051:                        return fImages[type];
1052:                return null;
1053:            }
1054:
1055:            public void dispose() {
1056:                for (int i = 0; i < fImages.length; i++)
1057:                    if (fImages[i] != null && !fImages[i].isDisposed())
1058:                        fImages[i].dispose();
1059:            }
1060:
1061:            private String getJavaDoc(String constant) {
1062:                if (fJP == null) {
1063:                    IProject project = ((PDEFormEditor) fSourcePage.getEditor())
1064:                            .getCommonProject();
1065:                    fJP = JavaCore.create(project);
1066:                }
1067:                return PDEJavaHelperUI.getOSGIConstantJavaDoc(constant, fJP);
1068:            }
1069:
1070:        }
ww___w.__ja___v_a_2_s.___c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.