This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 179508
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+13 lines)
Lines 105-110 Link Here
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
106
107
    <changes>
107
    <changes>
108
        <change id="ImportProcessor">
109
             <api name="general"/>
110
             <summary>Added ImportProcessor interface</summary>
111
             <version major="0" minor="51"/>
112
             <date day="18" month="01" year="2010"/>
113
             <author login="tslota"/>
114
             <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
115
             <description>
116
                 Added <code>ImportProcessor</code> interface,
117
             </description>
118
             <class package="org.netbeans.spi.java.loaders" name="ImportProcessor"/>
119
             <issue number="179508"/>
120
        </change>
108
        <change id="GeneratorUtilities.copyComments">
121
        <change id="GeneratorUtilities.copyComments">
109
             <api name="general"/>
122
             <api name="general"/>
110
             <summary>Added GeneratorUtilities.copyComments method.</summary>
123
             <summary>Added GeneratorUtilities.copyComments method.</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 43-49 Link Here
43
javadoc.title=Java Source
43
javadoc.title=Java Source
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
46
spec.version.base=0.53.0
46
spec.version.base=0.54.0
47
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
47
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
48
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
48
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
49
    ${o.n.core.dir}/lib/boot.jar:\
49
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/SourceUtils.java (-20 / +36 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.api.java.source;
42
package org.netbeans.api.java.source;
43
43
44
import org.netbeans.spi.java.loaders.ImportProcessor;
44
import java.io.File;
45
import java.io.File;
45
import java.io.IOException;
46
import java.io.IOException;
46
import java.net.MalformedURLException;
47
import java.net.MalformedURLException;
Lines 80-85 Link Here
80
import javax.swing.SwingUtilities;
81
import javax.swing.SwingUtilities;
81
82
82
import org.netbeans.api.annotations.common.NonNull;
83
import org.netbeans.api.annotations.common.NonNull;
84
import org.netbeans.api.editor.mimelookup.MimeLookup;
85
import org.netbeans.api.editor.mimelookup.MimePath;
83
import org.netbeans.api.java.classpath.ClassPath;
86
import org.netbeans.api.java.classpath.ClassPath;
84
import org.netbeans.api.java.lexer.JavaTokenId;
87
import org.netbeans.api.java.lexer.JavaTokenId;
85
import org.netbeans.api.java.classpath.GlobalPathRegistry;
88
import org.netbeans.api.java.classpath.GlobalPathRegistry;
Lines 112-117 Link Here
112
import org.openide.filesystems.FileUtil;
115
import org.openide.filesystems.FileUtil;
113
import org.openide.filesystems.URLMapper;
116
import org.openide.filesystems.URLMapper;
114
import org.openide.util.Exceptions;
117
import org.openide.util.Exceptions;
118
import org.openide.util.Lookup;
115
import org.openide.util.Parameters;
119
import org.openide.util.Parameters;
116
import org.openide.util.Utilities;
120
import org.openide.util.Utilities;
117
121
Lines 271-297 Link Here
271
            return fqn;
275
            return fqn;
272
        
276
        
273
        //not imported/visible so far by any means:
277
        //not imported/visible so far by any means:
274
        if (info instanceof WorkingCopy) {
278
        String topLevelLanguageMIMEType = info.getFileObject().getMIMEType();
275
            CompilationUnitTree nue = (CompilationUnitTree) ((WorkingCopy)info).getChangeSet().get(cut);
279
        if ("text/x-java".equals(topLevelLanguageMIMEType)){
276
            cut = nue != null ? nue : cut;
280
            if (info instanceof WorkingCopy) {
277
            ((WorkingCopy)info).rewrite(info.getCompilationUnit(), addImports(cut, Collections.singletonList(fqn), ((WorkingCopy)info).getTreeMaker()));
281
                CompilationUnitTree nue = (CompilationUnitTree) ((WorkingCopy)info).getChangeSet().get(cut);
278
        } else {
282
                cut = nue != null ? nue : cut;
279
            SwingUtilities.invokeLater(new Runnable() {
283
                ((WorkingCopy)info).rewrite(info.getCompilationUnit(), addImports(cut, Collections.singletonList(fqn), ((WorkingCopy)info).getTreeMaker()));
280
                public void run() {
284
            } else {
281
                    try {
285
                SwingUtilities.invokeLater(new Runnable() {
282
                        ModificationResult.runModificationTask(Collections.singletonList(info.getSnapshot().getSource()), new UserTask() {
286
                    public void run() {
283
                            @Override
287
                        try {
284
                            public void run(ResultIterator resultIterator) throws Exception {
288
                            ModificationResult.runModificationTask(Collections.singletonList(info.getSnapshot().getSource()), new UserTask() {
285
                                WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult());
289
                                @Override
286
                                copy.toPhase(Phase.ELEMENTS_RESOLVED);
290
                                public void run(ResultIterator resultIterator) throws Exception {
287
                                copy.rewrite(copy.getCompilationUnit(), addImports(copy.getCompilationUnit(), Collections.singletonList(fqn), copy.getTreeMaker()));                                
291
                                    WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult());
288
                            }
292
                                    copy.toPhase(Phase.ELEMENTS_RESOLVED);
289
                        }).commit();
293
                                    copy.rewrite(copy.getCompilationUnit(), addImports(copy.getCompilationUnit(), Collections.singletonList(fqn), copy.getTreeMaker()));
290
                    } catch (Exception e) {
294
                                }
291
                        Exceptions.printStackTrace(e);
295
                            }).commit();
296
                        } catch (Exception e) {
297
                            Exceptions.printStackTrace(e);
298
                        }
292
                    }
299
                    }
293
                }
300
                });
294
            });
301
            }
302
        } else { // embedded java, look up the handler for the top level language
303
            Lookup lookup = MimeLookup.getLookup(MimePath.get(topLevelLanguageMIMEType));
304
            Lookup.Result result = lookup.lookup(new Lookup.Template(ImportProcessor.class));
305
            Collection<ImportProcessor> instances = result.allInstances();
306
307
            for (ImportProcessor importsProcesor : instances) {
308
                importsProcesor.addImport(info.getDocument(), fqn);
309
            }
310
            
295
        }
311
        }
296
        TypeElement te = info.getElements().getTypeElement(fqn);
312
        TypeElement te = info.getElements().getTypeElement(fqn);
297
        if (te != null) {
313
        if (te != null) {
(-)a/java.source/src/org/netbeans/spi/java/loaders/ImportProcessor.java (+60 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.loaders;
41
42
import javax.swing.text.Document;
43
44
/**
45
 * Interface that allows to hook custom code to the action of inserting import
46
 * when code completion is called within embedded Java code
47
 *
48
 * @since 0.54
49
 * @author Tomasz.Slota@Sun.COM
50
 */
51
public interface ImportProcessor {
52
    /**
53
     * Handle request to add unresolved import
54
     *  (top-level-language specific way)
55
     *
56
     * @param doc
57
     * @param fullyQualifiedClassName
58
     */
59
    void addImport(Document doc, String fullyQualifiedClassName);
60
}

Return to bug 179508