Fix to make System.out/System.err output only when debugging 75/38175/3
authorMichael Vorburger <vorburger@redhat.com>
Wed, 27 Apr 2016 18:47:07 +0000 (20:47 +0200)
committerDavid M. Karr <davidmichaelkarr@gmail.com>
Mon, 16 May 2016 19:46:55 +0000 (12:46 -0700)
incl. also some Eclipse Auto-Save automated clean-up changes

Added checkstyle builder to some projects.
Changed some printlns to log method calls, including some commented-out
printlns (from earlier commits in this review).
Changed some HashSet variable types to Set.
Added additional log method to Activator.

Change-Id: I3dc5989136914c11a1af154789a885c6ff19ec6d
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
Signed-off-by: David M. Karr <davidmichaelkarr@gmail.com>
plugins/org.opendaylight.yangide.core.tests/.project
plugins/org.opendaylight.yangide.core/src/org/opendaylight/yangide/core/buffer/BufferManager.java
plugins/org.opendaylight.yangide.core/src/org/opendaylight/yangide/core/indexing/IndexAllProject.java
plugins/org.opendaylight.yangide.core/src/org/opendaylight/yangide/core/indexing/IndexManager.java
plugins/org.opendaylight.yangide.ext.model.editor/src/main/java/org/opendaylight/yangide/ext/model/editor/Activator.java
plugins/org.opendaylight.yangide.ext.model.editor/src/main/java/org/opendaylight/yangide/ext/model/editor/editors/YangDiagramEditor.java
plugins/org.opendaylight.yangide.m2e.yang.tests/.project
plugins/org.opendaylight.yangide.ui/.project
plugins/org.opendaylight.yangide.yangparser/.project
product/target-platform/.project

index 8d222732508c443641850a554c4b1cb967bc3249..5395b2a6b9dca5eef19198f40a4966e7eacecaf2 100644 (file)
                        <arguments>
                        </arguments>
                </buildCommand>
+               <buildCommand>
+                       <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
@@ -30,5 +35,6 @@
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
                <nature>org.eclipse.pde.PluginNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
        </natures>
 </projectDescription>
index cb7576bb49038f5cdf3db0e7600b00445d1c5dc5..0ea2bc339fd2270341963347bae452a2a87139c3 100644 (file)
@@ -12,8 +12,9 @@ import java.util.Enumeration;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
-
+import org.eclipse.core.runtime.IStatus;
 import org.opendaylight.yangide.core.IOpenable;
+import org.opendaylight.yangide.core.YangCorePlugin;
 import org.opendaylight.yangide.core.model.YangElement;
 
 /**
@@ -23,7 +24,7 @@ import org.opendaylight.yangide.core.model.YangElement;
 public class BufferManager {
 
     protected static BufferManager DEFAULT_BUFFER_MANAGER;
-    protected static boolean VERBOSE;
+    protected static boolean VERBOSE = false;
 
     /**
      * LRU cache of buffers. The key and value for an entry in the table is the identical buffer.
@@ -36,7 +37,7 @@ public class BufferManager {
     public void addBuffer(IBuffer buffer) {
         if (VERBOSE) {
             String owner = ((YangElement) buffer.getOwner()).toStringWithAncestors();
-            System.out.println("Adding buffer for " + owner); //$NON-NLS-1$
+            YangCorePlugin.log(IStatus.INFO, "Adding buffer for " + owner);
         }
         synchronized (this.openBuffers) {
             this.openBuffers.put(buffer.getOwner(), buffer);
@@ -44,8 +45,7 @@ public class BufferManager {
         // close buffers that were removed from the cache if space was needed
         this.openBuffers.closeBuffers();
         if (VERBOSE) {
-            System.out
-                    .println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
+            YangCorePlugin.log(IStatus.INFO, "-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
         }
     }
 
index ce76442e1c150d5c85dc4b7e6b0e60aeb8097155..dadc81c7f658b7045d4be5a58f784ba00bba817f 100644 (file)
@@ -9,18 +9,18 @@ package org.opendaylight.yangide.core.indexing;
 
 import java.io.IOException;
 import java.util.HashSet;
+import java.util.Set;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceProxy;
-import org.eclipse.core.resources.IResourceProxyVisitor;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -57,7 +57,7 @@ public class IndexAllProject extends IndexRequest {
 
     @Override
     public boolean execute(IProgressMonitor progressMonitor) {
-        System.err.println("[I] Project: " + project.getName());
+        YangCorePlugin.log(IStatus.INFO, "[I] Project: " + project.getName());
 
         if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) {
             return true;
@@ -66,17 +66,16 @@ public class IndexAllProject extends IndexRequest {
         if (!this.project.isAccessible()) {
             return true;
         }
-        final HashSet<IPath> ignoredPath = new HashSet<IPath>();
-        final HashSet<IPath> externalJarsPath = new HashSet<IPath>();
+        final Set<IPath> ignoredPath = new HashSet<>();
+        final Set<IPath> externalJarsPath = new HashSet<>();
         try {
             JavaProject proj = (JavaProject) JavaCore.create(project);
-            final HashSet<String> projectScope = new HashSet<>();
+            final Set<String> projectScope = new HashSet<>();
             projectScope.add(project.getName());
 
             if (proj != null) {
                 IClasspathEntry[] classpath = proj.getResolvedClasspath();
-                for (int i = 0, length = classpath.length; i < length; i++) {
-                    IClasspathEntry entry = classpath[i];
+                for (IClasspathEntry entry : classpath) {
                     IPath entryPath = entry.getPath();
                     IPath output = entry.getOutputLocation();
                     if (output != null && !entryPath.equals(output)) {
@@ -94,8 +93,8 @@ public class IndexAllProject extends IndexRequest {
                     }
                 }
                 IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots();
-                for (int i = 0, length = roots.length; i < length; i++) {
-                    IPath entryPath = roots[i].getPath();
+                for (IPackageFragmentRoot root : roots) {
+                    IPath entryPath = root.getPath();
                     if (entryPath != null && entryPath.toFile().exists()
                             && entryPath.lastSegment().toLowerCase().endsWith(".jar")) {
                         externalJarsPath.add(entryPath);
@@ -105,7 +104,7 @@ public class IndexAllProject extends IndexRequest {
                 YangProjectInfo yangProjectInfo = (YangProjectInfo) YangCorePlugin.create(project).getElementInfo(null);
                 yangProjectInfo.setProjectScope(projectScope);
                 // fill indirect scope
-                HashSet<String> indirectScope = new HashSet<String>();
+                Set<String> indirectScope = new HashSet<>();
                 indirectScope.add(project.getName());
                 for (IJavaProject jproj : JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects()) {
                     if (jproj != proj) {
@@ -133,25 +132,22 @@ public class IndexAllProject extends IndexRequest {
             }
         }
         try {
-            final HashSet<IFile> indexedFiles = new HashSet<IFile>();
-            project.accept(new IResourceProxyVisitor() {
-                @Override
-                public boolean visit(IResourceProxy proxy) {
-                    if (IndexAllProject.this.isCancelled) {
-                        return false;
-                    }
-                    if (!ignoredPath.isEmpty() && ignoredPath.contains(proxy.requestFullPath())) {
-                        return false;
-                    }
-                    if (proxy.getType() == IResource.FILE) {
-                        if (CoreUtil.isYangLikeFileName(proxy.getName())) {
-                            IFile file = (IFile) proxy.requestResource();
-                            indexedFiles.add(file);
-                        }
-                        return false;
+            final HashSet<IFile> indexedFiles = new HashSet<>();
+            project.accept(proxy -> {
+                if (IndexAllProject.this.isCancelled) {
+                    return false;
+                }
+                if (!ignoredPath.isEmpty() && ignoredPath.contains(proxy.requestFullPath())) {
+                    return false;
+                }
+                if (proxy.getType() == IResource.FILE) {
+                    if (CoreUtil.isYangLikeFileName(proxy.getName())) {
+                        IFile file = (IFile) proxy.requestResource();
+                        indexedFiles.add(file);
                     }
-                    return true;
+                    return false;
                 }
+                return true;
             }, IResource.NONE);
 
             for (IFile iFile : indexedFiles) {
index a1a2b1e92bfb83017c6c26365866bcf2fb77c14d..a942d0011217dc76c6614ddf4f98c809c3267ee2 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.mapdb.DB;
 import org.mapdb.DBMaker;
@@ -131,13 +132,7 @@ public class IndexManager extends JobManager {
         if (this.db != null) {
             this.db.close();
         }
-        File[] files = indexFile.getParentFile().listFiles(new FilenameFilter() {
-
-            @Override
-            public boolean accept(File dir, String name) {
-                return name.startsWith("index") && (cleanAll || !name.startsWith("index_" + INDEX_VERSION));
-            }
-        });
+        File[] files = indexFile.getParentFile().listFiles((FilenameFilter) (dir, name) -> name.startsWith("index") && (cleanAll || !name.startsWith("index_" + INDEX_VERSION)));
         if (files != null) {
             for (File file : files) {
                 file.delete();
@@ -175,7 +170,7 @@ public class IndexManager extends JobManager {
         Iterable<Long> it = Fun.filter(idxResources, file.getProject().getName(), file.getFullPath().toString());
         for (Long modStamp : it) {
             if (modStamp == file.getModificationStamp()) {
-                System.err.println("[x] " + file);
+                YangCorePlugin.log(IStatus.INFO, "[x] " + file);
                 return;
             }
         }
@@ -191,7 +186,7 @@ public class IndexManager extends JobManager {
         Iterable<Long> it = Fun.filter(idxResources, project.getName(), file.toString());
         for (Long modStamp : it) {
             if (modStamp == file.toFile().lastModified()) {
-                System.err.println("[x] " + file);
+                YangCorePlugin.log(IStatus.INFO, "[x] " + file);
                 return;
             }
         }
@@ -268,15 +263,14 @@ public class IndexManager extends JobManager {
     }
 
     public synchronized void addElementIndexInfo(ElementIndexInfo info) {
-        System.err.println("[I] " + info.getModule() + "@" + info.getRevision() + " - " + info.getName() + " - "
-                + info.getType());
-        idxKeywords.add(Fun.t6(info.getModule(), info.getRevision(), info.getName(), info.getType(), info.getPath(),
-                info));
+        YangCorePlugin.log(IStatus.INFO,
+                "[I] " + info.getModule() + "@" + info.getRevision() + " - " + info.getName() + " - " + info.getType());
+        idxKeywords.add(Fun.t6(info.getModule(), info.getRevision(), info.getName(), info.getType(), info.getPath(), info));
     }
 
     public synchronized void addElementIndexReferenceInfo(ElementIndexReferenceInfo info) {
-        System.err.println("[IR] " + info.getReference() + " : " + info.getType() + " - " + info.getProject() + "@"
-                + info.getPath());
+        YangCorePlugin.log(IStatus.INFO,
+                "[IR] " + info.getReference() + " : " + info.getType() + " - " + info.getProject() + "@" + info.getPath());
         idxReferences.add(Fun.t4(info.getReference(), info.getType(), info.getPath(), info));
     }
 
@@ -393,11 +387,11 @@ public class IndexManager extends JobManager {
         }
 
         String  nameWithoutPrefix   = name;
-        int colonIndex  = nameWithoutPrefix != null ? nameWithoutPrefix.indexOf(':') : -1; 
+        int colonIndex  = nameWithoutPrefix != null ? nameWithoutPrefix.indexOf(':') : -1;
         if (colonIndex != -1) {
             nameWithoutPrefix   = nameWithoutPrefix.substring(colonIndex + 1);
         }
-        
+
         for (Tuple6<String, String, String, ElementIndexType, String, ElementIndexInfo> entry : idxKeywords) {
             if (module != null && module.length() > 0 && !module.equals(entry.a)) {
                 continue;
@@ -424,7 +418,7 @@ public class IndexManager extends JobManager {
             }
 
             if (infos == null) {
-                infos = new ArrayList<ElementIndexInfo>();
+                infos = new ArrayList<>();
             }
             infos.add(entry.f);
         }
@@ -450,7 +444,7 @@ public class IndexManager extends JobManager {
         }
 
         String  nameWithoutPrefix   = reference.getName();
-        int colonIndex  = nameWithoutPrefix != null ? nameWithoutPrefix.indexOf(':') : -1; 
+        int colonIndex  = nameWithoutPrefix != null ? nameWithoutPrefix.indexOf(':') : -1;
         if (colonIndex != -1) {
             nameWithoutPrefix   = nameWithoutPrefix.substring(colonIndex + 1);
         }
@@ -478,7 +472,7 @@ public class IndexManager extends JobManager {
             }
 
             if (infos == null) {
-                infos = new ArrayList<ElementIndexReferenceInfo>();
+                infos = new ArrayList<>();
             }
 
             if (!infos.contains(entry.d)) {
index d46b15b562dccfec04234124e176186382a11c09..eed5271658b29aaf7f24d307bff5a87434b91d73 100644 (file)
@@ -104,4 +104,14 @@ public class Activator extends AbstractUIPlugin {
     public static void log(IStatus status) {
         getDefault().getLog().log(status);
     }
+    
+    /**
+     * Reports log to Error Log view.
+     *
+     * @param statusErrorID plugin related error ID
+     * @param message error message
+     */
+    public static void log(int statusErrorID, String message) {
+        log(new Status(statusErrorID, PLUGIN_ID, message));
+    }
 }
