You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/12/30 05:50:25 UTC

[GitHub] [netbeans] junichi11 commented on a change in pull request #2616: [NETBEANS-4739] CSS Go to Declaration , does not work

junichi11 commented on a change in pull request #2616:
URL: https://github.com/apache/netbeans/pull/2616#discussion_r549943176



##########
File path: ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/ProjectTestBase.java
##########
@@ -0,0 +1,381 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.css.editor;
+
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.swing.Icon;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.SourceGroup;
+import org.netbeans.api.project.Sources;
+import org.netbeans.junit.MockServices;
+import org.netbeans.lib.lexer.test.TestLanguageProvider;
+import org.netbeans.modules.css.lib.CssTestBase;
+import org.netbeans.modules.parsing.api.indexing.IndexingManager;
+import org.netbeans.modules.parsing.spi.indexing.PathRecognizer;
+import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.netbeans.spi.project.ProjectFactory;
+import org.netbeans.spi.project.ProjectState;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Lookup;
+import org.openide.util.Utilities;
+import org.openide.util.lookup.AbstractLookup;
+import org.openide.util.lookup.InstanceContent;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.test.MockLookup;
+
+/**
+ * Base class for all tests which needs a working static html project.
+ *
+ * Copied from org.netbeans.modules.css.prep.editor.ProjectTestBase
+ *
+ * @author marekfukala
+ */
+public class ProjectTestBase extends CssTestBase {
+
+    private String projectFolder;
+    
+    private FileObject srcFo, projectFo;
+//    private FileObject javaLibSrc, javaLibProjectFo;
+
+    public ProjectTestBase(String name, String projectFolder) {
+        super(name);
+        this.projectFolder = projectFolder;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        assertNotNull("the netbeans.dirs property must be specified!", System.getProperty("netbeans.dirs"));
+
+        this.projectFo = getTestFile(projectFolder);
+        assertNotNull(projectFo);
+        this.srcFo = getTestFile(getSourcesFolderName());
+        assertNotNull(srcFo);
+
+        Map<FileObject, ProjectInfo> projects = new HashMap<>();
+
+        //create classpath for web project
+        Map<String, ClassPath> cps = new HashMap<>();
+
+        ClassPath sourceClassPath = ClassPathSupport.createClassPath(new FileObject[]{srcFo});
+        
+        cps.put(ClassPath.SOURCE, sourceClassPath);
+        cps.put(ClassPath.COMPILE, ClassPathSupport.createClassPath(new FileObject[]{srcFo}));
+        cps.put(ClassPath.BOOT, createBootClassPath());
+        ClassPathProvider classpathProvider = new TestMultiClassPathProvider(projectFo, cps);
+        Sources sources = new TestSources(srcFo);
+
+        projects.put(projectFo, new ProjectInfo(classpathProvider, sources));
+
+        MockLookup.setInstances(
+                new TestMultiProjectFactory(projects),
+                new SimpleFileOwnerQueryImplementation(),
+                classpathProvider,
+                new TestLanguageProvider());
+
+        //provides the ClassPath.SOURCE as source path id so it is returned by
+        //PathRecognizerRegistry.getDefault().getSourceIds()
+        MockServices.setServices(TestPathRecognizer.class);
+
+        //register the source classpath so PathRegistry.getDefault().getRootsMarkedAs(classpathId) in QuerySupport works
+        GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[]{sourceClassPath});
+        
+        IndexingManager.getDefault().refreshIndexAndWait(srcFo.toURL(), null);
+    }
+    
+    protected String getTestProjectFolderName() {
+        return projectFolder;
+    }
+    
+    protected String getSourcesFolderName() {
+        return projectFolder + "/public_html";
+    }
+    
+    @ServiceProvider(service = PathRecognizer.class)
+    public static class TestPathRecognizer extends  PathRecognizer {

Review comment:
       Nitpick: Let's format the whole file.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists