--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 15457e75b376 Fri Mar 11 08:48:08 2011 +0100 @@ -0,0 +1,123 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.parsing.impl; + +import java.net.URL; +import java.util.Map; +import org.netbeans.modules.parsing.spi.indexing.BinaryIndexer; +import org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory; +import org.netbeans.modules.parsing.spi.indexing.Context; + +/** + * + * @author Jaroslav Tulach + */ +public final class GenericBinaryIndexerFactory extends BinaryIndexerFactory { + private Map map; + private BinaryIndexerFactory delegate; + + private GenericBinaryIndexerFactory(Map map) { + this.map = map; + } + + public static BinaryIndexerFactory create(Map map) { + return new GenericBinaryIndexerFactory(map); + } + + @Override + public BinaryIndexer createIndexer() { + Object obj = initDelegate(true); + if (obj instanceof BinaryIndexer) { + return (BinaryIndexer)obj; + } + return delegate.createIndexer(); + } + + @Override + public void rootsRemoved(Iterable removedRoots) { + initDelegate(false); + if (delegate != null) { + delegate.rootsRemoved(removedRoots); + return; + } + } + + @Override + public String getIndexerName() { + return (String)map.get("indexerName"); // NOI18N + } + + @Override + public int getIndexVersion() { + return (Integer)map.get("indexerVersion"); // NOI18N + } + + @Override + public boolean scanStarted(Context context) { + initDelegate(false); + if (delegate == null) { + return true; + } + return delegate.scanStarted(context); + } + + @Override + public void scanFinished(Context context) { + initDelegate(false); + if (delegate != null) { + delegate.scanFinished(context); + } + } + + private Object initDelegate(boolean always) { + if (delegate == null && (Boolean.TRUE.equals(map.get("factory")) || always)) { + Object obj = map.get("delegate"); + if (obj instanceof BinaryIndexerFactory) { + delegate = (BinaryIndexerFactory) obj; + } + return obj; + } + return delegate; + } + + +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 15457e75b376 Fri Mar 11 08:48:08 2011 +0100 @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.parsing.impl; + +import java.util.Collections; +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory; +import org.netbeans.modules.parsing.spi.indexing.IndexerRegistration; +import org.openide.filesystems.annotations.LayerBuilder.File; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author Jaroslav Tulach + */ +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class IndexerRegistrationProcessor extends LayerGeneratingProcessor { + + @Override + public Set getSupportedAnnotationTypes() { + return Collections.singleton(IndexerRegistration.class.getName()); + } + + @Override + protected boolean handleProcess( + Set annotations, RoundEnvironment roundEnv + ) throws LayerGenerationException { + TypeElement bif = processingEnv.getElementUtils().getTypeElement(BinaryIndexerFactory.class.getName()); + for (Element e : roundEnv.getElementsAnnotatedWith(IndexerRegistration.class)) { + IndexerRegistration ir = e.getAnnotation(IndexerRegistration.class); + + boolean isBif = processingEnv.getTypeUtils().isAssignable(e.asType(), bif.asType()); + + File f = layer(e).instanceFile("Editors", null); + f.methodvalue("instanceCreate", GenericBinaryIndexerFactory.class.getName(), "create"); + f.stringvalue("instanceClass", BinaryIndexerFactory.class.getName()); + f.instanceAttribute("delegate", null); + f.stringvalue("indexerName", ir.name()); + f.intvalue("indexerVersion", ir.version()); + f.boolvalue("factory", isBif); + f.write(); + } + return true; + } + +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 15457e75b376 Fri Mar 11 08:48:08 2011 +0100 @@ -0,0 +1,59 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.parsing.spi.indexing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** Annotation to annotate {@link BinaryIndexer}, {@link BinaryIndexerFactory}, + * or TBD... + * + * @author Jaroslav Tulach + */ +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.TYPE) +public @interface IndexerRegistration { + String name(); + int version(); +} --- a/spring.beans/src/org/netbeans/modules/spring/beans/index/SpringBinaryIndexer.java Thu Mar 10 20:22:44 2011 +0100 +++ a/spring.beans/src/org/netbeans/modules/spring/beans/index/SpringBinaryIndexer.java Fri Mar 11 08:48:08 2011 +0100 @@ -42,17 +42,15 @@ package org.netbeans.modules.spring.beans.index; -import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; -import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.modules.parsing.spi.indexing.BinaryIndexer; -import org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory; import org.netbeans.modules.parsing.spi.indexing.Context; +import org.netbeans.modules.parsing.spi.indexing.IndexerRegistration; import org.netbeans.modules.parsing.spi.indexing.support.IndexDocument; import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport; import org.netbeans.modules.spring.api.SpringUtilities; @@ -70,7 +68,7 @@ * * @author alexeybutenko */ - +@IndexerRegistration(name=SpringBinaryIndexer.INDEXER_NAME, version=SpringBinaryIndexer.INDEX_VERSION) public class SpringBinaryIndexer extends BinaryIndexer { private static final Logger LOGGER = Logger.getLogger(SpringBinaryIndexer.class.getSimpleName()); @@ -175,28 +173,4 @@ } return null; } - - public static class Factory extends BinaryIndexerFactory { - - @Override - public BinaryIndexer createIndexer() { - return new SpringBinaryIndexer(); - } - - @Override - public void rootsRemoved(Iterable removedRoots) { -// throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String getIndexerName() { - return INDEXER_NAME; - } - - @Override - public int getIndexVersion() { - return INDEX_VERSION; - } - } - } --- a/spring.beans/src/org/netbeans/modules/spring/beans/resources/layer.xml Thu Mar 10 20:22:44 2011 +0100 +++ a/spring.beans/src/org/netbeans/modules/spring/beans/resources/layer.xml Fri Mar 11 08:48:08 2011 +0100 @@ -153,9 +153,6 @@ - - -