index 1eed581a917c4b9393b4642252d81254c9589fd5..ddc59b13ce80e0bc497bca204cb2f00494807fc0 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangide.ext.model.editor.editors;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EAttribute;
@@ -45,6 +46,7 @@ import org.opendaylight.yangide.editor.editors.YangEditor;
 import org.opendaylight.yangide.ext.model.ModelPackage;
 import org.opendaylight.yangide.ext.model.Module;
 import org.opendaylight.yangide.ext.model.Node;
+import org.opendaylight.yangide.ext.model.editor.Activator;
 import org.opendaylight.yangide.ext.model.editor.diagram.EditorFeatureProvider;
 import org.opendaylight.yangide.ext.model.editor.util.DiagramImportSupport;
 import org.opendaylight.yangide.ext.model.editor.util.LayoutUtil;
@@ -67,7 +69,9 @@ public class YangDiagramEditor extends DiagramEditor {
 
         @Override
         public void nodeRemoved(Node node) {
-            System.out.println("Removed " + node);
+            if (Activator.getDefault().isDebugging()) {
+                Activator.log(IStatus.INFO, "Removed " + node);
+            }
             PictogramElement[] elements = getDiagramTypeProvider().getFeatureProvider()
                     .getAllPictogramElementsForBusinessObject(node);
             for (PictogramElement element : elements) {
@@ -80,7 +84,9 @@ public class YangDiagramEditor extends DiagramEditor {
 
         @Override
         public void nodeChanged(Node node, EObject object, Object newValue) {
-            System.out.println("Changed " + node);
+            if (Activator.getDefault().isDebugging()) {
+                Activator.log(IStatus.INFO, "Changed " + node);
+            }
             if (object instanceof EAttribute) {
                 PictogramElement pe = YangModelUIUtil.getBusinessObjectPropShape(
                         getDiagramTypeProvider().getFeatureProvider(), node, (EAttribute) object);
@@ -93,7 +99,9 @@ public class YangDiagramEditor extends DiagramEditor {
 
         @Override
         public void nodeAdded(Node parent, Node child, int position) {
-            System.out.println("Added " + child);
+            if (Activator.getDefault().isDebugging()) {
+                Activator.log(IStatus.INFO, "Added " + child);
+            }
             if (null == YangModelUIUtil.getBusinessObjectShape(getDiagramTypeProvider().getFeatureProvider(), child)) {
                 Point p = null;
                 if (parent instanceof Module) {
@@ -187,13 +195,8 @@ public class YangDiagramEditor extends DiagramEditor {
         super.initializeGraphicalViewer();
         GraphicalViewer graphicalViewer = getGraphicalViewer();
         if (graphicalViewer != null) {
-            graphicalViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-                @Override
-                public void selectionChanged(SelectionChangedEvent event) {
-                    ((YangDiagramBehavior) getDiagramBehavior()).getYangPaletteBehavior()
-                            .updateSelection(event.getSelection());
-                }
-            });
+            graphicalViewer.addSelectionChangedListener(event -> ((YangDiagramBehavior) getDiagramBehavior()).getYangPaletteBehavior()
+            .updateSelection(event.getSelection()));
         }
         sourceSelectionUpdater = new SourceSelectionUpdater();
     }
@@ -220,7 +223,7 @@ public class YangDiagramEditor extends DiagramEditor {
                                     .getConnectionReferenceSubjectClass(notification.getNotifier());
                             if (null != type) {
                                 getDiagramBehavior().getEditingDomain().getCommandStack()
-                                        .execute(new RecordingCommand(getDiagramBehavior().getEditingDomain()) {
+                                .execute(new RecordingCommand(getDiagramBehavior().getEditingDomain()) {
 
                                     @Override
                                     protected void doExecute() {
@@ -282,7 +285,7 @@ public class YangDiagramEditor extends DiagramEditor {
 
     public void setSourceModelManager(ISourceModelManager sourceModelManager) {
         ((EditorFeatureProvider) getDiagramTypeProvider().getFeatureProvider())
-                .setSourceModelManager(sourceModelManager);
+        .setSourceModelManager(sourceModelManager);
         this.sourceModelManager = sourceModelManager;
     }
 
@@ -295,8 +298,9 @@ public class YangDiagramEditor extends DiagramEditor {
      */
     public void startSourceSelectionUpdater() {
         GraphicalViewer graphicalViewer = getGraphicalViewer();
-        if (graphicalViewer != null)
+        if (graphicalViewer != null) {
             graphicalViewer.addSelectionChangedListener(sourceSelectionUpdater);
+        }
     }
 
     /**
@@ -304,8 +308,9 @@ public class YangDiagramEditor extends DiagramEditor {
      */
     public void stopSourceSelectionUpdater() {
         GraphicalViewer graphicalViewer = getGraphicalViewer();
-        if (graphicalViewer != null)
+        if (graphicalViewer != null) {
             graphicalViewer.removeSelectionChangedListener(sourceSelectionUpdater);
+        }
     }
 
     private class SourceSelectionUpdater implements ISelectionChangedListener {
@@ -314,7 +319,7 @@ public class YangDiagramEditor extends DiagramEditor {
             IStructuredSelection selection = (IStructuredSelection) event.getSelection();
             Object object = selection.getFirstElement();
             if (object instanceof GraphitiShapeEditPart) {
-                PictogramElement element = (PictogramElement) ((GraphitiShapeEditPart) object).getPictogramElement();
+                PictogramElement element = ((GraphitiShapeEditPart) object).getPictogramElement();
                 EObject node = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(element);
                 ASTNode moduleNode = sourceModelManager.getModuleNode((Node) node);
                 IRegion region = YangEditor.getSelectionRegion(moduleNode);
index 733815c064e7d270746fbe71a662d480585a0c1b..ad7d555d28e0949e1535f12d29dc0465078ea18e 100644 (file)
                        <arguments>
                        </arguments>
                </buildCommand>
+               <buildCommand>
+                       <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
@@ -30,5 +35,6 @@
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
                <nature>org.eclipse.pde.PluginNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
        </natures>
 </projectDescription>
index aa5df677219b613693230ba9a5da620af0926749..1a914cc680303456306a8df94d08e8c50fd6e047 100644 (file)
                        <arguments>
                        </arguments>
                </buildCommand>
+               <buildCommand>
+                       <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
@@ -30,5 +35,6 @@
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
                <nature>org.eclipse.pde.PluginNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
        </natures>
 </projectDescription>
index 374d6cd63a660dff94079f95cec57d4fc4a16bfc..43ee3a21c9f1d13dba0a8e4852b3607c7f064dd4 100644 (file)
                        <arguments>
                        </arguments>
                </buildCommand>
+               <buildCommand>
+                       <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
@@ -30,5 +35,6 @@
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
                <nature>org.eclipse.pde.PluginNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
        </natures>
 </projectDescription>
index 47b8831d18a3ee7a145f85b99d0bbfa286b081f3..d54deed330429df2427e8b240c7757f35b45058b 100644 (file)
@@ -5,6 +5,11 @@
        <projects>
        </projects>
        <buildSpec>
+               <buildCommand>
+                       <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
@@ -13,5 +18,6 @@
        </buildSpec>
        <natures>
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
+               <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
        </natures>
 </projectDescription>