repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/RootTaskScanner.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/TaskCollector.java
// public interface TaskCollector extends ICollector<Task> {
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/TaskScanner.java
// public interface TaskScanner {
//
// /**
// * Adds Tasks to the supplied collector.
// *
// * @param collector the collector of {@link Task}s.
// */
// void scan(TaskCollector collector);
//
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/MechanicLog.java
// public class MechanicLog {
// private static MechanicLog DEFAULT;
//
// private final ILog log;
//
// /**
// * Get the default instance.
// */
// public synchronized static MechanicLog getDefault() {
// if (DEFAULT == null) {
// DEFAULT = new MechanicLog(MechanicPlugin.getDefault());
// }
// return DEFAULT;
// }
//
// MechanicLog(Plugin plugin) {
// this(plugin.getLog());
// }
//
// public MechanicLog(ILog log) {
// this.log = Preconditions.checkNotNull(log);
// }
//
// /**
// * Log a status.
// */
// public void log(IStatus status) {
// log.log(status);
// }
//
// /**
// * Log an error to the Eclipse log.
// *
// * @param t the throwable.
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void logError(Throwable t, String fmt, Object... args) {
// String text = (args.length > 0) ? String.format(fmt, args) : fmt;
// log(new Status(IStatus.ERROR, MechanicPlugin.PLUGIN_ID, text, t));
// }
//
// /**
// * Log an error to the Eclipse log, using the exception's message as the log message text.
// *
// * @param t the throwable.
// */
// public void logError(Throwable t) {
// logError(t, t.getMessage());
// }
//
// /**
// * Log info to the Eclipse log.
// *
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void logInfo(String fmt, Object... args) {
// log(IStatus.INFO, fmt, args);
// }
//
// /**
// * Log warning to the Eclipse log.
// *
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void logWarning(String fmt, Object... args) {
// log(IStatus.WARNING, fmt, args);
// }
//
//
// /**
// * Log a message to the Eclipse log.
// *
// * @param severity message severity. Reference {@link IStatus#getSeverity()}.
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void log(int severity, String fmt, Object... args) {
// String text = (args.length > 0) ? String.format(fmt, args) : fmt;
// log(new Status(severity, MechanicPlugin.PLUGIN_ID, text));
// }
// }
| import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.google.eclipse.mechanic.TaskCollector;
import com.google.eclipse.mechanic.TaskScanner;
import com.google.eclipse.mechanic.plugin.core.MechanicLog; | /*******************************************************************************
* Copyright (C) 2007, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* A {@link TaskScanner} that loads and runs all other {@link TaskScanner}s.
*/
public class RootTaskScanner implements TaskScanner {
private static RootTaskScanner instance;
private final MechanicLog log;
private final Supplier<List<TaskScanner>> scannersExtensionPoint;
public RootTaskScanner() {
this(MechanicLog.getDefault(), ScannersExtensionPoint.getInstance());
}
@VisibleForTesting
RootTaskScanner(MechanicLog log, Supplier<List<TaskScanner>> scannersExtensionPoint) {
this.log = log;
this.scannersExtensionPoint = scannersExtensionPoint;
}
public synchronized static RootTaskScanner getInstance() {
if (instance == null) {
instance = new RootTaskScanner();
}
return instance;
}
| // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/TaskCollector.java
// public interface TaskCollector extends ICollector<Task> {
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/TaskScanner.java
// public interface TaskScanner {
//
// /**
// * Adds Tasks to the supplied collector.
// *
// * @param collector the collector of {@link Task}s.
// */
// void scan(TaskCollector collector);
//
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/MechanicLog.java
// public class MechanicLog {
// private static MechanicLog DEFAULT;
//
// private final ILog log;
//
// /**
// * Get the default instance.
// */
// public synchronized static MechanicLog getDefault() {
// if (DEFAULT == null) {
// DEFAULT = new MechanicLog(MechanicPlugin.getDefault());
// }
// return DEFAULT;
// }
//
// MechanicLog(Plugin plugin) {
// this(plugin.getLog());
// }
//
// public MechanicLog(ILog log) {
// this.log = Preconditions.checkNotNull(log);
// }
//
// /**
// * Log a status.
// */
// public void log(IStatus status) {
// log.log(status);
// }
//
// /**
// * Log an error to the Eclipse log.
// *
// * @param t the throwable.
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void logError(Throwable t, String fmt, Object... args) {
// String text = (args.length > 0) ? String.format(fmt, args) : fmt;
// log(new Status(IStatus.ERROR, MechanicPlugin.PLUGIN_ID, text, t));
// }
//
// /**
// * Log an error to the Eclipse log, using the exception's message as the log message text.
// *
// * @param t the throwable.
// */
// public void logError(Throwable t) {
// logError(t, t.getMessage());
// }
//
// /**
// * Log info to the Eclipse log.
// *
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void logInfo(String fmt, Object... args) {
// log(IStatus.INFO, fmt, args);
// }
//
// /**
// * Log warning to the Eclipse log.
// *
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void logWarning(String fmt, Object... args) {
// log(IStatus.WARNING, fmt, args);
// }
//
//
// /**
// * Log a message to the Eclipse log.
// *
// * @param severity message severity. Reference {@link IStatus#getSeverity()}.
// * @param fmt string format
// * @param args args that accompany the string format. If this is empty, fmt is assumed to be
// * an unformatted string.
// */
// public void log(int severity, String fmt, Object... args) {
// String text = (args.length > 0) ? String.format(fmt, args) : fmt;
// log(new Status(severity, MechanicPlugin.PLUGIN_ID, text));
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/RootTaskScanner.java
import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.google.eclipse.mechanic.TaskCollector;
import com.google.eclipse.mechanic.TaskScanner;
import com.google.eclipse.mechanic.plugin.core.MechanicLog;
/*******************************************************************************
* Copyright (C) 2007, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* A {@link TaskScanner} that loads and runs all other {@link TaskScanner}s.
*/
public class RootTaskScanner implements TaskScanner {
private static RootTaskScanner instance;
private final MechanicLog log;
private final Supplier<List<TaskScanner>> scannersExtensionPoint;
public RootTaskScanner() {
this(MechanicLog.getDefault(), ScannersExtensionPoint.getInstance());
}
@VisibleForTesting
RootTaskScanner(MechanicLog log, Supplier<List<TaskScanner>> scannersExtensionPoint) {
this.log = log;
this.scannersExtensionPoint = scannersExtensionPoint;
}
public synchronized static RootTaskScanner getInstance() {
if (instance == null) {
instance = new RootTaskScanner();
}
return instance;
}
| public void scan(TaskCollector collector) { |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ScannersExtensionPoint.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/TaskScanner.java
// public interface TaskScanner {
//
// /**
// * Adds Tasks to the supplied collector.
// *
// * @param collector the collector of {@link Task}s.
// */
// void scan(TaskCollector collector);
//
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/MechanicPlugin.java
// public class MechanicPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "com.google.eclipse.mechanic";
//
// // The shared instance
// private static MechanicPlugin plugin;
//
// private IMechanicPreferences mechanicPreferences;
//
// private volatile IPreferenceRecordingService preferenceRecordingService =
// new PreferenceRecordingService();
//
// private PopupNotifier popupNotifier;
//
// public MechanicPlugin() {
// plugin = this;
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
//
// mechanicPreferences = new MechanicPreferences();
//
// // popup notifier must start before the mechanic service in order to
// // catch the first statuses.
// popupNotifier = new PopupNotifier(MechanicService.getInstance(), getMechanicPreferences());
// popupNotifier.initialize();
//
// UriCaches.initialize();
//
// // immediately start the mechanic service
// MechanicService.getInstance().start();
// }
//
// @Override
// public void stop(BundleContext context) throws Exception {
// MechanicService.getInstance().stop();
// UriCaches.destroy();
// popupNotifier.dispose();
// TasksExtensionPoint.dispose();
// ScannersExtensionPoint.dispose();
// ResourceTaskProvidersExtensionPoint.dispose();
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Keep this around as some of the generated code expects it.
// * @return shared instance of this plug-in class
// */
// public static MechanicPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(PLUGIN_ID, path);
// }
//
// public IPreferenceRecordingService getPreferenceRecordingService() {
// if (preferenceRecordingService == null) {
// preferenceRecordingService = new PreferenceRecordingService();
// }
//
// return preferenceRecordingService;
// }
//
// public IMechanicPreferences getMechanicPreferences() {
// return mechanicPreferences;
// }
// }
| import java.util.List;
import org.eclipse.core.runtime.Platform;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.eclipse.mechanic.TaskScanner;
import com.google.eclipse.mechanic.plugin.core.MechanicPlugin; | /*******************************************************************************
* Copyright (C) 2009, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Code behind the {@code com.google.eclipse.mechanic.scanners} extension point.
*
* <p>This class interfaces with the {@link Platform}, reading all extensions of the
* {@code scanners} extension point, providing a mechanism for translating their
* implementations to instances of {@link TaskScanner}.
*/
public class ScannersExtensionPoint {
private static final String EXTENSION_POINT_NAME = "scanners";
private static final String TAG_SCANNER = "scanner";
private static final String ATTR_CLASS = "class";
// Initialization On Demand Holder Idiom
// http://crazybob.org/2007/01/lazy-loading-singletons.html
private static class SingletonHolder { | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/TaskScanner.java
// public interface TaskScanner {
//
// /**
// * Adds Tasks to the supplied collector.
// *
// * @param collector the collector of {@link Task}s.
// */
// void scan(TaskCollector collector);
//
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/MechanicPlugin.java
// public class MechanicPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "com.google.eclipse.mechanic";
//
// // The shared instance
// private static MechanicPlugin plugin;
//
// private IMechanicPreferences mechanicPreferences;
//
// private volatile IPreferenceRecordingService preferenceRecordingService =
// new PreferenceRecordingService();
//
// private PopupNotifier popupNotifier;
//
// public MechanicPlugin() {
// plugin = this;
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
//
// mechanicPreferences = new MechanicPreferences();
//
// // popup notifier must start before the mechanic service in order to
// // catch the first statuses.
// popupNotifier = new PopupNotifier(MechanicService.getInstance(), getMechanicPreferences());
// popupNotifier.initialize();
//
// UriCaches.initialize();
//
// // immediately start the mechanic service
// MechanicService.getInstance().start();
// }
//
// @Override
// public void stop(BundleContext context) throws Exception {
// MechanicService.getInstance().stop();
// UriCaches.destroy();
// popupNotifier.dispose();
// TasksExtensionPoint.dispose();
// ScannersExtensionPoint.dispose();
// ResourceTaskProvidersExtensionPoint.dispose();
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Keep this around as some of the generated code expects it.
// * @return shared instance of this plug-in class
// */
// public static MechanicPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(PLUGIN_ID, path);
// }
//
// public IPreferenceRecordingService getPreferenceRecordingService() {
// if (preferenceRecordingService == null) {
// preferenceRecordingService = new PreferenceRecordingService();
// }
//
// return preferenceRecordingService;
// }
//
// public IMechanicPreferences getMechanicPreferences() {
// return mechanicPreferences;
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ScannersExtensionPoint.java
import java.util.List;
import org.eclipse.core.runtime.Platform;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.eclipse.mechanic.TaskScanner;
import com.google.eclipse.mechanic.plugin.core.MechanicPlugin;
/*******************************************************************************
* Copyright (C) 2009, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Code behind the {@code com.google.eclipse.mechanic.scanners} extension point.
*
* <p>This class interfaces with the {@link Platform}, reading all extensions of the
* {@code scanners} extension point, providing a mechanism for translating their
* implementations to instances of {@link TaskScanner}.
*/
public class ScannersExtensionPoint {
private static final String EXTENSION_POINT_NAME = "scanners";
private static final String TAG_SCANNER = "scanner";
private static final String ATTR_CLASS = "class";
// Initialization On Demand Holder Idiom
// http://crazybob.org/2007/01/lazy-loading-singletons.html
private static class SingletonHolder { | static SimpleExtensionPointManager<TaskScanner> instance = |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ResourceTaskScanner.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ResourceTaskProvidersExtensionPoint.java
// public class ResourceTaskProvidersExtensionPoint {
// private static final String EXTENSION_POINT_NAME = "resourcetaskproviders";
// private static final String TAG_TASK = "provider";
// private static final String ATTR_CLASS = "class";
//
// // Initialization On Demand Holder Idiom
// // http://crazybob.org/2007/01/lazy-loading-singletons.html
// private static class SingletonHolder {
// static SimpleExtensionPointManager<IResourceTaskProvider> instance =
// SimpleExtensionPointManager.newInstance(
// EXTENSION_POINT_NAME,
// IResourceTaskProvider.class,
// TAG_TASK,
// ATTR_CLASS,
// null);
// }
//
// private ResourceTaskProvidersExtensionPoint() {
// }
//
// /**
// * Return the {@link IResourceTaskProvider} supplier, initializing it if required.
// *
// * <p>The supplier is memoized, so it will return the same instantiated
// * objects upon repeated calls.
// */
// public static Supplier<List<IResourceTaskProvider>> getInstance() {
// return Suppliers.memoize(new Supplier<List<IResourceTaskProvider>>() {
// public List<IResourceTaskProvider> get() {
// return SingletonHolder.instance.getInstances();
// }
// });
// }
//
// /**
// * Clears the list of task providers.
// *
// * <p><em>This should only be called by {@link MechanicPlugin#stop}.</em>
// */
// public static void dispose() {
// SingletonHolder.instance = null;
// }
// }
| import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.eclipse.mechanic.internal.ResourceTaskProvidersExtensionPoint; | /*******************************************************************************
* Copyright (C) 2009, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic;
/**
* Scanner that looks in the registered {@link IResourceTaskProvider}s
* for tasks.
*/
public abstract class ResourceTaskScanner implements TaskScanner {
private final Supplier<List<IResourceTaskProvider>> supplier;
public ResourceTaskScanner() { | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ResourceTaskProvidersExtensionPoint.java
// public class ResourceTaskProvidersExtensionPoint {
// private static final String EXTENSION_POINT_NAME = "resourcetaskproviders";
// private static final String TAG_TASK = "provider";
// private static final String ATTR_CLASS = "class";
//
// // Initialization On Demand Holder Idiom
// // http://crazybob.org/2007/01/lazy-loading-singletons.html
// private static class SingletonHolder {
// static SimpleExtensionPointManager<IResourceTaskProvider> instance =
// SimpleExtensionPointManager.newInstance(
// EXTENSION_POINT_NAME,
// IResourceTaskProvider.class,
// TAG_TASK,
// ATTR_CLASS,
// null);
// }
//
// private ResourceTaskProvidersExtensionPoint() {
// }
//
// /**
// * Return the {@link IResourceTaskProvider} supplier, initializing it if required.
// *
// * <p>The supplier is memoized, so it will return the same instantiated
// * objects upon repeated calls.
// */
// public static Supplier<List<IResourceTaskProvider>> getInstance() {
// return Suppliers.memoize(new Supplier<List<IResourceTaskProvider>>() {
// public List<IResourceTaskProvider> get() {
// return SingletonHolder.instance.getInstances();
// }
// });
// }
//
// /**
// * Clears the list of task providers.
// *
// * <p><em>This should only be called by {@link MechanicPlugin#stop}.</em>
// */
// public static void dispose() {
// SingletonHolder.instance = null;
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ResourceTaskScanner.java
import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.eclipse.mechanic.internal.ResourceTaskProvidersExtensionPoint;
/*******************************************************************************
* Copyright (C) 2009, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic;
/**
* Scanner that looks in the registered {@link IResourceTaskProvider}s
* for tasks.
*/
public abstract class ResourceTaskScanner implements TaskScanner {
private final Supplier<List<IResourceTaskProvider>> supplier;
public ResourceTaskScanner() { | this(ResourceTaskProvidersExtensionPoint.getInstance()); |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ResourceTaskProvidersExtensionPoint.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskProvider.java
// public interface IResourceTaskProvider {
// /**
// * Collect task references provided by this provider.
// *
// * <p>In theory this is similar to calling
// * {@code collectTaskReferences(".", extFilter, collector)}, but
// * that's in theory only.
// *
// * @param extFilter the filename extension to filter.
// * @param collector the collector to receive all task references.
// *
// * TODO(konigsberg): Remove the filter parameter.
// */
// void collectTaskReferences(
// String extFilter,
// ICollector<IResourceTaskReference> collector);
//
// /**
// * Collect task references provided by this provider, relative to the
// * provider's root.
// *
// * <p>This is only used for finding Class-based tasks, and is not even
// * implemented in the UriTaskProvider.
// *
// * @param localPath the relative path to the resources
// * @param extFilter the filename extension to filter.
// * @param collector the collector to receive all task references.
// *
// * TODO(konigsberg): Remove the filter parameter.
// */
// void collectTaskReferences(
// String localPath,
// String extFilter,
// ICollector<IResourceTaskReference> collector);
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/MechanicPlugin.java
// public class MechanicPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "com.google.eclipse.mechanic";
//
// // The shared instance
// private static MechanicPlugin plugin;
//
// private IMechanicPreferences mechanicPreferences;
//
// private volatile IPreferenceRecordingService preferenceRecordingService =
// new PreferenceRecordingService();
//
// private PopupNotifier popupNotifier;
//
// public MechanicPlugin() {
// plugin = this;
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
//
// mechanicPreferences = new MechanicPreferences();
//
// // popup notifier must start before the mechanic service in order to
// // catch the first statuses.
// popupNotifier = new PopupNotifier(MechanicService.getInstance(), getMechanicPreferences());
// popupNotifier.initialize();
//
// UriCaches.initialize();
//
// // immediately start the mechanic service
// MechanicService.getInstance().start();
// }
//
// @Override
// public void stop(BundleContext context) throws Exception {
// MechanicService.getInstance().stop();
// UriCaches.destroy();
// popupNotifier.dispose();
// TasksExtensionPoint.dispose();
// ScannersExtensionPoint.dispose();
// ResourceTaskProvidersExtensionPoint.dispose();
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Keep this around as some of the generated code expects it.
// * @return shared instance of this plug-in class
// */
// public static MechanicPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(PLUGIN_ID, path);
// }
//
// public IPreferenceRecordingService getPreferenceRecordingService() {
// if (preferenceRecordingService == null) {
// preferenceRecordingService = new PreferenceRecordingService();
// }
//
// return preferenceRecordingService;
// }
//
// public IMechanicPreferences getMechanicPreferences() {
// return mechanicPreferences;
// }
// }
| import java.util.List;
import org.eclipse.core.runtime.Platform;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.eclipse.mechanic.IResourceTaskProvider;
import com.google.eclipse.mechanic.plugin.core.MechanicPlugin; | /*******************************************************************************
* Copyright (C) 2014, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Code behind the {@code com.google.eclipse.mechanic.resourcetaskproviders} extension point.
*
* <p>This class interfaces with the {@link Platform}, reading all extensions of the
* {@code tasks} extension point, providing a mechanism for translating their
* implementations to instances of {@link IResourceTaskProvider}.
*/
public class ResourceTaskProvidersExtensionPoint {
private static final String EXTENSION_POINT_NAME = "resourcetaskproviders";
private static final String TAG_TASK = "provider";
private static final String ATTR_CLASS = "class";
// Initialization On Demand Holder Idiom
// http://crazybob.org/2007/01/lazy-loading-singletons.html
private static class SingletonHolder { | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskProvider.java
// public interface IResourceTaskProvider {
// /**
// * Collect task references provided by this provider.
// *
// * <p>In theory this is similar to calling
// * {@code collectTaskReferences(".", extFilter, collector)}, but
// * that's in theory only.
// *
// * @param extFilter the filename extension to filter.
// * @param collector the collector to receive all task references.
// *
// * TODO(konigsberg): Remove the filter parameter.
// */
// void collectTaskReferences(
// String extFilter,
// ICollector<IResourceTaskReference> collector);
//
// /**
// * Collect task references provided by this provider, relative to the
// * provider's root.
// *
// * <p>This is only used for finding Class-based tasks, and is not even
// * implemented in the UriTaskProvider.
// *
// * @param localPath the relative path to the resources
// * @param extFilter the filename extension to filter.
// * @param collector the collector to receive all task references.
// *
// * TODO(konigsberg): Remove the filter parameter.
// */
// void collectTaskReferences(
// String localPath,
// String extFilter,
// ICollector<IResourceTaskReference> collector);
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/MechanicPlugin.java
// public class MechanicPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "com.google.eclipse.mechanic";
//
// // The shared instance
// private static MechanicPlugin plugin;
//
// private IMechanicPreferences mechanicPreferences;
//
// private volatile IPreferenceRecordingService preferenceRecordingService =
// new PreferenceRecordingService();
//
// private PopupNotifier popupNotifier;
//
// public MechanicPlugin() {
// plugin = this;
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
//
// mechanicPreferences = new MechanicPreferences();
//
// // popup notifier must start before the mechanic service in order to
// // catch the first statuses.
// popupNotifier = new PopupNotifier(MechanicService.getInstance(), getMechanicPreferences());
// popupNotifier.initialize();
//
// UriCaches.initialize();
//
// // immediately start the mechanic service
// MechanicService.getInstance().start();
// }
//
// @Override
// public void stop(BundleContext context) throws Exception {
// MechanicService.getInstance().stop();
// UriCaches.destroy();
// popupNotifier.dispose();
// TasksExtensionPoint.dispose();
// ScannersExtensionPoint.dispose();
// ResourceTaskProvidersExtensionPoint.dispose();
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Keep this around as some of the generated code expects it.
// * @return shared instance of this plug-in class
// */
// public static MechanicPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(PLUGIN_ID, path);
// }
//
// public IPreferenceRecordingService getPreferenceRecordingService() {
// if (preferenceRecordingService == null) {
// preferenceRecordingService = new PreferenceRecordingService();
// }
//
// return preferenceRecordingService;
// }
//
// public IMechanicPreferences getMechanicPreferences() {
// return mechanicPreferences;
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/ResourceTaskProvidersExtensionPoint.java
import java.util.List;
import org.eclipse.core.runtime.Platform;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.eclipse.mechanic.IResourceTaskProvider;
import com.google.eclipse.mechanic.plugin.core.MechanicPlugin;
/*******************************************************************************
* Copyright (C) 2014, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Code behind the {@code com.google.eclipse.mechanic.resourcetaskproviders} extension point.
*
* <p>This class interfaces with the {@link Platform}, reading all extensions of the
* {@code tasks} extension point, providing a mechanism for translating their
* implementations to instances of {@link IResourceTaskProvider}.
*/
public class ResourceTaskProvidersExtensionPoint {
private static final String EXTENSION_POINT_NAME = "resourcetaskproviders";
private static final String TAG_TASK = "provider";
private static final String ATTR_CLASS = "class";
// Initialization On Demand Holder Idiom
// http://crazybob.org/2007/01/lazy-loading-singletons.html
private static class SingletonHolder { | static SimpleExtensionPointManager<IResourceTaskProvider> instance = |
alfsch/workspacemechanic | parent/tests/com.google.eclipse.mechanic.tests/src/com/google/eclipse/mechanic/internal/UriTaskProviderTest.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ListCollector.java
// public class ListCollector<T> implements ICollector<T> {
// private final List<T> list = Lists.newArrayList();
//
// public static <T> ListCollector<T> create() {
// return new ListCollector<T>();
// }
//
// public void collect(T element) {
// list.add(element);
// }
//
// public List<T> get() {
// return list;
// }
// }
| import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import junit.framework.TestCase;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.ListCollector;
import com.google.eclipse.mechanic.tests.internal.RunAsJUnitTest; | /*******************************************************************************
* Copyright (C) 2011, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Tests for (@link {@link UriTaskProvider}.
*
*/
@RunAsJUnitTest
public class UriTaskProviderTest extends TestCase {
private static final String CONTENT =
"{ type : 'com.google.eclipse.mechanic.UriTaskProviderModel', " +
"metadata : {" +
" name: 'green hornet'," +
" description: 'i wear green and i fight crime'," +
" contact: 'greenhornet.com'" +
"}, " +
"tasks: [" +
" 'http://www.google.com/foo/bar/baz', " +
" 'path'," +
" 'path2'" +
"]" +
"} ";
public void testRelativize() throws Exception {
URI uri = URI.create("http://www.testuri.com/mechanic/tasks/schema");
IUriContentProvider cache = mock(IUriContentProvider.class);
when(cache.get(uri)).thenReturn(asInputStream(CONTENT));
UriTaskProvider provider = UriTaskProvider.newInstance(uri, cache, cache); | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ListCollector.java
// public class ListCollector<T> implements ICollector<T> {
// private final List<T> list = Lists.newArrayList();
//
// public static <T> ListCollector<T> create() {
// return new ListCollector<T>();
// }
//
// public void collect(T element) {
// list.add(element);
// }
//
// public List<T> get() {
// return list;
// }
// }
// Path: parent/tests/com.google.eclipse.mechanic.tests/src/com/google/eclipse/mechanic/internal/UriTaskProviderTest.java
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import junit.framework.TestCase;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.ListCollector;
import com.google.eclipse.mechanic.tests.internal.RunAsJUnitTest;
/*******************************************************************************
* Copyright (C) 2011, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Tests for (@link {@link UriTaskProvider}.
*
*/
@RunAsJUnitTest
public class UriTaskProviderTest extends TestCase {
private static final String CONTENT =
"{ type : 'com.google.eclipse.mechanic.UriTaskProviderModel', " +
"metadata : {" +
" name: 'green hornet'," +
" description: 'i wear green and i fight crime'," +
" contact: 'greenhornet.com'" +
"}, " +
"tasks: [" +
" 'http://www.google.com/foo/bar/baz', " +
" 'path'," +
" 'path2'" +
"]" +
"} ";
public void testRelativize() throws Exception {
URI uri = URI.create("http://www.testuri.com/mechanic/tasks/schema");
IUriContentProvider cache = mock(IUriContentProvider.class);
when(cache.get(uri)).thenReturn(asInputStream(CONTENT));
UriTaskProvider provider = UriTaskProvider.newInstance(uri, cache, cache); | ListCollector<IResourceTaskReference> collector = ListCollector.create(); |
alfsch/workspacemechanic | parent/tests/com.google.eclipse.mechanic.tests/src/com/google/eclipse/mechanic/internal/UriTaskProviderTest.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ListCollector.java
// public class ListCollector<T> implements ICollector<T> {
// private final List<T> list = Lists.newArrayList();
//
// public static <T> ListCollector<T> create() {
// return new ListCollector<T>();
// }
//
// public void collect(T element) {
// list.add(element);
// }
//
// public List<T> get() {
// return list;
// }
// }
| import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import junit.framework.TestCase;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.ListCollector;
import com.google.eclipse.mechanic.tests.internal.RunAsJUnitTest; | /*******************************************************************************
* Copyright (C) 2011, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Tests for (@link {@link UriTaskProvider}.
*
*/
@RunAsJUnitTest
public class UriTaskProviderTest extends TestCase {
private static final String CONTENT =
"{ type : 'com.google.eclipse.mechanic.UriTaskProviderModel', " +
"metadata : {" +
" name: 'green hornet'," +
" description: 'i wear green and i fight crime'," +
" contact: 'greenhornet.com'" +
"}, " +
"tasks: [" +
" 'http://www.google.com/foo/bar/baz', " +
" 'path'," +
" 'path2'" +
"]" +
"} ";
public void testRelativize() throws Exception {
URI uri = URI.create("http://www.testuri.com/mechanic/tasks/schema");
IUriContentProvider cache = mock(IUriContentProvider.class);
when(cache.get(uri)).thenReturn(asInputStream(CONTENT));
UriTaskProvider provider = UriTaskProvider.newInstance(uri, cache, cache); | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ListCollector.java
// public class ListCollector<T> implements ICollector<T> {
// private final List<T> list = Lists.newArrayList();
//
// public static <T> ListCollector<T> create() {
// return new ListCollector<T>();
// }
//
// public void collect(T element) {
// list.add(element);
// }
//
// public List<T> get() {
// return list;
// }
// }
// Path: parent/tests/com.google.eclipse.mechanic.tests/src/com/google/eclipse/mechanic/internal/UriTaskProviderTest.java
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import junit.framework.TestCase;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.ListCollector;
import com.google.eclipse.mechanic.tests.internal.RunAsJUnitTest;
/*******************************************************************************
* Copyright (C) 2011, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Tests for (@link {@link UriTaskProvider}.
*
*/
@RunAsJUnitTest
public class UriTaskProviderTest extends TestCase {
private static final String CONTENT =
"{ type : 'com.google.eclipse.mechanic.UriTaskProviderModel', " +
"metadata : {" +
" name: 'green hornet'," +
" description: 'i wear green and i fight crime'," +
" contact: 'greenhornet.com'" +
"}, " +
"tasks: [" +
" 'http://www.google.com/foo/bar/baz', " +
" 'path'," +
" 'path2'" +
"]" +
"} ";
public void testRelativize() throws Exception {
URI uri = URI.create("http://www.testuri.com/mechanic/tasks/schema");
IUriContentProvider cache = mock(IUriContentProvider.class);
when(cache.get(uri)).thenReturn(asInputStream(CONTENT));
UriTaskProvider provider = UriTaskProvider.newInstance(uri, cache, cache); | ListCollector<IResourceTaskReference> collector = ListCollector.create(); |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/ui/TaskSelectionDialog.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/Task.java
// public interface Task {
//
// /**
// * Return an id for this task. The id should be unique to any instance that
// * behaves differently than another instance. Typically the id would be the
// * fully qualified class name unless two task instances somehow manage to
// * behave differently. In this case they should each return a unique id.
// */
// public String getId();
//
// /**
// * Returns a string suitable for display to the user providing a title for
// * this Task. This is used in contexts where a short
// * description is needed. Capitalization should follow the same rules as
// * applied to book titles.
// */
// public String getTitle();
//
// /**
// * Returns a string suitable for display to the user describing what action
// * will be taken when the associated {@link RepairAction} is executed.
// * <p/>
// * The description should start with a 3rd person descriptive verb such as:
// * <p/>
// * "Customizes your java code templates with user information."
// * "Configures a local extension location."
// */
// public String getDescription();
//
// /**
// * Returns an Evaluator for this task. The Evaluator should return false
// * if the associated RepairAction needs to be executed.
// */
// public Evaluator getEvaluator();
//
// /**
// * Returns a {@link RepairAction} capable of bringing this {@link Task}
// * into compliance.
// */
// public RepairAction getRepairAction();
// }
| import com.google.eclipse.mechanic.Task;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.dialogs.ListDialog;
import java.util.Collection; | /*******************************************************************************
* Copyright (C) 2007, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.plugin.ui;
/**
* Allows the user to pick a single Task from a list of Tasks.
*
* TODO(smckay): We should pretty this up to use a view similar to the
* MechanicDialog.
*/
public final class TaskSelectionDialog extends ListDialog {
public TaskSelectionDialog(Shell parent, String title, | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/Task.java
// public interface Task {
//
// /**
// * Return an id for this task. The id should be unique to any instance that
// * behaves differently than another instance. Typically the id would be the
// * fully qualified class name unless two task instances somehow manage to
// * behave differently. In this case they should each return a unique id.
// */
// public String getId();
//
// /**
// * Returns a string suitable for display to the user providing a title for
// * this Task. This is used in contexts where a short
// * description is needed. Capitalization should follow the same rules as
// * applied to book titles.
// */
// public String getTitle();
//
// /**
// * Returns a string suitable for display to the user describing what action
// * will be taken when the associated {@link RepairAction} is executed.
// * <p/>
// * The description should start with a 3rd person descriptive verb such as:
// * <p/>
// * "Customizes your java code templates with user information."
// * "Configures a local extension location."
// */
// public String getDescription();
//
// /**
// * Returns an Evaluator for this task. The Evaluator should return false
// * if the associated RepairAction needs to be executed.
// */
// public Evaluator getEvaluator();
//
// /**
// * Returns a {@link RepairAction} capable of bringing this {@link Task}
// * into compliance.
// */
// public RepairAction getRepairAction();
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/ui/TaskSelectionDialog.java
import com.google.eclipse.mechanic.Task;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.dialogs.ListDialog;
import java.util.Collection;
/*******************************************************************************
* Copyright (C) 2007, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.plugin.ui;
/**
* Allows the user to pick a single Task from a list of Tasks.
*
* TODO(smckay): We should pretty this up to use a view similar to the
* MechanicDialog.
*/
public final class TaskSelectionDialog extends ListDialog {
public TaskSelectionDialog(Shell parent, String title, | Collection<Task> items) { |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/UriTaskProvider.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ICollector.java
// public interface ICollector<T> {
// /**
// * Add a element to the collector.
// */
// void collect(T element);
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/ResourceTaskProvider.java
// public abstract class ResourceTaskProvider implements IResourceTaskProvider {
//
// /**
// * Throws exception, ensures subclasses implement equals method.
// */
// @Override
// public boolean equals(Object obj) {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement equals");
// }
//
// /**
// * Throws exception, ensures subclasses implement hashCode method.
// */
// @Override
// public int hashCode() {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement hashCode");
// }
// }
| import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import com.google.common.base.Preconditions;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteStreams;
import com.google.common.io.InputSupplier;
import com.google.eclipse.mechanic.ICollector;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.plugin.core.ResourceTaskProvider;
import com.google.gson.JsonSyntaxException; | /*******************************************************************************
* Copyright (C) 2011, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Provides information about tasks that come from URIs.
*/
public final class UriTaskProvider extends ResourceTaskProvider {
private final URI uri;
private UriTaskProviderModel model;
private final IUriContentProvider stateSensitiveCache;
private final IUriContentProvider longTermCache;
| // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ICollector.java
// public interface ICollector<T> {
// /**
// * Add a element to the collector.
// */
// void collect(T element);
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/ResourceTaskProvider.java
// public abstract class ResourceTaskProvider implements IResourceTaskProvider {
//
// /**
// * Throws exception, ensures subclasses implement equals method.
// */
// @Override
// public boolean equals(Object obj) {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement equals");
// }
//
// /**
// * Throws exception, ensures subclasses implement hashCode method.
// */
// @Override
// public int hashCode() {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement hashCode");
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/UriTaskProvider.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import com.google.common.base.Preconditions;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteStreams;
import com.google.common.io.InputSupplier;
import com.google.eclipse.mechanic.ICollector;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.plugin.core.ResourceTaskProvider;
import com.google.gson.JsonSyntaxException;
/*******************************************************************************
* Copyright (C) 2011, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.internal;
/**
* Provides information about tasks that come from URIs.
*/
public final class UriTaskProvider extends ResourceTaskProvider {
private final URI uri;
private UriTaskProviderModel model;
private final IUriContentProvider stateSensitiveCache;
private final IUriContentProvider longTermCache;
| private final class TaskReference implements IResourceTaskReference { |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/UriTaskProvider.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ICollector.java
// public interface ICollector<T> {
// /**
// * Add a element to the collector.
// */
// void collect(T element);
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/ResourceTaskProvider.java
// public abstract class ResourceTaskProvider implements IResourceTaskProvider {
//
// /**
// * Throws exception, ensures subclasses implement equals method.
// */
// @Override
// public boolean equals(Object obj) {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement equals");
// }
//
// /**
// * Throws exception, ensures subclasses implement hashCode method.
// */
// @Override
// public int hashCode() {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement hashCode");
// }
// }
| import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import com.google.common.base.Preconditions;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteStreams;
import com.google.common.io.InputSupplier;
import com.google.eclipse.mechanic.ICollector;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.plugin.core.ResourceTaskProvider;
import com.google.gson.JsonSyntaxException; | * Create a new instance.
*
* <p>The constructor takes two caches. One has a shorter lifetime and so is more frequently
* polled, to get the list of tasks to process. The other has a longer lifetime (12 hours
* ATM) and is used to cache actual tasks (e.g. .epf files) which are much less likely to change.
*
* @param uri The URI that contains information about tasks.
* @param stateSensitiveCache short term cache.
* @param longTermCache long term cache.
*/
public static UriTaskProvider newInstance(
URI uri,
IUriContentProvider stateSensitiveCache,
IUriContentProvider longTermCache) throws IOException {
UriTaskProvider instance = new UriTaskProvider(
uri, stateSensitiveCache, longTermCache);
instance.setModel();
return instance;
}
private void setModel() throws IOException, JsonSyntaxException {
InputStream inputStream = stateSensitiveCache.get(uri);
try {
model = UriTaskProviderModelParser.read(inputStream);
} finally {
inputStream.close();
}
}
| // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/ICollector.java
// public interface ICollector<T> {
// /**
// * Add a element to the collector.
// */
// void collect(T element);
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/IResourceTaskReference.java
// public interface IResourceTaskReference {
// /** Return the name of the task reference. This is typically a local name. */
// String getName();
//
// /** Return the task reference as an input stream. */
// InputStream newInputStream() throws IOException;
//
// /**
// * Return the time this resource was last modified, in milliseconds since the epoch.
// */
// long getLastModified() throws IOException;
//
// /**
// * Return the task reference path. Provide enough metadata to give it some distinction,
// * separate from other providers.
// */
// String getPath();
//
// /**
// * Return the File representation of this resource. Is {@code null} it's not a File.
// */
// File asFile();
//
// /**
// * Return the MD5 hash of this task
// */
// long computeMD5() throws IOException;
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/plugin/core/ResourceTaskProvider.java
// public abstract class ResourceTaskProvider implements IResourceTaskProvider {
//
// /**
// * Throws exception, ensures subclasses implement equals method.
// */
// @Override
// public boolean equals(Object obj) {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement equals");
// }
//
// /**
// * Throws exception, ensures subclasses implement hashCode method.
// */
// @Override
// public int hashCode() {
// throw new RuntimeException(this.getClass().getName() + "doesn't implement hashCode");
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/internal/UriTaskProvider.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import com.google.common.base.Preconditions;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteStreams;
import com.google.common.io.InputSupplier;
import com.google.eclipse.mechanic.ICollector;
import com.google.eclipse.mechanic.IResourceTaskReference;
import com.google.eclipse.mechanic.plugin.core.ResourceTaskProvider;
import com.google.gson.JsonSyntaxException;
* Create a new instance.
*
* <p>The constructor takes two caches. One has a shorter lifetime and so is more frequently
* polled, to get the list of tasks to process. The other has a longer lifetime (12 hours
* ATM) and is used to cache actual tasks (e.g. .epf files) which are much less likely to change.
*
* @param uri The URI that contains information about tasks.
* @param stateSensitiveCache short term cache.
* @param longTermCache long term cache.
*/
public static UriTaskProvider newInstance(
URI uri,
IUriContentProvider stateSensitiveCache,
IUriContentProvider longTermCache) throws IOException {
UriTaskProvider instance = new UriTaskProvider(
uri, stateSensitiveCache, longTermCache);
instance.setModel();
return instance;
}
private void setModel() throws IOException, JsonSyntaxException {
InputStream inputStream = stateSensitiveCache.get(uri);
try {
model = UriTaskProviderModelParser.read(inputStream);
} finally {
inputStream.close();
}
}
| public void collectTaskReferences(String localPath, String filter, ICollector<IResourceTaskReference> collector) { |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsParser.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
// private final ImmutableList<KbaBinding> list;
//
// public KbaBindingList(KbaBinding... list) {
// this(Arrays.asList(list));
// }
//
// public KbaBindingList(Iterable<KbaBinding> list) {
// this.list = ImmutableList.copyOf(list);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(list);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaBindingList)) {
// return false;
// }
// KbaBindingList that = (KbaBindingList) obj;
// return this.list.equals(that.list);
// }
//
// @Override
// public String toString() {
// return this.list.toString();
// }
//
// public ImmutableList<KbaBinding> getList() {
// return list;
// }
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
// public static final class KbaMetaData {
//
// private final String description;
//
// public KbaMetaData(String description) {
// this.description = Preconditions.checkNotNull(description);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(description);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaMetaData)) {
// return false;
// }
// KbaMetaData that = (KbaMetaData)obj;
// return
// this.description.equals(that.description);
// }
//
// @Override
// public String toString() {
// return String.format(
// "description: %s",
// this.description);
// }
//
// public String getDescription() {
// return description;
// }
// }
| import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.KbaMetaData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken; | /*******************************************************************************
* Copyright (C) 2010, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.core.keybinding;
/**
* Reads a JSON file containing the mechanic diagnostics, and returns that in
* the internal format.
*
* <p>The changes will be taken from a file with a format like below:
*
* <pre>
*
{
"metadata" : {
"description" : "",
},
"changeSets" : [
{
"scheme" : "org.eclipse.ui.emacsAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{"keys" : "Shift+Alt+Q T", "cmd" : "a.b.c.d.e"}
]
},
{
"scheme" : "org.eclipse.ui.defaultAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{'keys' : 'Shift+Alt+Q I', 'cmd' : 'org.eclipse.ui.views.showView', 'params' : {'org.eclipse.ui.views.showView.viewId' : 'org.eclipse.jdt.debug.ui.DisplayView' }},
]
},
]
}
* </pre>
*
* This file starts out with metadata (for mechanic's own use), then it has a
* "changeSets" section, that being a list of what we internally call
* {@link KbaChangeSet}, each specific to a single scheme/platform/context/action,
* and containing a list of binding changes.
*
* @author zorzella@google.com
*/
class KeyBindingsParser {
static final String METADATA_JSON_KEY = "metadata";
static final String BINDINGS_JSON_KEY = "bindings";
static final String CONTEXT_JSON_KEY = "context";
static final String PLATFORM_JSON_KEY = "platform";
static final String SCHEME_JSON_KEY = "scheme";
static final String DESCRIPTION_JSON_KEY = "description";
static final String CHANGE_SETS_JSON_KEY = "changeSets";
static final String ACTION_JSON_KEY = "action";
static final String COMMAND_JSON_KEY = "cmd";
static final String COMMAND_PARAMETERS_JSON_KEY = "params";
static final String KEYS_JSON_KEY = "keys";
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting() | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
// private final ImmutableList<KbaBinding> list;
//
// public KbaBindingList(KbaBinding... list) {
// this(Arrays.asList(list));
// }
//
// public KbaBindingList(Iterable<KbaBinding> list) {
// this.list = ImmutableList.copyOf(list);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(list);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaBindingList)) {
// return false;
// }
// KbaBindingList that = (KbaBindingList) obj;
// return this.list.equals(that.list);
// }
//
// @Override
// public String toString() {
// return this.list.toString();
// }
//
// public ImmutableList<KbaBinding> getList() {
// return list;
// }
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
// public static final class KbaMetaData {
//
// private final String description;
//
// public KbaMetaData(String description) {
// this.description = Preconditions.checkNotNull(description);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(description);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaMetaData)) {
// return false;
// }
// KbaMetaData that = (KbaMetaData)obj;
// return
// this.description.equals(that.description);
// }
//
// @Override
// public String toString() {
// return String.format(
// "description: %s",
// this.description);
// }
//
// public String getDescription() {
// return description;
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsParser.java
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.KbaMetaData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
/*******************************************************************************
* Copyright (C) 2010, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.core.keybinding;
/**
* Reads a JSON file containing the mechanic diagnostics, and returns that in
* the internal format.
*
* <p>The changes will be taken from a file with a format like below:
*
* <pre>
*
{
"metadata" : {
"description" : "",
},
"changeSets" : [
{
"scheme" : "org.eclipse.ui.emacsAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{"keys" : "Shift+Alt+Q T", "cmd" : "a.b.c.d.e"}
]
},
{
"scheme" : "org.eclipse.ui.defaultAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{'keys' : 'Shift+Alt+Q I', 'cmd' : 'org.eclipse.ui.views.showView', 'params' : {'org.eclipse.ui.views.showView.viewId' : 'org.eclipse.jdt.debug.ui.DisplayView' }},
]
},
]
}
* </pre>
*
* This file starts out with metadata (for mechanic's own use), then it has a
* "changeSets" section, that being a list of what we internally call
* {@link KbaChangeSet}, each specific to a single scheme/platform/context/action,
* and containing a list of binding changes.
*
* @author zorzella@google.com
*/
class KeyBindingsParser {
static final String METADATA_JSON_KEY = "metadata";
static final String BINDINGS_JSON_KEY = "bindings";
static final String CONTEXT_JSON_KEY = "context";
static final String PLATFORM_JSON_KEY = "platform";
static final String SCHEME_JSON_KEY = "scheme";
static final String DESCRIPTION_JSON_KEY = "description";
static final String CHANGE_SETS_JSON_KEY = "changeSets";
static final String ACTION_JSON_KEY = "action";
static final String COMMAND_JSON_KEY = "cmd";
static final String COMMAND_PARAMETERS_JSON_KEY = "params";
static final String KEYS_JSON_KEY = "keys";
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting() | .registerTypeAdapter(KbaMetaData.class, new KbaMetaDataAdapter()) |
alfsch/workspacemechanic | parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsParser.java | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
// private final ImmutableList<KbaBinding> list;
//
// public KbaBindingList(KbaBinding... list) {
// this(Arrays.asList(list));
// }
//
// public KbaBindingList(Iterable<KbaBinding> list) {
// this.list = ImmutableList.copyOf(list);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(list);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaBindingList)) {
// return false;
// }
// KbaBindingList that = (KbaBindingList) obj;
// return this.list.equals(that.list);
// }
//
// @Override
// public String toString() {
// return this.list.toString();
// }
//
// public ImmutableList<KbaBinding> getList() {
// return list;
// }
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
// public static final class KbaMetaData {
//
// private final String description;
//
// public KbaMetaData(String description) {
// this.description = Preconditions.checkNotNull(description);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(description);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaMetaData)) {
// return false;
// }
// KbaMetaData that = (KbaMetaData)obj;
// return
// this.description.equals(that.description);
// }
//
// @Override
// public String toString() {
// return String.format(
// "description: %s",
// this.description);
// }
//
// public String getDescription() {
// return description;
// }
// }
| import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.KbaMetaData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken; | /*******************************************************************************
* Copyright (C) 2010, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.core.keybinding;
/**
* Reads a JSON file containing the mechanic diagnostics, and returns that in
* the internal format.
*
* <p>The changes will be taken from a file with a format like below:
*
* <pre>
*
{
"metadata" : {
"description" : "",
},
"changeSets" : [
{
"scheme" : "org.eclipse.ui.emacsAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{"keys" : "Shift+Alt+Q T", "cmd" : "a.b.c.d.e"}
]
},
{
"scheme" : "org.eclipse.ui.defaultAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{'keys' : 'Shift+Alt+Q I', 'cmd' : 'org.eclipse.ui.views.showView', 'params' : {'org.eclipse.ui.views.showView.viewId' : 'org.eclipse.jdt.debug.ui.DisplayView' }},
]
},
]
}
* </pre>
*
* This file starts out with metadata (for mechanic's own use), then it has a
* "changeSets" section, that being a list of what we internally call
* {@link KbaChangeSet}, each specific to a single scheme/platform/context/action,
* and containing a list of binding changes.
*
* @author zorzella@google.com
*/
class KeyBindingsParser {
static final String METADATA_JSON_KEY = "metadata";
static final String BINDINGS_JSON_KEY = "bindings";
static final String CONTEXT_JSON_KEY = "context";
static final String PLATFORM_JSON_KEY = "platform";
static final String SCHEME_JSON_KEY = "scheme";
static final String DESCRIPTION_JSON_KEY = "description";
static final String CHANGE_SETS_JSON_KEY = "changeSets";
static final String ACTION_JSON_KEY = "action";
static final String COMMAND_JSON_KEY = "cmd";
static final String COMMAND_PARAMETERS_JSON_KEY = "params";
static final String KEYS_JSON_KEY = "keys";
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(KbaMetaData.class, new KbaMetaDataAdapter())
.registerTypeAdapter(KeyBindingsModel.class, new KeyBindingsTaskAdapter())
.registerTypeAdapter(KbaChangeSet.class, new KbaChangeSetAdapter()) | // Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
// private final ImmutableList<KbaBinding> list;
//
// public KbaBindingList(KbaBinding... list) {
// this(Arrays.asList(list));
// }
//
// public KbaBindingList(Iterable<KbaBinding> list) {
// this.list = ImmutableList.copyOf(list);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(list);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaBindingList)) {
// return false;
// }
// KbaBindingList that = (KbaBindingList) obj;
// return this.list.equals(that.list);
// }
//
// @Override
// public String toString() {
// return this.list.toString();
// }
//
// public ImmutableList<KbaBinding> getList() {
// return list;
// }
// }
//
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
// public static final class KbaMetaData {
//
// private final String description;
//
// public KbaMetaData(String description) {
// this.description = Preconditions.checkNotNull(description);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(description);
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof KbaMetaData)) {
// return false;
// }
// KbaMetaData that = (KbaMetaData)obj;
// return
// this.description.equals(that.description);
// }
//
// @Override
// public String toString() {
// return String.format(
// "description: %s",
// this.description);
// }
//
// public String getDescription() {
// return description;
// }
// }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsParser.java
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.KbaMetaData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
/*******************************************************************************
* Copyright (C) 2010, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package com.google.eclipse.mechanic.core.keybinding;
/**
* Reads a JSON file containing the mechanic diagnostics, and returns that in
* the internal format.
*
* <p>The changes will be taken from a file with a format like below:
*
* <pre>
*
{
"metadata" : {
"description" : "",
},
"changeSets" : [
{
"scheme" : "org.eclipse.ui.emacsAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{"keys" : "Shift+Alt+Q T", "cmd" : "a.b.c.d.e"}
]
},
{
"scheme" : "org.eclipse.ui.defaultAcceleratorConfiguration",
"platform" : "",
"context" : "org.eclipse.ui.contexts.window",
"action" : "add",
"bindings" : [
{'keys' : 'Shift+Alt+Q I', 'cmd' : 'org.eclipse.ui.views.showView', 'params' : {'org.eclipse.ui.views.showView.viewId' : 'org.eclipse.jdt.debug.ui.DisplayView' }},
]
},
]
}
* </pre>
*
* This file starts out with metadata (for mechanic's own use), then it has a
* "changeSets" section, that being a list of what we internally call
* {@link KbaChangeSet}, each specific to a single scheme/platform/context/action,
* and containing a list of binding changes.
*
* @author zorzella@google.com
*/
class KeyBindingsParser {
static final String METADATA_JSON_KEY = "metadata";
static final String BINDINGS_JSON_KEY = "bindings";
static final String CONTEXT_JSON_KEY = "context";
static final String PLATFORM_JSON_KEY = "platform";
static final String SCHEME_JSON_KEY = "scheme";
static final String DESCRIPTION_JSON_KEY = "description";
static final String CHANGE_SETS_JSON_KEY = "changeSets";
static final String ACTION_JSON_KEY = "action";
static final String COMMAND_JSON_KEY = "cmd";
static final String COMMAND_PARAMETERS_JSON_KEY = "params";
static final String KEYS_JSON_KEY = "keys";
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(KbaMetaData.class, new KbaMetaDataAdapter())
.registerTypeAdapter(KeyBindingsModel.class, new KeyBindingsTaskAdapter())
.registerTypeAdapter(KbaChangeSet.class, new KbaChangeSetAdapter()) | .registerTypeAdapter(KbaChangeSet.KbaBindingList.class, new KbaBindingListAdapter()) |
PaulNoth/saral | src/main/java/com/pidanic/saral/scope/LocalVariable.java | // Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.util.Type; | package com.pidanic.saral.scope;
public class LocalVariable {
public static final String SYSTEM_IN = "SYSTEM_IN";
private final String name; | // Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
import com.pidanic.saral.util.Type;
package com.pidanic.saral.scope;
public class LocalVariable {
public static final String SYSTEM_IN = "SYSTEM_IN";
private final String name; | private final Type type; |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/Init.java | // Path: src/main/java/com/pidanic/saral/generator/InitGenerator.java
// public class InitGenerator {
//
// private ClassWriter classWriter;
//
// public InitGenerator(ClassWriter classWriter) {
// this.classWriter = classWriter;
// }
//
// public ClassWriter generate(Init statements) {
// Scope scope = statements.getScope();
// MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
//
//
// List<Statement> instructionQueue = statements.getStatements();
//
// CallableStatementGenerator callableStatementGenerator = new CallableStatementGenerator(classWriter, scope);
// List<Function> functions = instructionQueue.stream()
// .filter(stmt -> stmt instanceof CallableStatement)
// .map(statement -> (Function) statement)
// .collect(Collectors.toList());
// functions.forEach(procedure -> procedure.accept(callableStatementGenerator));
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mv, scope);
// StatementGenerator blockStatementGenerator = new BlockStatementGenerator(mv, scope);
// List<Statement> notCallableStatements = instructionQueue.stream()
// .filter(stmt -> !(stmt instanceof CallableStatement))
// .collect(Collectors.toList());
// for(Statement ins : notCallableStatements) {
// if(ins instanceof SimpleStatement) {
// ins.accept(simpleStatementGenerator);
// } else if (ins instanceof BlockStatement) {
// ins.accept(blockStatementGenerator);
// }
// }
//
// closeSystemInIfCreated(scope, mv);
// mv.visitInsn(Opcodes.RETURN);
// mv.visitMaxs(-1, -1);
// mv.visitEnd();
//
// classWriter.visitEnd();
// return classWriter;
// }
//
// private void closeSystemInIfCreated(Scope scope, MethodVisitor mv) {
// if(scope.existsLocalVariable(LocalVariable.SYSTEM_IN)) {
// int systemInIndex = scope.getLocalVariableIndex(LocalVariable.SYSTEM_IN);
// mv.visitVarInsn(Opcodes.ALOAD, systemInIndex);
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/Scanner", "close", "()V", false);
// }
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.generator.InitGenerator;
import com.pidanic.saral.scope.Scope;
import java.util.List; | package com.pidanic.saral.domain;
public class Init {
private List<Statement> instructions; | // Path: src/main/java/com/pidanic/saral/generator/InitGenerator.java
// public class InitGenerator {
//
// private ClassWriter classWriter;
//
// public InitGenerator(ClassWriter classWriter) {
// this.classWriter = classWriter;
// }
//
// public ClassWriter generate(Init statements) {
// Scope scope = statements.getScope();
// MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
//
//
// List<Statement> instructionQueue = statements.getStatements();
//
// CallableStatementGenerator callableStatementGenerator = new CallableStatementGenerator(classWriter, scope);
// List<Function> functions = instructionQueue.stream()
// .filter(stmt -> stmt instanceof CallableStatement)
// .map(statement -> (Function) statement)
// .collect(Collectors.toList());
// functions.forEach(procedure -> procedure.accept(callableStatementGenerator));
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mv, scope);
// StatementGenerator blockStatementGenerator = new BlockStatementGenerator(mv, scope);
// List<Statement> notCallableStatements = instructionQueue.stream()
// .filter(stmt -> !(stmt instanceof CallableStatement))
// .collect(Collectors.toList());
// for(Statement ins : notCallableStatements) {
// if(ins instanceof SimpleStatement) {
// ins.accept(simpleStatementGenerator);
// } else if (ins instanceof BlockStatement) {
// ins.accept(blockStatementGenerator);
// }
// }
//
// closeSystemInIfCreated(scope, mv);
// mv.visitInsn(Opcodes.RETURN);
// mv.visitMaxs(-1, -1);
// mv.visitEnd();
//
// classWriter.visitEnd();
// return classWriter;
// }
//
// private void closeSystemInIfCreated(Scope scope, MethodVisitor mv) {
// if(scope.existsLocalVariable(LocalVariable.SYSTEM_IN)) {
// int systemInIndex = scope.getLocalVariableIndex(LocalVariable.SYSTEM_IN);
// mv.visitVarInsn(Opcodes.ALOAD, systemInIndex);
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/Scanner", "close", "()V", false);
// }
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/domain/Init.java
import com.pidanic.saral.generator.InitGenerator;
import com.pidanic.saral.scope.Scope;
import java.util.List;
package com.pidanic.saral.domain;
public class Init {
private List<Statement> instructions; | private Scope scope; |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/Init.java | // Path: src/main/java/com/pidanic/saral/generator/InitGenerator.java
// public class InitGenerator {
//
// private ClassWriter classWriter;
//
// public InitGenerator(ClassWriter classWriter) {
// this.classWriter = classWriter;
// }
//
// public ClassWriter generate(Init statements) {
// Scope scope = statements.getScope();
// MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
//
//
// List<Statement> instructionQueue = statements.getStatements();
//
// CallableStatementGenerator callableStatementGenerator = new CallableStatementGenerator(classWriter, scope);
// List<Function> functions = instructionQueue.stream()
// .filter(stmt -> stmt instanceof CallableStatement)
// .map(statement -> (Function) statement)
// .collect(Collectors.toList());
// functions.forEach(procedure -> procedure.accept(callableStatementGenerator));
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mv, scope);
// StatementGenerator blockStatementGenerator = new BlockStatementGenerator(mv, scope);
// List<Statement> notCallableStatements = instructionQueue.stream()
// .filter(stmt -> !(stmt instanceof CallableStatement))
// .collect(Collectors.toList());
// for(Statement ins : notCallableStatements) {
// if(ins instanceof SimpleStatement) {
// ins.accept(simpleStatementGenerator);
// } else if (ins instanceof BlockStatement) {
// ins.accept(blockStatementGenerator);
// }
// }
//
// closeSystemInIfCreated(scope, mv);
// mv.visitInsn(Opcodes.RETURN);
// mv.visitMaxs(-1, -1);
// mv.visitEnd();
//
// classWriter.visitEnd();
// return classWriter;
// }
//
// private void closeSystemInIfCreated(Scope scope, MethodVisitor mv) {
// if(scope.existsLocalVariable(LocalVariable.SYSTEM_IN)) {
// int systemInIndex = scope.getLocalVariableIndex(LocalVariable.SYSTEM_IN);
// mv.visitVarInsn(Opcodes.ALOAD, systemInIndex);
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/Scanner", "close", "()V", false);
// }
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.generator.InitGenerator;
import com.pidanic.saral.scope.Scope;
import java.util.List; | package com.pidanic.saral.domain;
public class Init {
private List<Statement> instructions;
private Scope scope;
public Init(Scope scope, List<Statement> instructions) {
this.instructions = instructions;
this.scope = scope;
}
public List<Statement> getStatements() {
return instructions;
}
| // Path: src/main/java/com/pidanic/saral/generator/InitGenerator.java
// public class InitGenerator {
//
// private ClassWriter classWriter;
//
// public InitGenerator(ClassWriter classWriter) {
// this.classWriter = classWriter;
// }
//
// public ClassWriter generate(Init statements) {
// Scope scope = statements.getScope();
// MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
//
//
// List<Statement> instructionQueue = statements.getStatements();
//
// CallableStatementGenerator callableStatementGenerator = new CallableStatementGenerator(classWriter, scope);
// List<Function> functions = instructionQueue.stream()
// .filter(stmt -> stmt instanceof CallableStatement)
// .map(statement -> (Function) statement)
// .collect(Collectors.toList());
// functions.forEach(procedure -> procedure.accept(callableStatementGenerator));
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mv, scope);
// StatementGenerator blockStatementGenerator = new BlockStatementGenerator(mv, scope);
// List<Statement> notCallableStatements = instructionQueue.stream()
// .filter(stmt -> !(stmt instanceof CallableStatement))
// .collect(Collectors.toList());
// for(Statement ins : notCallableStatements) {
// if(ins instanceof SimpleStatement) {
// ins.accept(simpleStatementGenerator);
// } else if (ins instanceof BlockStatement) {
// ins.accept(blockStatementGenerator);
// }
// }
//
// closeSystemInIfCreated(scope, mv);
// mv.visitInsn(Opcodes.RETURN);
// mv.visitMaxs(-1, -1);
// mv.visitEnd();
//
// classWriter.visitEnd();
// return classWriter;
// }
//
// private void closeSystemInIfCreated(Scope scope, MethodVisitor mv) {
// if(scope.existsLocalVariable(LocalVariable.SYSTEM_IN)) {
// int systemInIndex = scope.getLocalVariableIndex(LocalVariable.SYSTEM_IN);
// mv.visitVarInsn(Opcodes.ALOAD, systemInIndex);
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/Scanner", "close", "()V", false);
// }
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/domain/Init.java
import com.pidanic.saral.generator.InitGenerator;
import com.pidanic.saral.scope.Scope;
import java.util.List;
package com.pidanic.saral.domain;
public class Init {
private List<Statement> instructions;
private Scope scope;
public Init(Scope scope, List<Statement> instructions) {
this.instructions = instructions;
this.scope = scope;
}
public List<Statement> getStatements() {
return instructions;
}
| public void accept(InitGenerator generator) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/Compiler.java | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ByteCodeGenerator.java
// public class ByteCodeGenerator {
// private static final int CLASS_VERSION = 54;
//
// public byte[] generateByteCode(Init compilationUnit) {
// String name = compilationUnit.getScope().getClassName();
// ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES + ClassWriter.COMPUTE_MAXS);
//
// cw.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
//
// InitGenerator initGenerator = new InitGenerator(cw);
// return initGenerator.generate(compilationUnit).toByteArray();
// }
// }
| import com.pidanic.saral.domain.Init;
import com.pidanic.saral.generator.ByteCodeGenerator;
import java.io.*;
import java.nio.file.Files; | package com.pidanic.saral;
public class Compiler {
public static void main(String[] args) {
new Compiler().compile(args);
}
public void compile(String[] args) {
File file = new File(args[0]);
String fileName = file.getName();
String className = fileName.substring(0, fileName.lastIndexOf('.'));
try {
File preprocessedTempFile = new Preprocessor().preprocess(file);
| // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ByteCodeGenerator.java
// public class ByteCodeGenerator {
// private static final int CLASS_VERSION = 54;
//
// public byte[] generateByteCode(Init compilationUnit) {
// String name = compilationUnit.getScope().getClassName();
// ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES + ClassWriter.COMPUTE_MAXS);
//
// cw.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
//
// InitGenerator initGenerator = new InitGenerator(cw);
// return initGenerator.generate(compilationUnit).toByteArray();
// }
// }
// Path: src/main/java/com/pidanic/saral/Compiler.java
import com.pidanic.saral.domain.Init;
import com.pidanic.saral.generator.ByteCodeGenerator;
import java.io.*;
import java.nio.file.Files;
package com.pidanic.saral;
public class Compiler {
public static void main(String[] args) {
new Compiler().compile(args);
}
public void compile(String[] args) {
File file = new File(args[0]);
String fileName = file.getName();
String className = fileName.substring(0, fileName.lastIndexOf('.'));
try {
File preprocessedTempFile = new Preprocessor().preprocess(file);
| Init compilationUnit = new SaralCompilationUnitParser().getCompilationUnit(preprocessedTempFile, className); |
PaulNoth/saral | src/main/java/com/pidanic/saral/Compiler.java | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ByteCodeGenerator.java
// public class ByteCodeGenerator {
// private static final int CLASS_VERSION = 54;
//
// public byte[] generateByteCode(Init compilationUnit) {
// String name = compilationUnit.getScope().getClassName();
// ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES + ClassWriter.COMPUTE_MAXS);
//
// cw.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
//
// InitGenerator initGenerator = new InitGenerator(cw);
// return initGenerator.generate(compilationUnit).toByteArray();
// }
// }
| import com.pidanic.saral.domain.Init;
import com.pidanic.saral.generator.ByteCodeGenerator;
import java.io.*;
import java.nio.file.Files; | package com.pidanic.saral;
public class Compiler {
public static void main(String[] args) {
new Compiler().compile(args);
}
public void compile(String[] args) {
File file = new File(args[0]);
String fileName = file.getName();
String className = fileName.substring(0, fileName.lastIndexOf('.'));
try {
File preprocessedTempFile = new Preprocessor().preprocess(file);
Init compilationUnit = new SaralCompilationUnitParser().getCompilationUnit(preprocessedTempFile, className);
saveBytecodeToClassFile(compilationUnit);
Files.delete(preprocessedTempFile.toPath());
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
private static void saveBytecodeToClassFile(Init compilationUnit) throws IOException { | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ByteCodeGenerator.java
// public class ByteCodeGenerator {
// private static final int CLASS_VERSION = 54;
//
// public byte[] generateByteCode(Init compilationUnit) {
// String name = compilationUnit.getScope().getClassName();
// ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES + ClassWriter.COMPUTE_MAXS);
//
// cw.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
//
// InitGenerator initGenerator = new InitGenerator(cw);
// return initGenerator.generate(compilationUnit).toByteArray();
// }
// }
// Path: src/main/java/com/pidanic/saral/Compiler.java
import com.pidanic.saral.domain.Init;
import com.pidanic.saral.generator.ByteCodeGenerator;
import java.io.*;
import java.nio.file.Files;
package com.pidanic.saral;
public class Compiler {
public static void main(String[] args) {
new Compiler().compile(args);
}
public void compile(String[] args) {
File file = new File(args[0]);
String fileName = file.getName();
String className = fileName.substring(0, fileName.lastIndexOf('.'));
try {
File preprocessedTempFile = new Preprocessor().preprocess(file);
Init compilationUnit = new SaralCompilationUnitParser().getCompilationUnit(preprocessedTempFile, className);
saveBytecodeToClassFile(compilationUnit);
Files.delete(preprocessedTempFile.toPath());
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
private static void saveBytecodeToClassFile(Init compilationUnit) throws IOException { | byte[] byteCode = new ByteCodeGenerator().generateByteCode(compilationUnit); |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/block/Procedure.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.BuiltInType;
import java.util.List; | package com.pidanic.saral.domain.block;
public class Procedure extends Function {
public Procedure(Scope scope, String name, List<Argument> arguments, List<Statement> statements) { | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
// Path: src/main/java/com/pidanic/saral/domain/block/Procedure.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.BuiltInType;
import java.util.List;
package com.pidanic.saral.domain.block;
public class Procedure extends Function {
public Procedure(Scope scope, String name, List<Argument> arguments, List<Statement> statements) { | super(scope, name, arguments, statements, BuiltInType.VOID); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/ProcedureVisitor.java | // Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/FunctionHelper.java
// public final class FunctionHelper {
//
// public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
// List<Argument> arguments = new ArrayList<>();
// for(int i = 0; i < arglistContext.ID().size(); i++) {
// String argName = arglistContext.ID(i).getText();
// SaralParser.TypeContext typeContext = arglistContext.type(i);
// Type argType;
// if(typeContext.typeBasic() != null) {
// String argTypeName = typeContext.typeBasic().getText();
// argType = TypeResolver.getFromTypeName(argTypeName);
// } else {
// argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
// }
// LocalVariable var = new LocalVariable(argName, argType, true);
// if(scope.existsLocalVariable(var.name())) {
// throw new VariableNameAlreadyExists(scope, var.name());
// }
// scope.addLocalVariable(var);
// arguments.add(new Argument(argName, argType));
// }
// return arguments;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.*;
import com.pidanic.saral.domain.block.*;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.FunctionHelper;
import com.pidanic.saral.util.StatementsHelper;
import java.util.Collections;
import java.util.List; | package com.pidanic.saral.visitor;
public class ProcedureVisitor extends SaralBaseVisitor<Procedure> {
private Scope scope;
public ProcedureVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public Procedure visitProc_definition(SaralParser.Proc_definitionContext ctx) {
String procedureName = ctx.ID().getText();
| // Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/FunctionHelper.java
// public final class FunctionHelper {
//
// public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
// List<Argument> arguments = new ArrayList<>();
// for(int i = 0; i < arglistContext.ID().size(); i++) {
// String argName = arglistContext.ID(i).getText();
// SaralParser.TypeContext typeContext = arglistContext.type(i);
// Type argType;
// if(typeContext.typeBasic() != null) {
// String argTypeName = typeContext.typeBasic().getText();
// argType = TypeResolver.getFromTypeName(argTypeName);
// } else {
// argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
// }
// LocalVariable var = new LocalVariable(argName, argType, true);
// if(scope.existsLocalVariable(var.name())) {
// throw new VariableNameAlreadyExists(scope, var.name());
// }
// scope.addLocalVariable(var);
// arguments.add(new Argument(argName, argType));
// }
// return arguments;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/ProcedureVisitor.java
import com.pidanic.saral.domain.*;
import com.pidanic.saral.domain.block.*;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.FunctionHelper;
import com.pidanic.saral.util.StatementsHelper;
import java.util.Collections;
import java.util.List;
package com.pidanic.saral.visitor;
public class ProcedureVisitor extends SaralBaseVisitor<Procedure> {
private Scope scope;
public ProcedureVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public Procedure visitProc_definition(SaralParser.Proc_definitionContext ctx) {
String procedureName = ctx.ID().getText();
| List<Argument> arguments = FunctionHelper.parseFunctionArguments(ctx.arglist(), scope); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/ProcedureVisitor.java | // Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/FunctionHelper.java
// public final class FunctionHelper {
//
// public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
// List<Argument> arguments = new ArrayList<>();
// for(int i = 0; i < arglistContext.ID().size(); i++) {
// String argName = arglistContext.ID(i).getText();
// SaralParser.TypeContext typeContext = arglistContext.type(i);
// Type argType;
// if(typeContext.typeBasic() != null) {
// String argTypeName = typeContext.typeBasic().getText();
// argType = TypeResolver.getFromTypeName(argTypeName);
// } else {
// argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
// }
// LocalVariable var = new LocalVariable(argName, argType, true);
// if(scope.existsLocalVariable(var.name())) {
// throw new VariableNameAlreadyExists(scope, var.name());
// }
// scope.addLocalVariable(var);
// arguments.add(new Argument(argName, argType));
// }
// return arguments;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.*;
import com.pidanic.saral.domain.block.*;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.FunctionHelper;
import com.pidanic.saral.util.StatementsHelper;
import java.util.Collections;
import java.util.List; | package com.pidanic.saral.visitor;
public class ProcedureVisitor extends SaralBaseVisitor<Procedure> {
private Scope scope;
public ProcedureVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public Procedure visitProc_definition(SaralParser.Proc_definitionContext ctx) {
String procedureName = ctx.ID().getText();
List<Argument> arguments = FunctionHelper.parseFunctionArguments(ctx.arglist(), scope);
Procedure me = new Procedure(scope, procedureName, arguments, Collections.emptyList());
this.addMyselfToScope(me);
| // Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/FunctionHelper.java
// public final class FunctionHelper {
//
// public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
// List<Argument> arguments = new ArrayList<>();
// for(int i = 0; i < arglistContext.ID().size(); i++) {
// String argName = arglistContext.ID(i).getText();
// SaralParser.TypeContext typeContext = arglistContext.type(i);
// Type argType;
// if(typeContext.typeBasic() != null) {
// String argTypeName = typeContext.typeBasic().getText();
// argType = TypeResolver.getFromTypeName(argTypeName);
// } else {
// argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
// }
// LocalVariable var = new LocalVariable(argName, argType, true);
// if(scope.existsLocalVariable(var.name())) {
// throw new VariableNameAlreadyExists(scope, var.name());
// }
// scope.addLocalVariable(var);
// arguments.add(new Argument(argName, argType));
// }
// return arguments;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/ProcedureVisitor.java
import com.pidanic.saral.domain.*;
import com.pidanic.saral.domain.block.*;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.FunctionHelper;
import com.pidanic.saral.util.StatementsHelper;
import java.util.Collections;
import java.util.List;
package com.pidanic.saral.visitor;
public class ProcedureVisitor extends SaralBaseVisitor<Procedure> {
private Scope scope;
public ProcedureVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public Procedure visitProc_definition(SaralParser.Proc_definitionContext ctx) {
String procedureName = ctx.ID().getText();
List<Argument> arguments = FunctionHelper.parseFunctionArguments(ctx.arglist(), scope);
Procedure me = new Procedure(scope, procedureName, arguments, Collections.emptyList());
this.addMyselfToScope(me);
| List<Statement> allStatements = StatementsHelper.parseStatements(ctx.block().statements(), scope); |
PaulNoth/saral | src/main/java/com/pidanic/saral/exception/FunctionCallNotFound.java | // Path: src/main/java/com/pidanic/saral/domain/ProcedureCall.java
// public class ProcedureCall implements SimpleStatement {
//
// private Function function;
// private List<CalledArgument> arguments;
//
// public ProcedureCall(Function function, List<CalledArgument> calledArguments) {
// this.function = function;
// this.arguments = new ArrayList<>(calledArguments);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((SimpleStatementGenerator) generator).generate(this);
// }
//
// public List<CalledArgument> getCalledArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public Function getFunction() {
// return function;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/FunctionCall.java
// public class FunctionCall extends Expression {
//
// private Function function;
// private List<CalledArgument> arguments;
//
// public List<CalledArgument> getCalledArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public Function getFunction() {
// return function;
// }
//
// public FunctionCall(Function function, List<CalledArgument> calledArguments) {
// super(function.getReturnType());
// this.function = function;
// this.arguments = new ArrayList<>(calledArguments);
// }
//
//
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
// }
| import com.pidanic.saral.domain.ProcedureCall;
import com.pidanic.saral.domain.expression.FunctionCall; | package com.pidanic.saral.exception;
public class FunctionCallNotFound extends RuntimeException {
public FunctionCallNotFound(FunctionCall functionCall) {
super("No procedure found for name " + functionCall.getFunction().getName());
}
| // Path: src/main/java/com/pidanic/saral/domain/ProcedureCall.java
// public class ProcedureCall implements SimpleStatement {
//
// private Function function;
// private List<CalledArgument> arguments;
//
// public ProcedureCall(Function function, List<CalledArgument> calledArguments) {
// this.function = function;
// this.arguments = new ArrayList<>(calledArguments);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((SimpleStatementGenerator) generator).generate(this);
// }
//
// public List<CalledArgument> getCalledArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public Function getFunction() {
// return function;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/FunctionCall.java
// public class FunctionCall extends Expression {
//
// private Function function;
// private List<CalledArgument> arguments;
//
// public List<CalledArgument> getCalledArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public Function getFunction() {
// return function;
// }
//
// public FunctionCall(Function function, List<CalledArgument> calledArguments) {
// super(function.getReturnType());
// this.function = function;
// this.arguments = new ArrayList<>(calledArguments);
// }
//
//
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
// }
// Path: src/main/java/com/pidanic/saral/exception/FunctionCallNotFound.java
import com.pidanic.saral.domain.ProcedureCall;
import com.pidanic.saral.domain.expression.FunctionCall;
package com.pidanic.saral.exception;
public class FunctionCallNotFound extends RuntimeException {
public FunctionCallNotFound(FunctionCall functionCall) {
super("No procedure found for name " + functionCall.getFunction().getName());
}
| public FunctionCallNotFound(ProcedureCall functionCall) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/util/FunctionHelper.java | // Path: src/main/java/com/pidanic/saral/exception/VariableNameAlreadyExists.java
// public class VariableNameAlreadyExists extends RuntimeException {
// public VariableNameAlreadyExists(Scope scope, String varName) {
// super("Local variable " + varName + " already exists in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.exception.VariableNameAlreadyExists;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.ArrayList;
import java.util.List; | package com.pidanic.saral.util;
public final class FunctionHelper {
public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
List<Argument> arguments = new ArrayList<>();
for(int i = 0; i < arglistContext.ID().size(); i++) {
String argName = arglistContext.ID(i).getText();
SaralParser.TypeContext typeContext = arglistContext.type(i);
Type argType;
if(typeContext.typeBasic() != null) {
String argTypeName = typeContext.typeBasic().getText();
argType = TypeResolver.getFromTypeName(argTypeName);
} else {
argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
} | // Path: src/main/java/com/pidanic/saral/exception/VariableNameAlreadyExists.java
// public class VariableNameAlreadyExists extends RuntimeException {
// public VariableNameAlreadyExists(Scope scope, String varName) {
// super("Local variable " + varName + " already exists in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/util/FunctionHelper.java
import com.pidanic.saral.exception.VariableNameAlreadyExists;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.ArrayList;
import java.util.List;
package com.pidanic.saral.util;
public final class FunctionHelper {
public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
List<Argument> arguments = new ArrayList<>();
for(int i = 0; i < arglistContext.ID().size(); i++) {
String argName = arglistContext.ID(i).getText();
SaralParser.TypeContext typeContext = arglistContext.type(i);
Type argType;
if(typeContext.typeBasic() != null) {
String argTypeName = typeContext.typeBasic().getText();
argType = TypeResolver.getFromTypeName(argTypeName);
} else {
argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
} | LocalVariable var = new LocalVariable(argName, argType, true); |
PaulNoth/saral | src/main/java/com/pidanic/saral/util/FunctionHelper.java | // Path: src/main/java/com/pidanic/saral/exception/VariableNameAlreadyExists.java
// public class VariableNameAlreadyExists extends RuntimeException {
// public VariableNameAlreadyExists(Scope scope, String varName) {
// super("Local variable " + varName + " already exists in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.exception.VariableNameAlreadyExists;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.ArrayList;
import java.util.List; | package com.pidanic.saral.util;
public final class FunctionHelper {
public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
List<Argument> arguments = new ArrayList<>();
for(int i = 0; i < arglistContext.ID().size(); i++) {
String argName = arglistContext.ID(i).getText();
SaralParser.TypeContext typeContext = arglistContext.type(i);
Type argType;
if(typeContext.typeBasic() != null) {
String argTypeName = typeContext.typeBasic().getText();
argType = TypeResolver.getFromTypeName(argTypeName);
} else {
argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
}
LocalVariable var = new LocalVariable(argName, argType, true);
if(scope.existsLocalVariable(var.name())) { | // Path: src/main/java/com/pidanic/saral/exception/VariableNameAlreadyExists.java
// public class VariableNameAlreadyExists extends RuntimeException {
// public VariableNameAlreadyExists(Scope scope, String varName) {
// super("Local variable " + varName + " already exists in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/util/FunctionHelper.java
import com.pidanic.saral.exception.VariableNameAlreadyExists;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.ArrayList;
import java.util.List;
package com.pidanic.saral.util;
public final class FunctionHelper {
public static List<Argument> parseFunctionArguments(SaralParser.ArglistContext arglistContext, Scope scope) {
List<Argument> arguments = new ArrayList<>();
for(int i = 0; i < arglistContext.ID().size(); i++) {
String argName = arglistContext.ID(i).getText();
SaralParser.TypeContext typeContext = arglistContext.type(i);
Type argType;
if(typeContext.typeBasic() != null) {
String argTypeName = typeContext.typeBasic().getText();
argType = TypeResolver.getFromTypeName(argTypeName);
} else {
argType = TypeResolver.getArrayTypeFromTypeName(typeContext.typeArray().typeBasic().getText());
}
LocalVariable var = new LocalVariable(argName, argType, true);
if(scope.existsLocalVariable(var.name())) { | throw new VariableNameAlreadyExists(scope, var.name()); |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/expression/BinaryExpression.java | // Path: src/main/java/com/pidanic/saral/domain/expression/cast/CastExpression.java
// public class CastExpression extends UnaryExpression {
// public CastExpression(Type castingType, Expression expression) {
// super(castingType, getSign(castingType, expression.type()), expression);
// }
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
//
// private static CastingSign getSign(Type castingType, Type expressionType) {
// if(castingType == BuiltInType.DOUBLE) {
// return CastingSign.LONG_TO_DOUBLE;
// }
// if(castingType == BuiltInType.INT) {
// return CastingSign.LONG_TO_INT;
// }
// return CastingSign.LONG_TO_DOUBLE;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.expression.cast.CastExpression;
import com.pidanic.saral.util.BuiltInType;
import com.pidanic.saral.util.Type; | package com.pidanic.saral.domain.expression;
public abstract class BinaryExpression extends Expression {
private Expression left;
private Expression right;
private Sign sign;
| // Path: src/main/java/com/pidanic/saral/domain/expression/cast/CastExpression.java
// public class CastExpression extends UnaryExpression {
// public CastExpression(Type castingType, Expression expression) {
// super(castingType, getSign(castingType, expression.type()), expression);
// }
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
//
// private static CastingSign getSign(Type castingType, Type expressionType) {
// if(castingType == BuiltInType.DOUBLE) {
// return CastingSign.LONG_TO_DOUBLE;
// }
// if(castingType == BuiltInType.INT) {
// return CastingSign.LONG_TO_INT;
// }
// return CastingSign.LONG_TO_DOUBLE;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/expression/BinaryExpression.java
import com.pidanic.saral.domain.expression.cast.CastExpression;
import com.pidanic.saral.util.BuiltInType;
import com.pidanic.saral.util.Type;
package com.pidanic.saral.domain.expression;
public abstract class BinaryExpression extends Expression {
private Expression left;
private Expression right;
private Sign sign;
| public BinaryExpression(Type type, Sign sign, Expression left, Expression right) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/expression/BinaryExpression.java | // Path: src/main/java/com/pidanic/saral/domain/expression/cast/CastExpression.java
// public class CastExpression extends UnaryExpression {
// public CastExpression(Type castingType, Expression expression) {
// super(castingType, getSign(castingType, expression.type()), expression);
// }
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
//
// private static CastingSign getSign(Type castingType, Type expressionType) {
// if(castingType == BuiltInType.DOUBLE) {
// return CastingSign.LONG_TO_DOUBLE;
// }
// if(castingType == BuiltInType.INT) {
// return CastingSign.LONG_TO_INT;
// }
// return CastingSign.LONG_TO_DOUBLE;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.expression.cast.CastExpression;
import com.pidanic.saral.util.BuiltInType;
import com.pidanic.saral.util.Type; | package com.pidanic.saral.domain.expression;
public abstract class BinaryExpression extends Expression {
private Expression left;
private Expression right;
private Sign sign;
public BinaryExpression(Type type, Sign sign, Expression left, Expression right) {
super(type);
Type leftType = left.type(); | // Path: src/main/java/com/pidanic/saral/domain/expression/cast/CastExpression.java
// public class CastExpression extends UnaryExpression {
// public CastExpression(Type castingType, Expression expression) {
// super(castingType, getSign(castingType, expression.type()), expression);
// }
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
//
// private static CastingSign getSign(Type castingType, Type expressionType) {
// if(castingType == BuiltInType.DOUBLE) {
// return CastingSign.LONG_TO_DOUBLE;
// }
// if(castingType == BuiltInType.INT) {
// return CastingSign.LONG_TO_INT;
// }
// return CastingSign.LONG_TO_DOUBLE;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/expression/BinaryExpression.java
import com.pidanic.saral.domain.expression.cast.CastExpression;
import com.pidanic.saral.util.BuiltInType;
import com.pidanic.saral.util.Type;
package com.pidanic.saral.domain.expression;
public abstract class BinaryExpression extends Expression {
private Expression left;
private Expression right;
private Sign sign;
public BinaryExpression(Type type, Sign sign, Expression left, Expression right) {
super(type);
Type leftType = left.type(); | if(leftType == BuiltInType.VOID) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/expression/BinaryExpression.java | // Path: src/main/java/com/pidanic/saral/domain/expression/cast/CastExpression.java
// public class CastExpression extends UnaryExpression {
// public CastExpression(Type castingType, Expression expression) {
// super(castingType, getSign(castingType, expression.type()), expression);
// }
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
//
// private static CastingSign getSign(Type castingType, Type expressionType) {
// if(castingType == BuiltInType.DOUBLE) {
// return CastingSign.LONG_TO_DOUBLE;
// }
// if(castingType == BuiltInType.INT) {
// return CastingSign.LONG_TO_INT;
// }
// return CastingSign.LONG_TO_DOUBLE;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.expression.cast.CastExpression;
import com.pidanic.saral.util.BuiltInType;
import com.pidanic.saral.util.Type; | public BinaryExpression(Type type, Sign sign, Expression left, Expression right) {
super(type);
Type leftType = left.type();
if(leftType == BuiltInType.VOID) {
throw new UnsupportedOperationException("Only numerical, string and boolean expressions supported. Actual expression type. Left: "
+ left.type() + ", right: " + right.type());
}
this.sign = sign;
this.left = left;
this.right = right;
convertIfCast(type, left, right);
}
public Expression getLeft() {
return left;
}
public Expression getRight() {
return right;
}
public Sign getSign() {
return sign;
}
private void convertIfCast(Type type, Expression left, Expression right) {
final Type leftType = left.type();
final Type rightType = right.type();
if(type == BuiltInType.DOUBLE) {
if(leftType == BuiltInType.LONG) { | // Path: src/main/java/com/pidanic/saral/domain/expression/cast/CastExpression.java
// public class CastExpression extends UnaryExpression {
// public CastExpression(Type castingType, Expression expression) {
// super(castingType, getSign(castingType, expression.type()), expression);
// }
// @Override
// public void accept(ExpressionGenerator generator) {
// generator.generate(this);
// }
//
// private static CastingSign getSign(Type castingType, Type expressionType) {
// if(castingType == BuiltInType.DOUBLE) {
// return CastingSign.LONG_TO_DOUBLE;
// }
// if(castingType == BuiltInType.INT) {
// return CastingSign.LONG_TO_INT;
// }
// return CastingSign.LONG_TO_DOUBLE;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/expression/BinaryExpression.java
import com.pidanic.saral.domain.expression.cast.CastExpression;
import com.pidanic.saral.util.BuiltInType;
import com.pidanic.saral.util.Type;
public BinaryExpression(Type type, Sign sign, Expression left, Expression right) {
super(type);
Type leftType = left.type();
if(leftType == BuiltInType.VOID) {
throw new UnsupportedOperationException("Only numerical, string and boolean expressions supported. Actual expression type. Left: "
+ left.type() + ", right: " + right.type());
}
this.sign = sign;
this.left = left;
this.right = right;
convertIfCast(type, left, right);
}
public Expression getLeft() {
return left;
}
public Expression getRight() {
return right;
}
public Sign getSign() {
return sign;
}
private void convertIfCast(Type type, Expression left, Expression right) {
final Type leftType = left.type();
final Type rightType = right.type();
if(type == BuiltInType.DOUBLE) {
if(leftType == BuiltInType.LONG) { | this.left = new CastExpression(BuiltInType.DOUBLE, left); |
PaulNoth/saral | src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor; | package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor; | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor;
package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor; | private final Scope scope; |
PaulNoth/saral | src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor; | package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor;
private final Scope scope;
public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
this.scope = scope;
this.methodVisitor = methodVisitor;
}
| // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor;
package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor;
private final Scope scope;
public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
this.scope = scope;
this.methodVisitor = methodVisitor;
}
| public void generate(ReturnStatement retStatement) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor; | package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor;
private final Scope scope;
public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
this.scope = scope;
this.methodVisitor = methodVisitor;
}
public void generate(ReturnStatement retStatement) { | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor;
package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor;
private final Scope scope;
public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
this.scope = scope;
this.methodVisitor = methodVisitor;
}
public void generate(ReturnStatement retStatement) { | Expression returnVariable = retStatement.getExpression(); |
PaulNoth/saral | src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor; | package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor;
private final Scope scope;
public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
this.scope = scope;
this.methodVisitor = methodVisitor;
}
public void generate(ReturnStatement retStatement) {
Expression returnVariable = retStatement.getExpression(); | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import org.objectweb.asm.MethodVisitor;
package com.pidanic.saral.generator;
public class ReturnStatementGenerator extends StatementGenerator {
private final MethodVisitor methodVisitor;
private final Scope scope;
public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
this.scope = scope;
this.methodVisitor = methodVisitor;
}
public void generate(ReturnStatement retStatement) {
Expression returnVariable = retStatement.getExpression(); | Type retType = returnVariable.type(); |
PaulNoth/saral | src/main/java/com/pidanic/saral/util/DescriptorFactory.java | // Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
// public class Function extends CallableStatement {
// private String name;
// private List<Argument> arguments;
// private List<Statement> statements;
// private ReturnStatement retStatement;
// private Type returnType;
//
// public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) {
// super(scope);
// this.name = name;
// this.arguments = new ArrayList<>(arguments);
// this.statements = new ArrayList<>(statements);
// this.returnType = returnType;
// this.retStatement = retStatement;
// }
//
// Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType) {
// this(scope, name, arguments, statements, returnType, null);
// }
//
// public String getName() {
// return name;
// }
//
// public List<Argument> getArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public List<Statement> getStatements() {
// return Collections.unmodifiableList(statements);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((CallableStatementGenerator) generator).generate(this);
// }
//
// public Type getReturnType() {
// return returnType;
// }
//
// public Optional<ReturnStatement> getReturnStatement() {
// return Optional.ofNullable(retStatement);
// }
//
// public void setStatements(List<Statement> newStatements) {
// this.statements = newStatements;
// }
//
// public void setRetStatement(ReturnStatement newStatements) {
// this.retStatement = newStatements;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Procedure.java
// public class Procedure extends Function {
//
// public Procedure(Scope scope, String name, List<Argument> arguments, List<Statement> statements) {
// super(scope, name, arguments, statements, BuiltInType.VOID);
// }
// }
| import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.domain.block.Function;
import com.pidanic.saral.domain.block.Procedure;
import java.util.Collection;
import java.util.stream.Collectors; | package com.pidanic.saral.util;
public class DescriptorFactory {
public static String getMethodDescriptor(Procedure procedure) { | // Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
// public class Function extends CallableStatement {
// private String name;
// private List<Argument> arguments;
// private List<Statement> statements;
// private ReturnStatement retStatement;
// private Type returnType;
//
// public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) {
// super(scope);
// this.name = name;
// this.arguments = new ArrayList<>(arguments);
// this.statements = new ArrayList<>(statements);
// this.returnType = returnType;
// this.retStatement = retStatement;
// }
//
// Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType) {
// this(scope, name, arguments, statements, returnType, null);
// }
//
// public String getName() {
// return name;
// }
//
// public List<Argument> getArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public List<Statement> getStatements() {
// return Collections.unmodifiableList(statements);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((CallableStatementGenerator) generator).generate(this);
// }
//
// public Type getReturnType() {
// return returnType;
// }
//
// public Optional<ReturnStatement> getReturnStatement() {
// return Optional.ofNullable(retStatement);
// }
//
// public void setStatements(List<Statement> newStatements) {
// this.statements = newStatements;
// }
//
// public void setRetStatement(ReturnStatement newStatements) {
// this.retStatement = newStatements;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Procedure.java
// public class Procedure extends Function {
//
// public Procedure(Scope scope, String name, List<Argument> arguments, List<Statement> statements) {
// super(scope, name, arguments, statements, BuiltInType.VOID);
// }
// }
// Path: src/main/java/com/pidanic/saral/util/DescriptorFactory.java
import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.domain.block.Function;
import com.pidanic.saral.domain.block.Procedure;
import java.util.Collection;
import java.util.stream.Collectors;
package com.pidanic.saral.util;
public class DescriptorFactory {
public static String getMethodDescriptor(Procedure procedure) { | Collection<Argument> arguments = procedure.getArguments(); |
PaulNoth/saral | src/main/java/com/pidanic/saral/util/DescriptorFactory.java | // Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
// public class Function extends CallableStatement {
// private String name;
// private List<Argument> arguments;
// private List<Statement> statements;
// private ReturnStatement retStatement;
// private Type returnType;
//
// public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) {
// super(scope);
// this.name = name;
// this.arguments = new ArrayList<>(arguments);
// this.statements = new ArrayList<>(statements);
// this.returnType = returnType;
// this.retStatement = retStatement;
// }
//
// Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType) {
// this(scope, name, arguments, statements, returnType, null);
// }
//
// public String getName() {
// return name;
// }
//
// public List<Argument> getArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public List<Statement> getStatements() {
// return Collections.unmodifiableList(statements);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((CallableStatementGenerator) generator).generate(this);
// }
//
// public Type getReturnType() {
// return returnType;
// }
//
// public Optional<ReturnStatement> getReturnStatement() {
// return Optional.ofNullable(retStatement);
// }
//
// public void setStatements(List<Statement> newStatements) {
// this.statements = newStatements;
// }
//
// public void setRetStatement(ReturnStatement newStatements) {
// this.retStatement = newStatements;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Procedure.java
// public class Procedure extends Function {
//
// public Procedure(Scope scope, String name, List<Argument> arguments, List<Statement> statements) {
// super(scope, name, arguments, statements, BuiltInType.VOID);
// }
// }
| import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.domain.block.Function;
import com.pidanic.saral.domain.block.Procedure;
import java.util.Collection;
import java.util.stream.Collectors; | package com.pidanic.saral.util;
public class DescriptorFactory {
public static String getMethodDescriptor(Procedure procedure) {
Collection<Argument> arguments = procedure.getArguments();
Type returnType = BuiltInType.VOID;
return getMethodDescriptor(arguments, returnType);
}
| // Path: src/main/java/com/pidanic/saral/domain/block/Argument.java
// public class Argument {
// private final Type type;
// private final String name;
//
// public Argument(String name, Type type) {
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
//
// public void accept(SimpleStatementGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// public void accept(ExpressionGenerator expressionGenerator, String localVariableName) {
// expressionGenerator.generate(this, localVariableName);
// }
//
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
// public class Function extends CallableStatement {
// private String name;
// private List<Argument> arguments;
// private List<Statement> statements;
// private ReturnStatement retStatement;
// private Type returnType;
//
// public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) {
// super(scope);
// this.name = name;
// this.arguments = new ArrayList<>(arguments);
// this.statements = new ArrayList<>(statements);
// this.returnType = returnType;
// this.retStatement = retStatement;
// }
//
// Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType) {
// this(scope, name, arguments, statements, returnType, null);
// }
//
// public String getName() {
// return name;
// }
//
// public List<Argument> getArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public List<Statement> getStatements() {
// return Collections.unmodifiableList(statements);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((CallableStatementGenerator) generator).generate(this);
// }
//
// public Type getReturnType() {
// return returnType;
// }
//
// public Optional<ReturnStatement> getReturnStatement() {
// return Optional.ofNullable(retStatement);
// }
//
// public void setStatements(List<Statement> newStatements) {
// this.statements = newStatements;
// }
//
// public void setRetStatement(ReturnStatement newStatements) {
// this.retStatement = newStatements;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/Procedure.java
// public class Procedure extends Function {
//
// public Procedure(Scope scope, String name, List<Argument> arguments, List<Statement> statements) {
// super(scope, name, arguments, statements, BuiltInType.VOID);
// }
// }
// Path: src/main/java/com/pidanic/saral/util/DescriptorFactory.java
import com.pidanic.saral.domain.block.Argument;
import com.pidanic.saral.domain.block.Function;
import com.pidanic.saral.domain.block.Procedure;
import java.util.Collection;
import java.util.stream.Collectors;
package com.pidanic.saral.util;
public class DescriptorFactory {
public static String getMethodDescriptor(Procedure procedure) {
Collection<Argument> arguments = procedure.getArguments();
Type returnType = BuiltInType.VOID;
return getMethodDescriptor(arguments, returnType);
}
| public static String getMethodDescriptor(Function function) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/generator/ByteCodeGenerator.java | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
| import com.pidanic.saral.domain.Init;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes; | package com.pidanic.saral.generator;
public class ByteCodeGenerator {
private static final int CLASS_VERSION = 54;
| // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
// Path: src/main/java/com/pidanic/saral/generator/ByteCodeGenerator.java
import com.pidanic.saral.domain.Init;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
package com.pidanic.saral.generator;
public class ByteCodeGenerator {
private static final int CLASS_VERSION = 54;
| public byte[] generateByteCode(Init compilationUnit) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/block/Function.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional; | package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments; | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments; | private List<Statement> statements; |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/block/Function.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional; | package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments;
private List<Statement> statements; | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments;
private List<Statement> statements; | private ReturnStatement retStatement; |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/block/Function.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional; | package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments;
private List<Statement> statements;
private ReturnStatement retStatement; | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments;
private List<Statement> statements;
private ReturnStatement retStatement; | private Type returnType; |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/block/Function.java | // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional; | package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments;
private List<Statement> statements;
private ReturnStatement retStatement;
private Type returnType;
| // Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
// public class ReturnStatement implements Statement {
//
// private Expression expression;
//
// public ReturnStatement(Expression variable) {
// this.expression = variable;
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((ReturnStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/CallableStatementGenerator.java
// public class CallableStatementGenerator extends StatementGenerator {
//
// private final ClassWriter classWriter;
// private final Scope scope;
//
// public CallableStatementGenerator(ClassWriter classWriter, Scope scope) {
// super();
// this.classWriter = classWriter;
// this.scope = scope;
// }
//
// public void generate(Function function) {
// Scope scope = function.getScope();
// String procedureName = function.getName();
//
// String descriptor = DescriptorFactory.getMethodDescriptor(function);
// Collection<Statement> statements = function.getStatements();
// int access = Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC;
// MethodVisitor mw = classWriter.visitMethod(access, procedureName, descriptor, null, null);
// mw.visitCode();
//
// StatementGenerator simpleStatementGenerator = new SimpleStatementGenerator(mw, scope);
// StatementGenerator statementGenerator = new BlockStatementGenerator(mw, scope);
// statements.forEach(statement -> {
// if(statement instanceof SimpleStatement) {
// statement.accept(simpleStatementGenerator);
// } else {
// statement.accept(statementGenerator);
// }
// });
//
// Optional<ReturnStatement> ret = function.getReturnStatement();
// generateReturnStatement(scope, mw, ret);
// }
//
// private void generateReturnStatement(Scope scope, MethodVisitor mw, Optional<ReturnStatement> returnStatement) {
// ReturnStatementGenerator returnStatementGenerator = new ReturnStatementGenerator(scope, mw);
// if(returnStatement.isPresent()) {
// returnStatementGenerator.generate(returnStatement.get());
// } else {
// mw.visitInsn(Opcodes.RETURN);
// }
// mw.visitMaxs(-1, -1);
// mw.visitEnd();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/block/Function.java
import com.pidanic.saral.domain.ReturnStatement;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.generator.CallableStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
package com.pidanic.saral.domain.block;
public class Function extends CallableStatement {
private String name;
private List<Argument> arguments;
private List<Statement> statements;
private ReturnStatement retStatement;
private Type returnType;
| public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/StatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/block/BlockStatement.java
// public interface BlockStatement extends Statement {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.domain.*;
import com.pidanic.saral.domain.block.BlockStatement;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope; | package com.pidanic.saral.visitor;
public class StatementVisitor extends SaralBaseVisitor<Statement> {
private Scope scope;
public StatementVisitor(Scope scope) {
this.scope = scope;
}
@Override
public Statement visitSimple_statement(SaralParser.Simple_statementContext ctx) {
SimpleStatementVisitor simpleStatementVisitor = new SimpleStatementVisitor(scope);
SimpleStatement simpleStatement = ctx.accept(simpleStatementVisitor);
return simpleStatement;
}
@Override
public Statement visitBlock_statement(SaralParser.Block_statementContext ctx) {
BlockStatementVisitor blockStatementVisitor = new BlockStatementVisitor(scope); | // Path: src/main/java/com/pidanic/saral/domain/block/BlockStatement.java
// public interface BlockStatement extends Statement {
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/StatementVisitor.java
import com.pidanic.saral.domain.*;
import com.pidanic.saral.domain.block.BlockStatement;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
package com.pidanic.saral.visitor;
public class StatementVisitor extends SaralBaseVisitor<Statement> {
private Scope scope;
public StatementVisitor(Scope scope) {
this.scope = scope;
}
@Override
public Statement visitSimple_statement(SaralParser.Simple_statementContext ctx) {
SimpleStatementVisitor simpleStatementVisitor = new SimpleStatementVisitor(scope);
SimpleStatement simpleStatement = ctx.accept(simpleStatementVisitor);
return simpleStatement;
}
@Override
public Statement visitBlock_statement(SaralParser.Block_statementContext ctx) {
BlockStatementVisitor blockStatementVisitor = new BlockStatementVisitor(scope); | BlockStatement blockStatement = ctx.accept(blockStatementVisitor); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/InitVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.domain.Init;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.List;
import java.util.stream.Collectors; | package com.pidanic.saral.visitor;
public class InitVisitor extends SaralBaseVisitor<Init> {
private Scope scope;
public InitVisitor(String className) {
this.scope = new Scope(className);
}
@Override
public Init visitInit(SaralParser.InitContext ctx) { | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/InitVisitor.java
import com.pidanic.saral.domain.Init;
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.List;
import java.util.stream.Collectors;
package com.pidanic.saral.visitor;
public class InitVisitor extends SaralBaseVisitor<Init> {
private Scope scope;
public InitVisitor(String className) {
this.scope = new Scope(className);
}
@Override
public Init visitInit(SaralParser.InitContext ctx) { | List<Statement> allStatements = ctx.statements().statement().stream().map(stmtCtx -> { |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/Statements.java | // Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.scope.Scope;
import java.util.List; | package com.pidanic.saral.domain;
public class Statements {
private List<Statement> instructions; | // Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/domain/Statements.java
import com.pidanic.saral.scope.Scope;
import java.util.List;
package com.pidanic.saral.domain;
public class Statements {
private List<Statement> instructions; | private Scope scope; |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/CalledArgumentVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/CalledArgument.java
// public class CalledArgument {
// private final String name;
//
// public CalledArgument(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotFound.java
// public class VariableNotFound extends RuntimeException {
// public VariableNotFound(Scope scope, String varName) {
// super("No local variable found for name " + varName + " found in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotInitialized.java
// public class VariableNotInitialized extends RuntimeException {
// public VariableNotInitialized(Scope scope, String varName) {
// super("Variable " + varName + " is not initialized in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.domain.CalledArgument;
import com.pidanic.saral.exception.VariableNotFound;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.exception.VariableNotInitialized;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.Optional; | package com.pidanic.saral.visitor;
public class CalledArgumentVisitor extends SaralBaseVisitor<CalledArgument> {
private Scope scope;
public CalledArgumentVisitor(Scope scope) {
this.scope = scope;
}
@Override
public CalledArgument visitVarID(SaralParser.VarIDContext ctx) {
String argName = ctx.ID().getText(); | // Path: src/main/java/com/pidanic/saral/domain/CalledArgument.java
// public class CalledArgument {
// private final String name;
//
// public CalledArgument(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotFound.java
// public class VariableNotFound extends RuntimeException {
// public VariableNotFound(Scope scope, String varName) {
// super("No local variable found for name " + varName + " found in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotInitialized.java
// public class VariableNotInitialized extends RuntimeException {
// public VariableNotInitialized(Scope scope, String varName) {
// super("Variable " + varName + " is not initialized in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/CalledArgumentVisitor.java
import com.pidanic.saral.domain.CalledArgument;
import com.pidanic.saral.exception.VariableNotFound;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.exception.VariableNotInitialized;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.Optional;
package com.pidanic.saral.visitor;
public class CalledArgumentVisitor extends SaralBaseVisitor<CalledArgument> {
private Scope scope;
public CalledArgumentVisitor(Scope scope) {
this.scope = scope;
}
@Override
public CalledArgument visitVarID(SaralParser.VarIDContext ctx) {
String argName = ctx.ID().getText(); | Optional<LocalVariable> argVar = scope.getLocalVariable(argName); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/CalledArgumentVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/CalledArgument.java
// public class CalledArgument {
// private final String name;
//
// public CalledArgument(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotFound.java
// public class VariableNotFound extends RuntimeException {
// public VariableNotFound(Scope scope, String varName) {
// super("No local variable found for name " + varName + " found in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotInitialized.java
// public class VariableNotInitialized extends RuntimeException {
// public VariableNotInitialized(Scope scope, String varName) {
// super("Variable " + varName + " is not initialized in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.domain.CalledArgument;
import com.pidanic.saral.exception.VariableNotFound;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.exception.VariableNotInitialized;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.Optional; | package com.pidanic.saral.visitor;
public class CalledArgumentVisitor extends SaralBaseVisitor<CalledArgument> {
private Scope scope;
public CalledArgumentVisitor(Scope scope) {
this.scope = scope;
}
@Override
public CalledArgument visitVarID(SaralParser.VarIDContext ctx) {
String argName = ctx.ID().getText();
Optional<LocalVariable> argVar = scope.getLocalVariable(argName);
if(!argVar.isPresent()) { | // Path: src/main/java/com/pidanic/saral/domain/CalledArgument.java
// public class CalledArgument {
// private final String name;
//
// public CalledArgument(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotFound.java
// public class VariableNotFound extends RuntimeException {
// public VariableNotFound(Scope scope, String varName) {
// super("No local variable found for name " + varName + " found in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotInitialized.java
// public class VariableNotInitialized extends RuntimeException {
// public VariableNotInitialized(Scope scope, String varName) {
// super("Variable " + varName + " is not initialized in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/CalledArgumentVisitor.java
import com.pidanic.saral.domain.CalledArgument;
import com.pidanic.saral.exception.VariableNotFound;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.exception.VariableNotInitialized;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.Optional;
package com.pidanic.saral.visitor;
public class CalledArgumentVisitor extends SaralBaseVisitor<CalledArgument> {
private Scope scope;
public CalledArgumentVisitor(Scope scope) {
this.scope = scope;
}
@Override
public CalledArgument visitVarID(SaralParser.VarIDContext ctx) {
String argName = ctx.ID().getText();
Optional<LocalVariable> argVar = scope.getLocalVariable(argName);
if(!argVar.isPresent()) { | throw new VariableNotFound(scope, argName); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/CalledArgumentVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/CalledArgument.java
// public class CalledArgument {
// private final String name;
//
// public CalledArgument(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotFound.java
// public class VariableNotFound extends RuntimeException {
// public VariableNotFound(Scope scope, String varName) {
// super("No local variable found for name " + varName + " found in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotInitialized.java
// public class VariableNotInitialized extends RuntimeException {
// public VariableNotInitialized(Scope scope, String varName) {
// super("Variable " + varName + " is not initialized in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
| import com.pidanic.saral.domain.CalledArgument;
import com.pidanic.saral.exception.VariableNotFound;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.exception.VariableNotInitialized;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.Optional; | package com.pidanic.saral.visitor;
public class CalledArgumentVisitor extends SaralBaseVisitor<CalledArgument> {
private Scope scope;
public CalledArgumentVisitor(Scope scope) {
this.scope = scope;
}
@Override
public CalledArgument visitVarID(SaralParser.VarIDContext ctx) {
String argName = ctx.ID().getText();
Optional<LocalVariable> argVar = scope.getLocalVariable(argName);
if(!argVar.isPresent()) {
throw new VariableNotFound(scope, argName);
}
if (!argVar.get().isInitialized()) { | // Path: src/main/java/com/pidanic/saral/domain/CalledArgument.java
// public class CalledArgument {
// private final String name;
//
// public CalledArgument(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotFound.java
// public class VariableNotFound extends RuntimeException {
// public VariableNotFound(Scope scope, String varName) {
// super("No local variable found for name " + varName + " found in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/LocalVariable.java
// public class LocalVariable {
//
// public static final String SYSTEM_IN = "SYSTEM_IN";
//
// private final String name;
// private final Type type;
// private boolean initialized;
// private boolean constant;
//
// public LocalVariable(String name, Type type, boolean initialized) {
// this(name, type, initialized, false);
// }
//
// LocalVariable(String name, Type type, boolean initialized, boolean constant) {
// this.name = name;
// this.type = type;
// this.initialized = initialized;
// this.constant = constant;
// }
//
// public Type type() {
// return type;
// }
//
// public String name() {
// return name;
// }
//
// public boolean isInitialized() {
// return initialized;
// }
//
// LocalVariable initialize() {
// return new LocalVariable(name(), type(), true, isConstant());
// }
//
// public boolean isConstant() {
// return constant;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNotInitialized.java
// public class VariableNotInitialized extends RuntimeException {
// public VariableNotInitialized(Scope scope, String varName) {
// super("Variable " + varName + " is not initialized in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/CalledArgumentVisitor.java
import com.pidanic.saral.domain.CalledArgument;
import com.pidanic.saral.exception.VariableNotFound;
import com.pidanic.saral.scope.LocalVariable;
import com.pidanic.saral.exception.VariableNotInitialized;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import java.util.Optional;
package com.pidanic.saral.visitor;
public class CalledArgumentVisitor extends SaralBaseVisitor<CalledArgument> {
private Scope scope;
public CalledArgumentVisitor(Scope scope) {
this.scope = scope;
}
@Override
public CalledArgument visitVarID(SaralParser.VarIDContext ctx) {
String argName = ctx.ID().getText();
Optional<LocalVariable> argVar = scope.getLocalVariable(argName);
if(!argVar.isPresent()) {
throw new VariableNotFound(scope, argName);
}
if (!argVar.get().isInitialized()) { | throw new VariableNotInitialized(scope, argVar.get().name()); |
PaulNoth/saral | src/main/java/com/pidanic/saral/scope/Scope.java | // Path: src/main/java/com/pidanic/saral/domain/block/Function.java
// public class Function extends CallableStatement {
// private String name;
// private List<Argument> arguments;
// private List<Statement> statements;
// private ReturnStatement retStatement;
// private Type returnType;
//
// public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) {
// super(scope);
// this.name = name;
// this.arguments = new ArrayList<>(arguments);
// this.statements = new ArrayList<>(statements);
// this.returnType = returnType;
// this.retStatement = retStatement;
// }
//
// Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType) {
// this(scope, name, arguments, statements, returnType, null);
// }
//
// public String getName() {
// return name;
// }
//
// public List<Argument> getArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public List<Statement> getStatements() {
// return Collections.unmodifiableList(statements);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((CallableStatementGenerator) generator).generate(this);
// }
//
// public Type getReturnType() {
// return returnType;
// }
//
// public Optional<ReturnStatement> getReturnStatement() {
// return Optional.ofNullable(retStatement);
// }
//
// public void setStatements(List<Statement> newStatements) {
// this.statements = newStatements;
// }
//
// public void setRetStatement(ReturnStatement newStatements) {
// this.retStatement = newStatements;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNameAlreadyExists.java
// public class VariableNameAlreadyExists extends RuntimeException {
// public VariableNameAlreadyExists(Scope scope, String varName) {
// super("Local variable " + varName + " already exists in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
| import com.pidanic.saral.domain.block.Function;
import com.pidanic.saral.exception.VariableNameAlreadyExists;
import com.pidanic.saral.util.BuiltInType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; | package com.pidanic.saral.scope;
public class Scope {
private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
private List<LocalVariable> localVariables; | // Path: src/main/java/com/pidanic/saral/domain/block/Function.java
// public class Function extends CallableStatement {
// private String name;
// private List<Argument> arguments;
// private List<Statement> statements;
// private ReturnStatement retStatement;
// private Type returnType;
//
// public Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType, ReturnStatement retStatement) {
// super(scope);
// this.name = name;
// this.arguments = new ArrayList<>(arguments);
// this.statements = new ArrayList<>(statements);
// this.returnType = returnType;
// this.retStatement = retStatement;
// }
//
// Function(Scope scope, String name, List<Argument> arguments, List<Statement> statements, Type returnType) {
// this(scope, name, arguments, statements, returnType, null);
// }
//
// public String getName() {
// return name;
// }
//
// public List<Argument> getArguments() {
// return Collections.unmodifiableList(arguments);
// }
//
// public List<Statement> getStatements() {
// return Collections.unmodifiableList(statements);
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((CallableStatementGenerator) generator).generate(this);
// }
//
// public Type getReturnType() {
// return returnType;
// }
//
// public Optional<ReturnStatement> getReturnStatement() {
// return Optional.ofNullable(retStatement);
// }
//
// public void setStatements(List<Statement> newStatements) {
// this.statements = newStatements;
// }
//
// public void setRetStatement(ReturnStatement newStatements) {
// this.retStatement = newStatements;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/exception/VariableNameAlreadyExists.java
// public class VariableNameAlreadyExists extends RuntimeException {
// public VariableNameAlreadyExists(Scope scope, String varName) {
// super("Local variable " + varName + " already exists in scope " + scope);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/BuiltInType.java
// public enum BuiltInType implements Type {
// BOOLEAN("logický", boolean.class, "Z", TypeSpecificOpcodes.INT),
// INT ("neskutočné numeralio int", int.class, "I", TypeSpecificOpcodes.INT),
// CHAR ("písmeno", char.class, "C", TypeSpecificOpcodes.INT),
// //BYTE ("neskutočné numeralio", byte.class, "B", TypeSpecificOpcodes.INT),
// //SHORT ("neskutočné numeralio", short.class, "S", TypeSpecificOpcodes.INT),
// LONG ("neskutočné numeralio", long.class, "J", TypeSpecificOpcodes.LONG),
// //FLOAT ("skutočné numeralio", float.class, "F", TypeSpecificOpcodes.FLOAT),
// DOUBLE ("skutočné numeralio", double.class, "D", TypeSpecificOpcodes.DOUBLE),
// STRING ("slovo", String.class, "Ljava/lang/String;", TypeSpecificOpcodes.OBJECT),
// BOOLEAN_ARR("funduš logický", boolean[].class, "[B", TypeSpecificOpcodes.BOOLEAN_ARRAY),
// //INT_ARR ("int[]", int[].class, "[I"),
// CHAR_ARR ("funduš písmeno", char[].class, "[C", TypeSpecificOpcodes.CHAR_ARRAY),
// //BYTE_ARR ("byte[]", byte[].class, "[B"),
// //SHORT_ARR ("short[]", short[].class, "[S"),
// LONG_ARR ("funduš neskutočné numeralio", long[].class, "[J", TypeSpecificOpcodes.LONG_ARRAY),
// //FLOAT_ARR ("float[]", float[].class, "[F"),
// DOUBLE_ARR ("funduš skutočné numeralio", double[].class, "[D", TypeSpecificOpcodes.DOUBLE_ARRAY),
// STRING_ARR ("funduš slovo", String[].class, "[Ljava/lang/String;", TypeSpecificOpcodes.OBJECT_ARRAY),
// //NONE("", null,""),
// VOID("void", void.class, "V", TypeSpecificOpcodes.VOID);
//
// private String name;
// private Class<?> typeClass;
// private String descriptor;
// private TypeSpecificOpcodes opCode;
//
// BuiltInType(String name, Class<?> typeClass, String descriptor, TypeSpecificOpcodes op) {
// this.name = name;
// this.typeClass = typeClass;
// this.descriptor = descriptor;
// this.opCode = op;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Class<?> getTypeClass() {
// return typeClass;
// }
//
// @Override
// public String getDescriptor() {
// return descriptor;
// }
//
// @Override
// public String getInternalName() {
// return getDescriptor();
// }
//
// @Override
// public TypeSpecificOpcodes getTypeSpecificOpcode() {
// return opCode;
// }
// }
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
import com.pidanic.saral.domain.block.Function;
import com.pidanic.saral.exception.VariableNameAlreadyExists;
import com.pidanic.saral.util.BuiltInType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
package com.pidanic.saral.scope;
public class Scope {
private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
private List<LocalVariable> localVariables; | private List<Function> functions; |
PaulNoth/saral | src/main/java/com/pidanic/saral/scope/LocalVariableArrayIndex.java | // Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.util.Type; | package com.pidanic.saral.scope;
public class LocalVariableArrayIndex extends LocalVariable {
private Expression index;
| // Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/scope/LocalVariableArrayIndex.java
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.util.Type;
package com.pidanic.saral.scope;
public class LocalVariableArrayIndex extends LocalVariable {
private Expression index;
| public LocalVariableArrayIndex(String name, Type type, boolean initialized, Expression index) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/IfStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/IfStatement.java
// public class IfStatement extends BlockStatementImpl {
// private Expression booleanExpression;
// private List<Statement> trueBlock;
// private List<Statement> falseBlock;
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock) {
// this(scope, booleanExpression, trueBlock, Collections.emptyList());
// }
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock, List<Statement> falseBlock) {
// super(scope);
// if(booleanExpression.type() != BuiltInType.BOOLEAN) {
// throw new IncompatibleTypeIfElse(scope, booleanExpression.type().getName());
// }
// this.booleanExpression = booleanExpression;
// this.trueBlock = trueBlock;
// this.falseBlock = falseBlock;
// if(falseBlock == null) {
// this.falseBlock = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getBooleanExpression() {
// return booleanExpression;
// }
//
// public List<Statement> getTrueBlock() {
// return Collections.unmodifiableList(trueBlock);
// }
//
// public List<Statement> getFalseBlock() {
// return Collections.unmodifiableList(falseBlock);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.IfStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class IfStatementVisitor extends SaralBaseVisitor<IfStatement> {
private Scope scope;
public IfStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
public Scope getScope() {
return scope;
}
@Override
public IfStatement visitIf_statement(SaralParser.If_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
| // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/IfStatement.java
// public class IfStatement extends BlockStatementImpl {
// private Expression booleanExpression;
// private List<Statement> trueBlock;
// private List<Statement> falseBlock;
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock) {
// this(scope, booleanExpression, trueBlock, Collections.emptyList());
// }
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock, List<Statement> falseBlock) {
// super(scope);
// if(booleanExpression.type() != BuiltInType.BOOLEAN) {
// throw new IncompatibleTypeIfElse(scope, booleanExpression.type().getName());
// }
// this.booleanExpression = booleanExpression;
// this.trueBlock = trueBlock;
// this.falseBlock = falseBlock;
// if(falseBlock == null) {
// this.falseBlock = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getBooleanExpression() {
// return booleanExpression;
// }
//
// public List<Statement> getTrueBlock() {
// return Collections.unmodifiableList(trueBlock);
// }
//
// public List<Statement> getFalseBlock() {
// return Collections.unmodifiableList(falseBlock);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/IfStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.IfStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class IfStatementVisitor extends SaralBaseVisitor<IfStatement> {
private Scope scope;
public IfStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
public Scope getScope() {
return scope;
}
@Override
public IfStatement visitIf_statement(SaralParser.If_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
| Expression expression = ctx.expression().accept(expressionVisitor); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/IfStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/IfStatement.java
// public class IfStatement extends BlockStatementImpl {
// private Expression booleanExpression;
// private List<Statement> trueBlock;
// private List<Statement> falseBlock;
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock) {
// this(scope, booleanExpression, trueBlock, Collections.emptyList());
// }
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock, List<Statement> falseBlock) {
// super(scope);
// if(booleanExpression.type() != BuiltInType.BOOLEAN) {
// throw new IncompatibleTypeIfElse(scope, booleanExpression.type().getName());
// }
// this.booleanExpression = booleanExpression;
// this.trueBlock = trueBlock;
// this.falseBlock = falseBlock;
// if(falseBlock == null) {
// this.falseBlock = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getBooleanExpression() {
// return booleanExpression;
// }
//
// public List<Statement> getTrueBlock() {
// return Collections.unmodifiableList(trueBlock);
// }
//
// public List<Statement> getFalseBlock() {
// return Collections.unmodifiableList(falseBlock);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.IfStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class IfStatementVisitor extends SaralBaseVisitor<IfStatement> {
private Scope scope;
public IfStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
public Scope getScope() {
return scope;
}
@Override
public IfStatement visitIf_statement(SaralParser.If_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/IfStatement.java
// public class IfStatement extends BlockStatementImpl {
// private Expression booleanExpression;
// private List<Statement> trueBlock;
// private List<Statement> falseBlock;
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock) {
// this(scope, booleanExpression, trueBlock, Collections.emptyList());
// }
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock, List<Statement> falseBlock) {
// super(scope);
// if(booleanExpression.type() != BuiltInType.BOOLEAN) {
// throw new IncompatibleTypeIfElse(scope, booleanExpression.type().getName());
// }
// this.booleanExpression = booleanExpression;
// this.trueBlock = trueBlock;
// this.falseBlock = falseBlock;
// if(falseBlock == null) {
// this.falseBlock = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getBooleanExpression() {
// return booleanExpression;
// }
//
// public List<Statement> getTrueBlock() {
// return Collections.unmodifiableList(trueBlock);
// }
//
// public List<Statement> getFalseBlock() {
// return Collections.unmodifiableList(falseBlock);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/IfStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.IfStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class IfStatementVisitor extends SaralBaseVisitor<IfStatement> {
private Scope scope;
public IfStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
public Scope getScope() {
return scope;
}
@Override
public IfStatement visitIf_statement(SaralParser.If_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | List<Statement> trueStatement = StatementsHelper.parseStatements(ctx.block().get(0).statements(), scope); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/IfStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/IfStatement.java
// public class IfStatement extends BlockStatementImpl {
// private Expression booleanExpression;
// private List<Statement> trueBlock;
// private List<Statement> falseBlock;
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock) {
// this(scope, booleanExpression, trueBlock, Collections.emptyList());
// }
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock, List<Statement> falseBlock) {
// super(scope);
// if(booleanExpression.type() != BuiltInType.BOOLEAN) {
// throw new IncompatibleTypeIfElse(scope, booleanExpression.type().getName());
// }
// this.booleanExpression = booleanExpression;
// this.trueBlock = trueBlock;
// this.falseBlock = falseBlock;
// if(falseBlock == null) {
// this.falseBlock = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getBooleanExpression() {
// return booleanExpression;
// }
//
// public List<Statement> getTrueBlock() {
// return Collections.unmodifiableList(trueBlock);
// }
//
// public List<Statement> getFalseBlock() {
// return Collections.unmodifiableList(falseBlock);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.IfStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class IfStatementVisitor extends SaralBaseVisitor<IfStatement> {
private Scope scope;
public IfStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
public Scope getScope() {
return scope;
}
@Override
public IfStatement visitIf_statement(SaralParser.If_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/IfStatement.java
// public class IfStatement extends BlockStatementImpl {
// private Expression booleanExpression;
// private List<Statement> trueBlock;
// private List<Statement> falseBlock;
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock) {
// this(scope, booleanExpression, trueBlock, Collections.emptyList());
// }
//
// public IfStatement(Scope scope, Expression booleanExpression, List<Statement> trueBlock, List<Statement> falseBlock) {
// super(scope);
// if(booleanExpression.type() != BuiltInType.BOOLEAN) {
// throw new IncompatibleTypeIfElse(scope, booleanExpression.type().getName());
// }
// this.booleanExpression = booleanExpression;
// this.trueBlock = trueBlock;
// this.falseBlock = falseBlock;
// if(falseBlock == null) {
// this.falseBlock = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getBooleanExpression() {
// return booleanExpression;
// }
//
// public List<Statement> getTrueBlock() {
// return Collections.unmodifiableList(trueBlock);
// }
//
// public List<Statement> getFalseBlock() {
// return Collections.unmodifiableList(falseBlock);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/IfStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.IfStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class IfStatementVisitor extends SaralBaseVisitor<IfStatement> {
private Scope scope;
public IfStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
public Scope getScope() {
return scope;
}
@Override
public IfStatement visitIf_statement(SaralParser.If_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | List<Statement> trueStatement = StatementsHelper.parseStatements(ctx.block().get(0).statements(), scope); |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/expression/UnaryExpression.java | // Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
| import com.pidanic.saral.util.Type; | package com.pidanic.saral.domain.expression;
public abstract class UnaryExpression extends Expression {
private Expression expression;
private Sign sign;
| // Path: src/main/java/com/pidanic/saral/util/Type.java
// public interface Type {
// String getName();
// Class<?> getTypeClass();
// String getDescriptor();
// String getInternalName();
// TypeSpecificOpcodes getTypeSpecificOpcode();
// }
// Path: src/main/java/com/pidanic/saral/domain/expression/UnaryExpression.java
import com.pidanic.saral.util.Type;
package com.pidanic.saral.domain.expression;
public abstract class UnaryExpression extends Expression {
private Expression expression;
private Sign sign;
| public UnaryExpression(Type type, Sign sign, Expression left) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/SaralCompilationUnitParser.java | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/error/SaralTreeWalkErrorListener.java
// public class SaralTreeWalkErrorListener extends BaseErrorListener {
// @Override
// public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
// final String errorFormat = "You fucked up at line %d,char %d :(. Details:\n%s";
// final String errorMsg = String.format(errorFormat, line, charPositionInLine, msg);
// System.out.println(errorMsg);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/visitor/InitVisitor.java
// public class InitVisitor extends SaralBaseVisitor<Init> {
//
// private Scope scope;
//
// public InitVisitor(String className) {
// this.scope = new Scope(className);
// }
//
// @Override
// public Init visitInit(SaralParser.InitContext ctx) {
// List<Statement> allStatements = ctx.statements().statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new StatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new StatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return new Init(scope, allStatements);
// }
// }
| import com.pidanic.saral.domain.Init;
import com.pidanic.saral.error.SaralTreeWalkErrorListener;
import com.pidanic.saral.grammar.SaralLexer;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.visitor.InitVisitor;
import org.antlr.v4.runtime.*;
import java.io.File;
import java.io.IOException; | package com.pidanic.saral;
public class SaralCompilationUnitParser {
public Init getCompilationUnit(File preprocessedTempFile, String className) throws IOException{
String fileAbsPath = preprocessedTempFile.getAbsolutePath();
CharStream charStream = CharStreams.fromFileName(fileAbsPath);
SaralLexer saralLexer = new SaralLexer(charStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(saralLexer);
SaralParser saralParser = new SaralParser(commonTokenStream);
| // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/error/SaralTreeWalkErrorListener.java
// public class SaralTreeWalkErrorListener extends BaseErrorListener {
// @Override
// public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
// final String errorFormat = "You fucked up at line %d,char %d :(. Details:\n%s";
// final String errorMsg = String.format(errorFormat, line, charPositionInLine, msg);
// System.out.println(errorMsg);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/visitor/InitVisitor.java
// public class InitVisitor extends SaralBaseVisitor<Init> {
//
// private Scope scope;
//
// public InitVisitor(String className) {
// this.scope = new Scope(className);
// }
//
// @Override
// public Init visitInit(SaralParser.InitContext ctx) {
// List<Statement> allStatements = ctx.statements().statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new StatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new StatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return new Init(scope, allStatements);
// }
// }
// Path: src/main/java/com/pidanic/saral/SaralCompilationUnitParser.java
import com.pidanic.saral.domain.Init;
import com.pidanic.saral.error.SaralTreeWalkErrorListener;
import com.pidanic.saral.grammar.SaralLexer;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.visitor.InitVisitor;
import org.antlr.v4.runtime.*;
import java.io.File;
import java.io.IOException;
package com.pidanic.saral;
public class SaralCompilationUnitParser {
public Init getCompilationUnit(File preprocessedTempFile, String className) throws IOException{
String fileAbsPath = preprocessedTempFile.getAbsolutePath();
CharStream charStream = CharStreams.fromFileName(fileAbsPath);
SaralLexer saralLexer = new SaralLexer(charStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(saralLexer);
SaralParser saralParser = new SaralParser(commonTokenStream);
| BaseErrorListener errorListener = new SaralTreeWalkErrorListener(); |
PaulNoth/saral | src/main/java/com/pidanic/saral/SaralCompilationUnitParser.java | // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/error/SaralTreeWalkErrorListener.java
// public class SaralTreeWalkErrorListener extends BaseErrorListener {
// @Override
// public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
// final String errorFormat = "You fucked up at line %d,char %d :(. Details:\n%s";
// final String errorMsg = String.format(errorFormat, line, charPositionInLine, msg);
// System.out.println(errorMsg);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/visitor/InitVisitor.java
// public class InitVisitor extends SaralBaseVisitor<Init> {
//
// private Scope scope;
//
// public InitVisitor(String className) {
// this.scope = new Scope(className);
// }
//
// @Override
// public Init visitInit(SaralParser.InitContext ctx) {
// List<Statement> allStatements = ctx.statements().statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new StatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new StatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return new Init(scope, allStatements);
// }
// }
| import com.pidanic.saral.domain.Init;
import com.pidanic.saral.error.SaralTreeWalkErrorListener;
import com.pidanic.saral.grammar.SaralLexer;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.visitor.InitVisitor;
import org.antlr.v4.runtime.*;
import java.io.File;
import java.io.IOException; | package com.pidanic.saral;
public class SaralCompilationUnitParser {
public Init getCompilationUnit(File preprocessedTempFile, String className) throws IOException{
String fileAbsPath = preprocessedTempFile.getAbsolutePath();
CharStream charStream = CharStreams.fromFileName(fileAbsPath);
SaralLexer saralLexer = new SaralLexer(charStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(saralLexer);
SaralParser saralParser = new SaralParser(commonTokenStream);
BaseErrorListener errorListener = new SaralTreeWalkErrorListener();
saralParser.addErrorListener(errorListener);
| // Path: src/main/java/com/pidanic/saral/domain/Init.java
// public class Init {
// private List<Statement> instructions;
// private Scope scope;
//
// public Init(Scope scope, List<Statement> instructions) {
// this.instructions = instructions;
// this.scope = scope;
// }
//
// public List<Statement> getStatements() {
// return instructions;
// }
//
// public void accept(InitGenerator generator) {
// generator.generate(this);
// }
//
// public Scope getScope() {
// return scope;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/error/SaralTreeWalkErrorListener.java
// public class SaralTreeWalkErrorListener extends BaseErrorListener {
// @Override
// public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
// final String errorFormat = "You fucked up at line %d,char %d :(. Details:\n%s";
// final String errorMsg = String.format(errorFormat, line, charPositionInLine, msg);
// System.out.println(errorMsg);
// }
// }
//
// Path: src/main/java/com/pidanic/saral/visitor/InitVisitor.java
// public class InitVisitor extends SaralBaseVisitor<Init> {
//
// private Scope scope;
//
// public InitVisitor(String className) {
// this.scope = new Scope(className);
// }
//
// @Override
// public Init visitInit(SaralParser.InitContext ctx) {
// List<Statement> allStatements = ctx.statements().statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new StatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new StatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return new Init(scope, allStatements);
// }
// }
// Path: src/main/java/com/pidanic/saral/SaralCompilationUnitParser.java
import com.pidanic.saral.domain.Init;
import com.pidanic.saral.error.SaralTreeWalkErrorListener;
import com.pidanic.saral.grammar.SaralLexer;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.visitor.InitVisitor;
import org.antlr.v4.runtime.*;
import java.io.File;
import java.io.IOException;
package com.pidanic.saral;
public class SaralCompilationUnitParser {
public Init getCompilationUnit(File preprocessedTempFile, String className) throws IOException{
String fileAbsPath = preprocessedTempFile.getAbsolutePath();
CharStream charStream = CharStreams.fromFileName(fileAbsPath);
SaralLexer saralLexer = new SaralLexer(charStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(saralLexer);
SaralParser saralParser = new SaralParser(commonTokenStream);
BaseErrorListener errorListener = new SaralTreeWalkErrorListener();
saralParser.addErrorListener(errorListener);
| InitVisitor initVisitor = new InitVisitor(className); |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/ReturnStatement.java | // Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
// public class ReturnStatementGenerator extends StatementGenerator {
//
// private final MethodVisitor methodVisitor;
// private final Scope scope;
//
// public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
// this.scope = scope;
// this.methodVisitor = methodVisitor;
// }
//
// public void generate(ReturnStatement retStatement) {
// Expression returnVariable = retStatement.getExpression();
// Type retType = returnVariable.type();
// returnVariable.accept(new ExpressionGenerator(methodVisitor, scope));
// methodVisitor.visitInsn(retType.getTypeSpecificOpcode().getReturn());
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
| import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.generator.ReturnStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator; | package com.pidanic.saral.domain;
public class ReturnStatement implements Statement {
private Expression expression;
public ReturnStatement(Expression variable) {
this.expression = variable;
}
@Override | // Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
// public class ReturnStatementGenerator extends StatementGenerator {
//
// private final MethodVisitor methodVisitor;
// private final Scope scope;
//
// public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
// this.scope = scope;
// this.methodVisitor = methodVisitor;
// }
//
// public void generate(ReturnStatement retStatement) {
// Expression returnVariable = retStatement.getExpression();
// Type retType = returnVariable.type();
// returnVariable.accept(new ExpressionGenerator(methodVisitor, scope));
// methodVisitor.visitInsn(retType.getTypeSpecificOpcode().getReturn());
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
// Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.generator.ReturnStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
package com.pidanic.saral.domain;
public class ReturnStatement implements Statement {
private Expression expression;
public ReturnStatement(Expression variable) {
this.expression = variable;
}
@Override | public void accept(StatementGenerator generator) { |
PaulNoth/saral | src/main/java/com/pidanic/saral/domain/ReturnStatement.java | // Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
// public class ReturnStatementGenerator extends StatementGenerator {
//
// private final MethodVisitor methodVisitor;
// private final Scope scope;
//
// public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
// this.scope = scope;
// this.methodVisitor = methodVisitor;
// }
//
// public void generate(ReturnStatement retStatement) {
// Expression returnVariable = retStatement.getExpression();
// Type retType = returnVariable.type();
// returnVariable.accept(new ExpressionGenerator(methodVisitor, scope));
// methodVisitor.visitInsn(retType.getTypeSpecificOpcode().getReturn());
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
| import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.generator.ReturnStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator; | package com.pidanic.saral.domain;
public class ReturnStatement implements Statement {
private Expression expression;
public ReturnStatement(Expression variable) {
this.expression = variable;
}
@Override
public void accept(StatementGenerator generator) { | // Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/generator/ReturnStatementGenerator.java
// public class ReturnStatementGenerator extends StatementGenerator {
//
// private final MethodVisitor methodVisitor;
// private final Scope scope;
//
// public ReturnStatementGenerator(Scope scope, MethodVisitor methodVisitor) {
// this.scope = scope;
// this.methodVisitor = methodVisitor;
// }
//
// public void generate(ReturnStatement retStatement) {
// Expression returnVariable = retStatement.getExpression();
// Type retType = returnVariable.type();
// returnVariable.accept(new ExpressionGenerator(methodVisitor, scope));
// methodVisitor.visitInsn(retType.getTypeSpecificOpcode().getReturn());
// }
// }
//
// Path: src/main/java/com/pidanic/saral/generator/StatementGenerator.java
// public class StatementGenerator {
// }
// Path: src/main/java/com/pidanic/saral/domain/ReturnStatement.java
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.generator.ReturnStatementGenerator;
import com.pidanic.saral.generator.StatementGenerator;
package com.pidanic.saral.domain;
public class ReturnStatement implements Statement {
private Expression expression;
public ReturnStatement(Expression variable) {
this.expression = variable;
}
@Override
public void accept(StatementGenerator generator) { | ((ReturnStatementGenerator) generator).generate(this); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope); | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope); | Expression expression = ctx.expression().accept(expressionVisitor); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | List<Statement> block = StatementsHelper.parseStatements(ctx.block().statements(), scope); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor); | List<Statement> block = StatementsHelper.parseStatements(ctx.block().statements(), scope); |
PaulNoth/saral | src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
| import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List; | package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor);
List<Statement> block = StatementsHelper.parseStatements(ctx.block().statements(), scope);
if(block.isEmpty()) { | // Path: src/main/java/com/pidanic/saral/domain/Statement.java
// public interface Statement {
// void accept(StatementGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/domain/block/WhileStatement.java
// public class WhileStatement extends BlockStatementImpl {
//
// private List<Statement> block;
// private Expression expression;
//
// public WhileStatement(Scope scope, Expression expression, List<Statement> block) {
// super(scope);
// this.expression = expression;
// if(block != null) {
// this.block = Collections.unmodifiableList(block);
// } else {
// this.block = Collections.emptyList();
// }
// }
//
// @Override
// public void accept(StatementGenerator generator) {
// ((BlockStatementGenerator) generator).generate(this);
// }
//
// public Expression getExpression() {
// return expression;
// }
//
// public List<Statement> getBlock() {
// return block;
// }
// }
//
// Path: src/main/java/com/pidanic/saral/domain/expression/Expression.java
// public abstract class Expression {
// private Type type;
//
// public Expression(Type type) {
// this.type = type;
// }
//
// public Type type() {
// return type;
// }
//
// public abstract void accept(ExpressionGenerator generator);
// }
//
// Path: src/main/java/com/pidanic/saral/exception/EmptyWhileStatementBlock.java
// public class EmptyWhileStatementBlock extends RuntimeException {
// public EmptyWhileStatementBlock(Scope scope) {
// super("You defined empty while loop");
// }
// }
//
// Path: src/main/java/com/pidanic/saral/scope/Scope.java
// public class Scope {
//
// private static final LocalVariable EMPTY = new LocalVariable("empty", BuiltInType.BOOLEAN, true);
//
// private List<LocalVariable> localVariables;
// private List<Function> functions;
// private String className;
//
// public Scope(String className) {
// localVariables = new ArrayList<>();
// functions = new ArrayList<>();
// this.className = className;
// }
//
// public Scope(Scope scope) {
// localVariables = new ArrayList<>(scope.localVariables);
// functions = new ArrayList<>(scope.functions);
// className = scope.className;
// }
//
// public List<LocalVariable> getLocalVariables() {
// return Collections.unmodifiableList(localVariables);
// }
//
// public void addLocalVariable(LocalVariable localVariable) {
// localVariables.add(localVariable);
// if(localVariable.type() == BuiltInType.LONG || localVariable.type() == BuiltInType.DOUBLE) {
// localVariables.add(EMPTY);
// }
// }
//
// public boolean existsLocalVariable(String variableName) {
// return localVariables.stream().anyMatch(variable -> variable.name().equals(variableName));
// }
//
// public Optional<LocalVariable> getLocalVariable(String varName) {
// return localVariables.stream()
// .filter(variable -> variable.name().equals(varName))
// .findFirst();
// }
//
// public int getLocalVariableIndex(String varName) {
// return localVariables.stream().map(LocalVariable::name).collect(Collectors.toList()).indexOf(varName);
// }
//
// public Optional<Function> getFunction(String functionName) {
// return functions.stream().filter(proc -> proc.getName().equals(functionName))
// .findFirst();
// }
//
// public String getClassName() {
// return className;
// }
//
// public void addFunction(Function function) {
// this.functions.add(function);
// }
//
// public LocalVariable initializeLocalVariableAtIndex(int index) {
// LocalVariable localVariable = this.localVariables.get(index);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public LocalVariable initializeLocalVariable(String name) {
// LocalVariable localVariable = getLocalVariable(name).get();
// int index = getLocalVariableIndex(name);
// LocalVariable initializedLocalVar = localVariable.initialize();
// this.localVariables.set(index, initializedLocalVar);
// return initializedLocalVar;
// }
//
// public int localVariablesCount() {
// return localVariables.size();
// }
// }
//
// Path: src/main/java/com/pidanic/saral/util/StatementsHelper.java
// public final class StatementsHelper {
// public static List<Statement> parseStatements(SaralParser.StatementsContext statementsContext, Scope scope) {
// List<Statement> allStatements = statementsContext.statement().stream().map(stmtCtx -> {
// SaralParser.Block_statementContext block = stmtCtx.block_statement();
// SaralParser.Simple_statementContext simpleStmt = stmtCtx.simple_statement();
// Statement val;
// if(block != null) {
// val = block.accept(new BlockStatementVisitor(scope));
// } else {
// val = simpleStmt.accept(new SimpleStatementVisitor(scope));
// }
// return val;
// }).collect(Collectors.toList());
//
// return allStatements;
// }
// }
// Path: src/main/java/com/pidanic/saral/visitor/WhileStatementVisitor.java
import com.pidanic.saral.domain.Statement;
import com.pidanic.saral.domain.block.WhileStatement;
import com.pidanic.saral.domain.expression.Expression;
import com.pidanic.saral.exception.EmptyWhileStatementBlock;
import com.pidanic.saral.grammar.SaralBaseVisitor;
import com.pidanic.saral.grammar.SaralParser;
import com.pidanic.saral.scope.Scope;
import com.pidanic.saral.util.StatementsHelper;
import java.util.List;
package com.pidanic.saral.visitor;
public class WhileStatementVisitor extends SaralBaseVisitor<WhileStatement> {
private Scope scope;
public WhileStatementVisitor(Scope scope) {
this.scope = new Scope(scope);
}
@Override
public WhileStatement visitWhile_statement(SaralParser.While_statementContext ctx) {
ExpressionVisitor expressionVisitor = new ExpressionVisitor(scope);
Expression expression = ctx.expression().accept(expressionVisitor);
List<Statement> block = StatementsHelper.parseStatements(ctx.block().statements(), scope);
if(block.isEmpty()) { | throw new EmptyWhileStatementBlock(scope); |
pivio/pivio-web | src/test/java/io/pivio/view/app/overview/detail/view/DocumentViewModelTest.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package io.pivio.view.app.overview.detail.view;
public class DocumentViewModelTest {
private DocumentViewModel documentViewModel;
@Before
public void setup() { | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/test/java/io/pivio/view/app/overview/detail/view/DocumentViewModelTest.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package io.pivio.view.app.overview.detail.view;
public class DocumentViewModelTest {
private DocumentViewModel documentViewModel;
@Before
public void setup() { | Document document = new Document(); |
pivio/pivio-web | src/test/java/io/pivio/view/app/overview/detail/view/DocumentViewModelTest.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | package io.pivio.view.app.overview.detail.view;
public class DocumentViewModelTest {
private DocumentViewModel documentViewModel;
@Before
public void setup() {
Document document = new Document();
document.short_name = "SHORT";
document.software_dependencies = generateDependencies();
documentViewModel = new DocumentViewModel(document);
}
@Test
public void getConsolidatedLicenses() throws Exception {
List<String> consolidatedLicenses = documentViewModel.getConsolidatedLicenses();
assertThat(consolidatedLicenses).hasSize(7);
}
@Test
public void testContainsUnknownLicense() throws Exception {
List<String> consolidatedLicenses = documentViewModel.getConsolidatedLicenses();
assertThat(consolidatedLicenses).contains(documentViewModel.UNKNOWN_LICENSE);
}
@Test
public void testSortedDependencies() throws Exception { | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/test/java/io/pivio/view/app/overview/detail/view/DocumentViewModelTest.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
package io.pivio.view.app.overview.detail.view;
public class DocumentViewModelTest {
private DocumentViewModel documentViewModel;
@Before
public void setup() {
Document document = new Document();
document.short_name = "SHORT";
document.software_dependencies = generateDependencies();
documentViewModel = new DocumentViewModel(document);
}
@Test
public void getConsolidatedLicenses() throws Exception {
List<String> consolidatedLicenses = documentViewModel.getConsolidatedLicenses();
assertThat(consolidatedLicenses).hasSize(7);
}
@Test
public void testContainsUnknownLicense() throws Exception {
List<String> consolidatedLicenses = documentViewModel.getConsolidatedLicenses();
assertThat(consolidatedLicenses).contains(documentViewModel.UNKNOWN_LICENSE);
}
@Test
public void testSortedDependencies() throws Exception { | List<SoftwareDependency> sortedDependencies = documentViewModel.getSortedDependencies(); |
pivio/pivio-web | src/test/java/io/pivio/view/app/overview/detail/view/DocumentViewModelTest.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; | @Test
public void testSortedDependencies() throws Exception {
List<SoftwareDependency> sortedDependencies = documentViewModel.getSortedDependencies();
assertThat(sortedDependencies.get(0).name).isEqualTo("A");
assertThat(sortedDependencies.get(1).name).isEqualTo("B");
assertThat(sortedDependencies.get(2).name).isEqualTo("C");
}
@Test
public void testGetShortName() throws Exception {
assertThat(documentViewModel.getShortName()).isEqualTo("(SHORT)");
}
@Test
public void testGetNullShortName() throws Exception {
Document document = new Document();
document.short_name = null;
documentViewModel = new DocumentViewModel(document);
assertThat(documentViewModel.getShortName()).isEqualTo("");
}
private ArrayList<SoftwareDependency> generateDependencies() {
ArrayList<SoftwareDependency> softwareDependencies = new ArrayList<>();
softwareDependencies.add(new SoftwareDependency("B", "1", generateLicenses("-B-")));
softwareDependencies.add(new SoftwareDependency("A", "1", generateLicenses("-A-")));
softwareDependencies.add(new SoftwareDependency("C", "1", generateLicenses("-A-")));
return softwareDependencies;
}
| // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/test/java/io/pivio/view/app/overview/detail/view/DocumentViewModelTest.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void testSortedDependencies() throws Exception {
List<SoftwareDependency> sortedDependencies = documentViewModel.getSortedDependencies();
assertThat(sortedDependencies.get(0).name).isEqualTo("A");
assertThat(sortedDependencies.get(1).name).isEqualTo("B");
assertThat(sortedDependencies.get(2).name).isEqualTo("C");
}
@Test
public void testGetShortName() throws Exception {
assertThat(documentViewModel.getShortName()).isEqualTo("(SHORT)");
}
@Test
public void testGetNullShortName() throws Exception {
Document document = new Document();
document.short_name = null;
documentViewModel = new DocumentViewModel(document);
assertThat(documentViewModel.getShortName()).isEqualTo("");
}
private ArrayList<SoftwareDependency> generateDependencies() {
ArrayList<SoftwareDependency> softwareDependencies = new ArrayList<>();
softwareDependencies.add(new SoftwareDependency("B", "1", generateLicenses("-B-")));
softwareDependencies.add(new SoftwareDependency("A", "1", generateLicenses("-A-")));
softwareDependencies.add(new SoftwareDependency("C", "1", generateLicenses("-A-")));
return softwareDependencies;
}
| private ArrayList<License> generateLicenses(String prefix) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort; | package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License."; | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort;
package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License."; | public Document document; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort; | package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License.";
public Document document;
public ServiceViewModel service = new ServiceViewModel(); | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort;
package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License.";
public Document document;
public ServiceViewModel service = new ServiceViewModel(); | public List<SoftwareDependency> softwareDependencies = new ArrayList<>(); |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort; | package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License.";
public Document document;
public ServiceViewModel service = new ServiceViewModel();
public List<SoftwareDependency> softwareDependencies = new ArrayList<>();
public DocumentViewModel(Document document) {
this.document = document;
setupServiceViewModel();
}
public String getShortName() {
return document.short_name != null ? "(" + document.short_name + ")" : "";
}
private void setupServiceViewModel() { | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort;
package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License.";
public Document document;
public ServiceViewModel service = new ServiceViewModel();
public List<SoftwareDependency> softwareDependencies = new ArrayList<>();
public DocumentViewModel(Document document) {
this.document = document;
setupServiceViewModel();
}
public String getShortName() {
return document.short_name != null ? "(" + document.short_name + ")" : "";
}
private void setupServiceViewModel() { | for (Provides provide : document.service.provides) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort; | package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License.";
public Document document;
public ServiceViewModel service = new ServiceViewModel();
public List<SoftwareDependency> softwareDependencies = new ArrayList<>();
public DocumentViewModel(Document document) {
this.document = document;
setupServiceViewModel();
}
public String getShortName() {
return document.short_name != null ? "(" + document.short_name + ")" : "";
}
private void setupServiceViewModel() {
for (Provides provide : document.service.provides) {
service.provides.add(new ProvidesModel(provide));
}
this.softwareDependencies = document.software_dependencies;
}
public List<String> getConsolidatedLicenses() {
List<String> result = new ArrayList<>();
for (SoftwareDependency software_dependency : softwareDependencies) { | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/License.java
// @JsonIgnoreProperties(ignoreUnknown=true)
// public class License {
// public String fullName;
// public String url;
//
// public License(String fullName, String url) {
// this.fullName = fullName;
// this.url = url;
// }
//
// public License() {
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/SoftwareDependency.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class SoftwareDependency implements Comparable {
//
// public String name;
// public String version;
// public List<License> licenses = new ArrayList<>();
//
// public SoftwareDependency() {
// }
//
// public SoftwareDependency(String name, String version, List<License> licenses) {
// this.name = name;
// this.version = version;
// this.licenses = licenses;
// }
//
// @Override
// public int compareTo(Object o) {
// return name.compareTo(((SoftwareDependency)o).name);
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/DocumentViewModel.java
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.detail.serverresponse.License;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import io.pivio.view.app.overview.detail.serverresponse.SoftwareDependency;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort;
package io.pivio.view.app.overview.detail.view;
public class DocumentViewModel {
final String UNKNOWN_LICENSE = "Unknown License.";
public Document document;
public ServiceViewModel service = new ServiceViewModel();
public List<SoftwareDependency> softwareDependencies = new ArrayList<>();
public DocumentViewModel(Document document) {
this.document = document;
setupServiceViewModel();
}
public String getShortName() {
return document.short_name != null ? "(" + document.short_name + ")" : "";
}
private void setupServiceViewModel() {
for (Provides provide : document.service.provides) {
service.provides.add(new ProvidesModel(provide));
}
this.softwareDependencies = document.software_dependencies;
}
public List<String> getConsolidatedLicenses() {
List<String> result = new ArrayList<>();
for (SoftwareDependency software_dependency : softwareDependencies) { | for (License license : software_dependency.licenses) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/feed/FeedController.java | // Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
| import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; | package io.pivio.view.app.feed;
@Controller
public class FeedController {
@Autowired | // Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/feed/FeedController.java
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
package io.pivio.view.app.feed;
@Controller
public class FeedController {
@Autowired | ServerConfig serverConfig; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/ProvidesModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Internal.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Internal {
//
// public String service_name = "";
// public String short_name = "";
// public String port = "";
// public String why = "";
// public String label = "";
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
| import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Internal;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import java.util.ArrayList;
import java.util.List; | package io.pivio.view.app.overview.detail.view;
public class ProvidesModel {
public String description;
public String service_name;
public String protocol;
public String port;
public String transport_protocol;
public List<String> public_dns = new ArrayList<>();
public List<DependentServiceViewModel> dependentServices = new ArrayList<>();
| // Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Internal.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Internal {
//
// public String service_name = "";
// public String short_name = "";
// public String port = "";
// public String why = "";
// public String label = "";
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/ProvidesModel.java
import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Internal;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import java.util.ArrayList;
import java.util.List;
package io.pivio.view.app.overview.detail.view;
public class ProvidesModel {
public String description;
public String service_name;
public String protocol;
public String port;
public String transport_protocol;
public List<String> public_dns = new ArrayList<>();
public List<DependentServiceViewModel> dependentServices = new ArrayList<>();
| public ProvidesModel(Provides provides) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/ProvidesModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Internal.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Internal {
//
// public String service_name = "";
// public String short_name = "";
// public String port = "";
// public String why = "";
// public String label = "";
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
| import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Internal;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import java.util.ArrayList;
import java.util.List; | package io.pivio.view.app.overview.detail.view;
public class ProvidesModel {
public String description;
public String service_name;
public String protocol;
public String port;
public String transport_protocol;
public List<String> public_dns = new ArrayList<>();
public List<DependentServiceViewModel> dependentServices = new ArrayList<>();
public ProvidesModel(Provides provides) {
this.description = provides.description;
this.service_name = provides.service_name;
this.protocol = provides.protocol;
this.port = provides.port;
this.transport_protocol = provides.transport_protocol;
this.public_dns = provides.public_dns;
}
public String getTechInfo() {
return protocol + " " + transport_protocol + " " + port;
}
| // Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Internal.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Internal {
//
// public String service_name = "";
// public String short_name = "";
// public String port = "";
// public String why = "";
// public String label = "";
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/ProvidesModel.java
import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Internal;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import java.util.ArrayList;
import java.util.List;
package io.pivio.view.app.overview.detail.view;
public class ProvidesModel {
public String description;
public String service_name;
public String protocol;
public String port;
public String transport_protocol;
public List<String> public_dns = new ArrayList<>();
public List<DependentServiceViewModel> dependentServices = new ArrayList<>();
public ProvidesModel(Provides provides) {
this.description = provides.description;
this.service_name = provides.service_name;
this.protocol = provides.protocol;
this.port = provides.port;
this.transport_protocol = provides.transport_protocol;
this.public_dns = provides.public_dns;
}
public String getTechInfo() {
return protocol + " " + transport_protocol + " " + port;
}
| public void setDependentServices(List<ServiceIdShortName> allServices, String short_name) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/view/ProvidesModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Internal.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Internal {
//
// public String service_name = "";
// public String short_name = "";
// public String port = "";
// public String why = "";
// public String label = "";
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
| import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Internal;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import java.util.ArrayList;
import java.util.List; | package io.pivio.view.app.overview.detail.view;
public class ProvidesModel {
public String description;
public String service_name;
public String protocol;
public String port;
public String transport_protocol;
public List<String> public_dns = new ArrayList<>();
public List<DependentServiceViewModel> dependentServices = new ArrayList<>();
public ProvidesModel(Provides provides) {
this.description = provides.description;
this.service_name = provides.service_name;
this.protocol = provides.protocol;
this.port = provides.port;
this.transport_protocol = provides.transport_protocol;
this.public_dns = provides.public_dns;
}
public String getTechInfo() {
return protocol + " " + transport_protocol + " " + port;
}
public void setDependentServices(List<ServiceIdShortName> allServices, String short_name) {
for (ServiceIdShortName service : allServices) {
if (service.hasDependencies()) { | // Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Internal.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Internal {
//
// public String service_name = "";
// public String short_name = "";
// public String port = "";
// public String why = "";
// public String label = "";
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/view/ProvidesModel.java
import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Internal;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import java.util.ArrayList;
import java.util.List;
package io.pivio.view.app.overview.detail.view;
public class ProvidesModel {
public String description;
public String service_name;
public String protocol;
public String port;
public String transport_protocol;
public List<String> public_dns = new ArrayList<>();
public List<DependentServiceViewModel> dependentServices = new ArrayList<>();
public ProvidesModel(Provides provides) {
this.description = provides.description;
this.service_name = provides.service_name;
this.protocol = provides.protocol;
this.port = provides.port;
this.transport_protocol = provides.transport_protocol;
this.public_dns = provides.public_dns;
}
public String getTechInfo() {
return protocol + " " + transport_protocol + " " + port;
}
public void setDependentServices(List<ServiceIdShortName> allServices, String short_name) {
for (ServiceIdShortName service : allServices) {
if (service.hasDependencies()) { | for (Internal internalDependency : service.service.depends_on.internal) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/DetailController.java | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
| import io.pivio.view.PivioServerConnector;
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.io.IOException; | package io.pivio.view.app.overview.detail;
@Controller
public class DetailController {
@Autowired | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/DetailController.java
import io.pivio.view.PivioServerConnector;
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.io.IOException;
package io.pivio.view.app.overview.detail;
@Controller
public class DetailController {
@Autowired | ServerConfig serverConfig; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/DetailController.java | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
| import io.pivio.view.PivioServerConnector;
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.io.IOException; | package io.pivio.view.app.overview.detail;
@Controller
public class DetailController {
@Autowired
ServerConfig serverConfig;
@Autowired
DetailService detailService;
@Autowired | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/DetailController.java
import io.pivio.view.PivioServerConnector;
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.io.IOException;
package io.pivio.view.app.overview.detail;
@Controller
public class DetailController {
@Autowired
ServerConfig serverConfig;
@Autowired
DetailService detailService;
@Autowired | PivioServerConnector pivioServerConnector; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/list/OverviewModel.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Context.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Context {
//
// public String belongs_to_bounded_context;
// public String visibility;
//
// @Override
// public String toString() {
// return "Context{" +
// "belongs_to_bounded_context='" + belongs_to_bounded_context + '\'' +
// ", visibility='" + visibility + '\'' +
// '}';
// }
// }
| import io.pivio.view.app.overview.detail.serverresponse.Context;
import org.joda.time.DateTime;
import org.ocpsoft.prettytime.PrettyTime; | package io.pivio.view.app.overview.list;
public class OverviewModel {
public String name;
public String short_name;
public String description;
public String lastUpload;
public String lastUpdate; | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Context.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Context {
//
// public String belongs_to_bounded_context;
// public String visibility;
//
// @Override
// public String toString() {
// return "Context{" +
// "belongs_to_bounded_context='" + belongs_to_bounded_context + '\'' +
// ", visibility='" + visibility + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/list/OverviewModel.java
import io.pivio.view.app.overview.detail.serverresponse.Context;
import org.joda.time.DateTime;
import org.ocpsoft.prettytime.PrettyTime;
package io.pivio.view.app.overview.list;
public class OverviewModel {
public String name;
public String short_name;
public String description;
public String lastUpload;
public String lastUpdate; | public Context context; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/ServiceListGenerator.java | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
| import io.pivio.view.PivioServerConnector;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map; | package io.pivio.view.app.overview.detail;
/**
* Produces a map with serviceId as key and service_names and short_name:port as values of
* all services known to the system.
*/
@Service
public class ServiceListGenerator {
@Autowired | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/ServiceListGenerator.java
import io.pivio.view.PivioServerConnector;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
package io.pivio.view.app.overview.detail;
/**
* Produces a map with serviceId as key and service_names and short_name:port as values of
* all services known to the system.
*/
@Service
public class ServiceListGenerator {
@Autowired | PivioServerConnector pivioServerConnector; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/detail/ServiceListGenerator.java | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
| import io.pivio.view.PivioServerConnector;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map; | package io.pivio.view.app.overview.detail;
/**
* Produces a map with serviceId as key and service_names and short_name:port as values of
* all services known to the system.
*/
@Service
public class ServiceListGenerator {
@Autowired
PivioServerConnector pivioServerConnector;
Map<String, String> getServiceNameMap() {
List<ServiceIdShortName> allServices = pivioServerConnector.getAllServices();
Map<String, String> serviceNameMap = new HashMap<>();
for (ServiceIdShortName service : allServices) {
if (service.service != null) { | // Path: src/main/java/io/pivio/view/PivioServerConnector.java
// @Component
// public class PivioServerConnector {
//
// private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
//
// @Autowired
// ServerConfig serverConfig;
//
// public <T> ResponseEntity query(String path, String query, Class<T> type) throws UnsupportedEncodingException {
// String encodedQuery = URLEncoder.encode(query, "UTF-8");
// return get(serverConfig.apiAddress + path + encodedQuery, type);
// }
//
// public Document getDocumentById(String id) throws UnsupportedEncodingException {
// ResponseEntity responseEntity = get(serverConfig.apiAddress + "/document/" + id, Document.class);
// return (Document) responseEntity.getBody();
// }
//
// public <T> ResponseEntity list(String path, Class<T> type) throws UnsupportedEncodingException {
// return get(serverConfig.apiAddress + path, type);
// }
//
// public List<Overview> getOverviews() throws IOException {
// String path = "/document?fields=short_name,id,description,name,owner,context,lastUpdate,lastUpload,type&sort=name:asc";
// String url = serverConfig.apiAddress + path;
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<Overview>> typeRef = new ParameterizedTypeReference<List<Overview>>() {
// };
// List<Overview> result;
// try {
// ResponseEntity<List<Overview>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// result = response.getBody();
// sort(result);
// } catch (Exception e) {
// log.error("Pivio Server at {} does not respond (Exception=\n{}\n).", url, e.getMessage());
// throw new IOException("Unable to connect to " + url + ".");
// }
// return result;
// }
//
// private <T> ResponseEntity get(String url, Class<T> type) throws UnsupportedEncodingException {
// RestTemplate restTemplate = new RestTemplate();
// log.debug("Asking for :" + url);
// ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), type);
// log.debug("Response :" + response.getBody().toString());
// return response;
// }
//
// private HttpHeaders getHeaders() {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
// return headers;
// }
//
// public List<ServiceIdShortName> getAllServices() {
// String url = serverConfig.apiAddress + "/document?fields=service,id,short_name";
// RestTemplate restTemplate = new RestTemplate();
// ParameterizedTypeReference<List<ServiceIdShortName>> typeRef = new ParameterizedTypeReference<List<ServiceIdShortName>>() {
// };
// log.debug("Query {}.", url);
// ResponseEntity<List<ServiceIdShortName>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", getHeaders()), typeRef);
// return response.getBody();
// }
//
// public boolean deleteDocument(String id) throws IOException {
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// String url = serverConfig.apiAddress + "/document/" + id;
// ResponseEntity<Object> exchange = null;
// try {
// exchange = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>("", headers), Object.class);
// } catch (Exception e) {
// throw new IOException();
// }
// return exchange != null && exchange.getStatusCode() == HttpStatus.ACCEPTED;
// }
//
// public List<FeedItem> getChangeset() {
// String url = serverConfig.apiAddress + "/changeset?since=7d";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = getHeaders();
// ParameterizedTypeReference<List<FeedItem>> typeRef = new ParameterizedTypeReference<List<FeedItem>>() {
// };
// ResponseEntity<List<FeedItem>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>("", headers), typeRef);
// return response.getBody();
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Provides.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Provides {
//
// public String description;
// public String service_name;
// public String protocol;
// public String port;
// public String transport_protocol;
// public List<String> public_dns = new ArrayList<>();
// }
// Path: src/main/java/io/pivio/view/app/overview/detail/ServiceListGenerator.java
import io.pivio.view.PivioServerConnector;
import io.pivio.view.app.overview.detail.serverresponse.Provides;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
package io.pivio.view.app.overview.detail;
/**
* Produces a map with serviceId as key and service_names and short_name:port as values of
* all services known to the system.
*/
@Service
public class ServiceListGenerator {
@Autowired
PivioServerConnector pivioServerConnector;
Map<String, String> getServiceNameMap() {
List<ServiceIdShortName> allServices = pivioServerConnector.getAllServices();
Map<String, String> serviceNameMap = new HashMap<>();
for (ServiceIdShortName service : allServices) {
if (service.service != null) { | for (Provides provide : service.service.provides) { |
pivio/pivio-web | src/test/java/io/pivio/view/app/overview/detail/DocumentMapperTest.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import io.pivio.view.app.overview.detail.serverresponse.Document;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat; | package io.pivio.view.app.overview.detail;
public class DocumentMapperTest {
@Test
public void testMapDetail() throws IOException {
ObjectMapper mapper = new ObjectMapper();
| // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
// Path: src/test/java/io/pivio/view/app/overview/detail/DocumentMapperTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import io.pivio.view.app.overview.detail.serverresponse.Document;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
package io.pivio.view.app.overview.detail;
public class DocumentMapperTest {
@Test
public void testMapDetail() throws IOException {
ObjectMapper mapper = new ObjectMapper();
| Document document = mapper.readValue(new File("src/test/resources/detail.json"), Document.class); |
pivio/pivio-web | src/main/java/io/pivio/view/app/feed/FeedModel.java | // Path: src/main/java/io/pivio/view/app/feed/serverresponse/FeedItem.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class FeedItem {
//
// public String document;
// public int order;
// public Date timestamp;
// public List<Field> fields = new ArrayList<>();
//
// public FeedItem() {
// }
//
// public Map<String, List<Field>> getUniquePath() {
// Map<String, List<Field>> result = new HashMap<>();
// for (Field field : fields) {
// String uniquePath = field.path.split("/")[1];
// if (!result.containsKey(uniquePath)) {
// result.put(uniquePath, new ArrayList<>());
// }
// result.get(uniquePath).add(field);
// }
// return result;
// }
//
// }
| import io.pivio.view.app.feed.serverresponse.FeedItem;
import org.joda.time.DateTime;
import org.ocpsoft.prettytime.PrettyTime; | package io.pivio.view.app.feed;
public class FeedModel {
public String short_name; | // Path: src/main/java/io/pivio/view/app/feed/serverresponse/FeedItem.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class FeedItem {
//
// public String document;
// public int order;
// public Date timestamp;
// public List<Field> fields = new ArrayList<>();
//
// public FeedItem() {
// }
//
// public Map<String, List<Field>> getUniquePath() {
// Map<String, List<Field>> result = new HashMap<>();
// for (Field field : fields) {
// String uniquePath = field.path.split("/")[1];
// if (!result.containsKey(uniquePath)) {
// result.put(uniquePath, new ArrayList<>());
// }
// result.get(uniquePath).add(field);
// }
// return result;
// }
//
// }
// Path: src/main/java/io/pivio/view/app/feed/FeedModel.java
import io.pivio.view.app.feed.serverresponse.FeedItem;
import org.joda.time.DateTime;
import org.ocpsoft.prettytime.PrettyTime;
package io.pivio.view.app.feed;
public class FeedModel {
public String short_name; | public FeedItem feedItem; |
pivio/pivio-web | src/main/java/io/pivio/view/app/query/QueryController.java | // Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
| import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; | package io.pivio.view.app.query;
@Controller
public class QueryController {
@Autowired | // Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/query/QueryController.java
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
package io.pivio.view.app.query;
@Controller
public class QueryController {
@Autowired | ServerConfig serverConfig; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/list/ListController.java | // Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
| import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; | package io.pivio.view.app.overview.list;
@Controller
public class ListController {
@Autowired | // Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/list/ListController.java
import io.pivio.view.configuration.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
package io.pivio.view.app.overview.list;
@Controller
public class ListController {
@Autowired | ServerConfig serverConfig; |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/list/ModelMapper.java | // Path: src/main/java/io/pivio/view/app/overview/list/serverresponse/Overview.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Overview implements Comparable {
//
// public String name;
// public String short_name;
// public String description;
// public String lastUpload;
// public String lastUpdate;
// public Context context;
// public String id;
// public String owner;
// public String type;
//
// @Override
// public int compareTo(Object o) {
// return this.name.compareTo(((Overview) o).name);
// }
// }
| import io.pivio.view.app.overview.list.serverresponse.Overview;
import org.springframework.stereotype.Service; | package io.pivio.view.app.overview.list;
@Service
public class ModelMapper {
| // Path: src/main/java/io/pivio/view/app/overview/list/serverresponse/Overview.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Overview implements Comparable {
//
// public String name;
// public String short_name;
// public String description;
// public String lastUpload;
// public String lastUpdate;
// public Context context;
// public String id;
// public String owner;
// public String type;
//
// @Override
// public int compareTo(Object o) {
// return this.name.compareTo(((Overview) o).name);
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/list/ModelMapper.java
import io.pivio.view.app.overview.list.serverresponse.Overview;
import org.springframework.stereotype.Service;
package io.pivio.view.app.overview.list;
@Service
public class ModelMapper {
| public OverviewModel map(Overview overview) { |
pivio/pivio-web | src/main/java/io/pivio/view/app/overview/list/serverresponse/Overview.java | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Context.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Context {
//
// public String belongs_to_bounded_context;
// public String visibility;
//
// @Override
// public String toString() {
// return "Context{" +
// "belongs_to_bounded_context='" + belongs_to_bounded_context + '\'' +
// ", visibility='" + visibility + '\'' +
// '}';
// }
// }
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.pivio.view.app.overview.detail.serverresponse.Context; | package io.pivio.view.app.overview.list.serverresponse;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Overview implements Comparable {
public String name;
public String short_name;
public String description;
public String lastUpload;
public String lastUpdate; | // Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Context.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Context {
//
// public String belongs_to_bounded_context;
// public String visibility;
//
// @Override
// public String toString() {
// return "Context{" +
// "belongs_to_bounded_context='" + belongs_to_bounded_context + '\'' +
// ", visibility='" + visibility + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/app/overview/list/serverresponse/Overview.java
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.pivio.view.app.overview.detail.serverresponse.Context;
package io.pivio.view.app.overview.list.serverresponse;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Overview implements Comparable {
public String name;
public String short_name;
public String description;
public String lastUpload;
public String lastUpdate; | public Context context; |
pivio/pivio-web | src/main/java/io/pivio/view/PivioServerConnector.java | // Path: src/main/java/io/pivio/view/app/feed/serverresponse/FeedItem.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class FeedItem {
//
// public String document;
// public int order;
// public Date timestamp;
// public List<Field> fields = new ArrayList<>();
//
// public FeedItem() {
// }
//
// public Map<String, List<Field>> getUniquePath() {
// Map<String, List<Field>> result = new HashMap<>();
// for (Field field : fields) {
// String uniquePath = field.path.split("/")[1];
// if (!result.containsKey(uniquePath)) {
// result.put(uniquePath, new ArrayList<>());
// }
// result.get(uniquePath).add(field);
// }
// return result;
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/list/serverresponse/Overview.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Overview implements Comparable {
//
// public String name;
// public String short_name;
// public String description;
// public String lastUpload;
// public String lastUpdate;
// public Context context;
// public String id;
// public String owner;
// public String type;
//
// @Override
// public int compareTo(Object o) {
// return this.name.compareTo(((Overview) o).name);
// }
// }
//
// Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
| import io.pivio.view.app.feed.serverresponse.FeedItem;
import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.list.serverresponse.Overview;
import io.pivio.view.configuration.ServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import static java.util.Collections.sort; | package io.pivio.view;
@Component
public class PivioServerConnector {
private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
@Autowired | // Path: src/main/java/io/pivio/view/app/feed/serverresponse/FeedItem.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class FeedItem {
//
// public String document;
// public int order;
// public Date timestamp;
// public List<Field> fields = new ArrayList<>();
//
// public FeedItem() {
// }
//
// public Map<String, List<Field>> getUniquePath() {
// Map<String, List<Field>> result = new HashMap<>();
// for (Field field : fields) {
// String uniquePath = field.path.split("/")[1];
// if (!result.containsKey(uniquePath)) {
// result.put(uniquePath, new ArrayList<>());
// }
// result.get(uniquePath).add(field);
// }
// return result;
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/ServiceIdShortName.java
// public class ServiceIdShortName {
//
// public Service service;
// public String id;
// public String short_name;
//
// public ServiceIdShortName() {
// }
//
// public ServiceIdShortName(Service service, String id, String short_name) {
// this.service = service;
// this.id = id;
// this.short_name = short_name;
// }
//
// public boolean hasDependencies() {
// return service != null && service.depends_on != null;
// }
//
// @Override
// public String toString() {
// return "ServiceIdShortName{" +
// "service=" + service +
// ", id='" + id + '\'' +
// ", short_name='" + short_name + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/io/pivio/view/app/overview/detail/serverresponse/Document.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Document {
//
// public String owner;
// public String data_format_version;
// public String description;
// public String type;
// public String vcsroot;
// public String name;
// public String short_name;
// public String id;
// public String contact;
// public String created;
// public String lastUpload;
// public String lastUpdate;
// public String status;
// public String product_context;
// public List<String> tags = new ArrayList<>();
// public Map<String, String> links = new HashMap<>();
//
// public Runtime runtime = new Runtime();
// public List<SoftwareDependency> software_dependencies = new ArrayList<>();
// public Service service = new Service();
// public Context context = new Context();
//
// @Override
// public String toString() {
// return "Document{" +
// "owner='" + owner + '\'' +
// ", data_format_version='" + data_format_version + '\'' +
// ", description='" + description + '\'' +
// ", type='" + type + '\'' +
// ", vcsroot='" + vcsroot + '\'' +
// ", name='" + name + '\'' +
// ", short_name='" + short_name + '\'' +
// ", id='" + id + '\'' +
// ", contact='" + contact + '\'' +
// ", created='" + created + '\'' +
// ", lastUpload='" + lastUpload + '\'' +
// ", lastUpdate='" + lastUpdate + '\'' +
// ", status='" + status + '\'' +
// ", product_context='" + product_context + '\'' +
// ", tags=" + tags +
// ", links=" + links +
// ", runtime=" + runtime +
// ", software_dependencies=" + software_dependencies +
// ", service=" + service +
// ", context=" + context +
// '}';
// }
//
// public boolean ofTypeService() {
// return type.equalsIgnoreCase("service");
// }
//
// }
//
// Path: src/main/java/io/pivio/view/app/overview/list/serverresponse/Overview.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Overview implements Comparable {
//
// public String name;
// public String short_name;
// public String description;
// public String lastUpload;
// public String lastUpdate;
// public Context context;
// public String id;
// public String owner;
// public String type;
//
// @Override
// public int compareTo(Object o) {
// return this.name.compareTo(((Overview) o).name);
// }
// }
//
// Path: src/main/java/io/pivio/view/configuration/ServerConfig.java
// @Component
// public class ServerConfig {
// public List pages = new ArrayList<>(); // show nothing for default
// public String apiAddress = "http://localhost:9123"; // default
// public String mainUrl = "http://localhost:8080"; // needs to be determined later to match the host with the 'main' app.
// public String jsApiAddress = "http://localhost:9123/"; // If your webbrowser needs access to the API, the address is a different one.
//
// @Override
// public String toString() {
// return "ServerConfig{" +
// "pages=" + pages +
// ", apiAddress='" + apiAddress + '\'' +
// ", mainUrl='" + mainUrl + '\'' +
// ", jsApiAddress='" + jsApiAddress + '\'' +
// '}';
// }
// }
// Path: src/main/java/io/pivio/view/PivioServerConnector.java
import io.pivio.view.app.feed.serverresponse.FeedItem;
import io.pivio.view.app.overview.detail.ServiceIdShortName;
import io.pivio.view.app.overview.detail.serverresponse.Document;
import io.pivio.view.app.overview.list.serverresponse.Overview;
import io.pivio.view.configuration.ServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import static java.util.Collections.sort;
package io.pivio.view;
@Component
public class PivioServerConnector {
private final Logger log = LoggerFactory.getLogger(PivioServerConnector.class);
@Autowired | ServerConfig serverConfig; |
5waynewang/diamond | diamond-server/src/main/java/com/taobao/diamond/server/controller/AdminController.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.taobao.diamond.common.Constants;
import com.taobao.diamond.domain.ConfigInfo;
import com.taobao.diamond.domain.ConfigInfoEx;
import com.taobao.diamond.domain.Page;
import com.taobao.diamond.server.exception.ConfigServiceException;
import com.taobao.diamond.server.service.AdminService;
import com.taobao.diamond.server.service.ConfigService;
import com.taobao.diamond.server.utils.DiamondUtils;
import com.taobao.diamond.server.utils.GlobalCounter;
import com.taobao.diamond.utils.JSONUtils; | /*
* (C) 2007-2012 Alibaba Group Holding Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* Authors:
* leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
*/
package com.taobao.diamond.server.controller;
/**
* 管理控制器
*
* @author boyan
* @date 2010-5-6
*/
@Controller
@RequestMapping("/admin")
public class AdminController {
private static final Log log = LogFactory.getLog(AdminController.class);
@Autowired
private AdminService adminService;
@Autowired
private ConfigService configService;
@RequestMapping(params = "method=postConfig", method = RequestMethod.POST)
public String postConfig(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam("content") String content, ModelMap modelMap) { | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-server/src/main/java/com/taobao/diamond/server/controller/AdminController.java
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.taobao.diamond.common.Constants;
import com.taobao.diamond.domain.ConfigInfo;
import com.taobao.diamond.domain.ConfigInfoEx;
import com.taobao.diamond.domain.Page;
import com.taobao.diamond.server.exception.ConfigServiceException;
import com.taobao.diamond.server.service.AdminService;
import com.taobao.diamond.server.service.ConfigService;
import com.taobao.diamond.server.utils.DiamondUtils;
import com.taobao.diamond.server.utils.GlobalCounter;
import com.taobao.diamond.utils.JSONUtils;
/*
* (C) 2007-2012 Alibaba Group Holding Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* Authors:
* leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
*/
package com.taobao.diamond.server.controller;
/**
* 管理控制器
*
* @author boyan
* @date 2010-5-6
*/
@Controller
@RequestMapping("/admin")
public class AdminController {
private static final Log log = LogFactory.getLog(AdminController.class);
@Autowired
private AdminService adminService;
@Autowired
private ConfigService configService;
@RequestMapping(params = "method=postConfig", method = RequestMethod.POST)
public String postConfig(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam("content") String content, ModelMap modelMap) { | response.setCharacterEncoding(Constants.ENCODE); |
5waynewang/diamond | diamond-server/src/main/java/com/taobao/diamond/server/interceptor/PreparedRequestInterceptor.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.taobao.diamond.common.Constants;
| package com.taobao.diamond.server.interceptor;
/**
* <pre>
*
* </pre>
*
* @author Wayne.Wang<5waynewang@gmail.com>
* @since 10:08:12 AM Jun 22, 2016
*/
public class PreparedRequestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-server/src/main/java/com/taobao/diamond/server/interceptor/PreparedRequestInterceptor.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.taobao.diamond.common.Constants;
package com.taobao.diamond.server.interceptor;
/**
* <pre>
*
* </pre>
*
* @author Wayne.Wang<5waynewang@gmail.com>
* @since 10:08:12 AM Jun 22, 2016
*/
public class PreparedRequestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
| final String opaque = request.getHeader(Constants.OPAQUE);
|
5waynewang/diamond | diamond-utils/src/main/java/com/taobao/diamond/utils/SimpleCache.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.taobao.diamond.common.Constants;
| /*
* (C) 2007-2012 Alibaba Group Holding Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* Authors:
* leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
*/
package com.taobao.diamond.utils;
/**
* 一个带TTL的简单Cache,对于过期的entry没有清理
*
* @author fenghan
*
* @param <E>
*/
public class SimpleCache<E> {
private ConcurrentMap<String, CacheEntry<E>> cache;
private long cacheTTL;
private static class CacheEntry<E> {
public final long timestamp;
public final E value;
public CacheEntry(E value, long timestamp) {
this.timestamp = timestamp;
this.value = value;
}
}
public SimpleCache() {
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-utils/src/main/java/com/taobao/diamond/utils/SimpleCache.java
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.taobao.diamond.common.Constants;
/*
* (C) 2007-2012 Alibaba Group Holding Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* Authors:
* leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
*/
package com.taobao.diamond.utils;
/**
* 一个带TTL的简单Cache,对于过期的entry没有清理
*
* @author fenghan
*
* @param <E>
*/
public class SimpleCache<E> {
private ConcurrentMap<String, CacheEntry<E>> cache;
private long cacheTTL;
private static class CacheEntry<E> {
public final long timestamp;
public final E value;
public CacheEntry(E value, long timestamp) {
this.timestamp = timestamp;
this.value = value;
}
}
public SimpleCache() {
| this(Constants.POLLING_INTERVAL_TIME * 1000L);
|
5waynewang/diamond | diamond-server/src/test/java/com/taobao/diamond/server/EmbeddedServer.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.io.File;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.naming.resources.VirtualDirContext;
import com.taobao.diamond.common.Constants;
| package com.taobao.diamond.server;
public class EmbeddedServer {
public static void main(String[] args) throws Exception {
System.setProperty("profiles.active", "dev");
Tomcat tomcat = new Tomcat();
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-server/src/test/java/com/taobao/diamond/server/EmbeddedServer.java
import java.io.File;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.naming.resources.VirtualDirContext;
import com.taobao.diamond.common.Constants;
package com.taobao.diamond.server;
public class EmbeddedServer {
public static void main(String[] args) throws Exception {
System.setProperty("profiles.active", "dev");
Tomcat tomcat = new Tomcat();
| tomcat.setPort(Constants.DEFAULT_PORT);
|
5waynewang/diamond | diamond-client/src/main/java/com/taobao/diamond/client/processor/SnapshotConfigInfoProcessor.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.apache.commons.lang3.StringUtils;
import com.taobao.diamond.common.Constants; | file.mkdir();
}
}
public String getConfigInfomation(String dataId, String group) throws IOException {
if (StringUtils.isBlank(dataId)) {
return null;
}
if (StringUtils.isBlank(group)) {
return null;
}
String path = dir + File.separator + group;
final File dir = new File(path);
if (!dir.exists()) {
return null;
}
String filePath = path + File.separator + dataId;
final File file = new File(filePath);
if (!file.exists()) {
return null;
}
FileInputStream in = null;
StringBuilder sb = new StringBuilder(512);
try {
in = new FileInputStream(file);
byte[] data = new byte[8192];
int n = -1;
while ((n = in.read(data)) != -1) { | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-client/src/main/java/com/taobao/diamond/client/processor/SnapshotConfigInfoProcessor.java
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.apache.commons.lang3.StringUtils;
import com.taobao.diamond.common.Constants;
file.mkdir();
}
}
public String getConfigInfomation(String dataId, String group) throws IOException {
if (StringUtils.isBlank(dataId)) {
return null;
}
if (StringUtils.isBlank(group)) {
return null;
}
String path = dir + File.separator + group;
final File dir = new File(path);
if (!dir.exists()) {
return null;
}
String filePath = path + File.separator + dataId;
final File file = new File(filePath);
if (!file.exists()) {
return null;
}
FileInputStream in = null;
StringBuilder sb = new StringBuilder(512);
try {
in = new FileInputStream(file);
byte[] data = new byte[8192];
int n = -1;
while ((n = in.read(data)) != -1) { | sb.append(new String(data, 0, n, Constants.ENCODE)); |
5waynewang/diamond | diamond-utils/src/main/java/com/taobao/diamond/httpclient/HttpInvokeResult.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.nio.charset.Charset;
import org.apache.commons.lang3.StringUtils;
import com.taobao.diamond.common.Constants;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
| package com.taobao.diamond.httpclient;
/**
* @author Wayne.Wang<5waynewang@gmail.com>
* @since 8:05:22 PM Jul 28, 2014
*/
public class HttpInvokeResult {
private String remoteAddress;
private String requestURI;
private String requestMethod;
private String reason;
private volatile Throwable cause;
private volatile HttpHeaders headers;
private volatile HttpResponseStatus status;
private volatile ByteBuf content;
public int getStatusCode() {
return status == null ? 0 : status.code();
}
public byte[] getResponseBody() {
if (content == null) {
return null;
}
return content.array();
}
/**
* <pre>
* convert response bytes to String
* </pre>
*
* @return
*/
public String getResponseBodyAsString() {
if (content == null) {
return null;
}
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-utils/src/main/java/com/taobao/diamond/httpclient/HttpInvokeResult.java
import java.nio.charset.Charset;
import org.apache.commons.lang3.StringUtils;
import com.taobao.diamond.common.Constants;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
package com.taobao.diamond.httpclient;
/**
* @author Wayne.Wang<5waynewang@gmail.com>
* @since 8:05:22 PM Jul 28, 2014
*/
public class HttpInvokeResult {
private String remoteAddress;
private String requestURI;
private String requestMethod;
private String reason;
private volatile Throwable cause;
private volatile HttpHeaders headers;
private volatile HttpResponseStatus status;
private volatile ByteBuf content;
public int getStatusCode() {
return status == null ? 0 : status.code();
}
public byte[] getResponseBody() {
if (content == null) {
return null;
}
return content.array();
}
/**
* <pre>
* convert response bytes to String
* </pre>
*
* @return
*/
public String getResponseBodyAsString() {
if (content == null) {
return null;
}
| return content.toString(Charset.forName(Constants.ENCODE));
|
5waynewang/diamond | diamond-client/src/main/java/com/taobao/diamond/client/processor/LocalConfigInfoProcessor.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.taobao.diamond.common.Constants;
import com.taobao.diamond.configinfo.CacheData;
import com.taobao.diamond.io.FileSystem;
import com.taobao.diamond.io.Path;
import com.taobao.diamond.io.watch.StandardWatchEventKind;
import com.taobao.diamond.io.watch.WatchEvent;
import com.taobao.diamond.io.watch.WatchKey;
import com.taobao.diamond.io.watch.WatchService;
import com.taobao.diamond.utils.FileUtils;
| /*
* (C) 2007-2012 Alibaba Group Holding Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* Authors:
* leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
*/
package com.taobao.diamond.client.processor;
public class LocalConfigInfoProcessor {
private static final Log log = LogFactory.getLog(LocalConfigInfoProcessor.class);
private ScheduledExecutorService singleExecutor = Executors.newSingleThreadScheduledExecutor();;
private final Map<String/* filePath */, Long/* version */> existFiles = new HashMap<String, Long>();
private volatile boolean isRun;
private String rootPath = null;
/**
* 获取本地配置
*
* @param cacheData
* @param force
* 强制获取,在没有变更的时候不返回null
* @return
* @throws IOException
*/
public String getLocalConfigureInfomation(CacheData cacheData, boolean force) throws IOException {
String filePath = getFilePath(cacheData.getDataId(), cacheData.getGroup());
if (!existFiles.containsKey(filePath)) {
if (cacheData.isUseLocalConfigInfo()) {
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-client/src/main/java/com/taobao/diamond/client/processor/LocalConfigInfoProcessor.java
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.taobao.diamond.common.Constants;
import com.taobao.diamond.configinfo.CacheData;
import com.taobao.diamond.io.FileSystem;
import com.taobao.diamond.io.Path;
import com.taobao.diamond.io.watch.StandardWatchEventKind;
import com.taobao.diamond.io.watch.WatchEvent;
import com.taobao.diamond.io.watch.WatchKey;
import com.taobao.diamond.io.watch.WatchService;
import com.taobao.diamond.utils.FileUtils;
/*
* (C) 2007-2012 Alibaba Group Holding Limited.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* Authors:
* leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
*/
package com.taobao.diamond.client.processor;
public class LocalConfigInfoProcessor {
private static final Log log = LogFactory.getLog(LocalConfigInfoProcessor.class);
private ScheduledExecutorService singleExecutor = Executors.newSingleThreadScheduledExecutor();;
private final Map<String/* filePath */, Long/* version */> existFiles = new HashMap<String, Long>();
private volatile boolean isRun;
private String rootPath = null;
/**
* 获取本地配置
*
* @param cacheData
* @param force
* 强制获取,在没有变更的时候不返回null
* @return
* @throws IOException
*/
public String getLocalConfigureInfomation(CacheData cacheData, boolean force) throws IOException {
String filePath = getFilePath(cacheData.getDataId(), cacheData.getGroup());
if (!existFiles.containsKey(filePath)) {
if (cacheData.isUseLocalConfigInfo()) {
| cacheData.setLastModifiedHeader(Constants.NULL);
|
5waynewang/diamond | diamond-server/src/main/java/com/taobao/diamond/server/service/DiskService.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletContext;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.util.WebUtils;
import com.taobao.diamond.common.Constants;
import com.taobao.diamond.domain.ConfigInfo;
import com.taobao.diamond.server.exception.ConfigServiceException;
| package com.taobao.diamond.server.service;
/**
* 磁盘操作服务
*
* @author boyan
* @date 2010-5-4
*/
@Service
public class DiskService implements ServletContextAware {
private static final Log log = LogFactory.getLog(DiskService.class);
/**
* 修改标记缓存
*/
private final ConcurrentHashMap<String/* dataId + group */, Boolean/* 是否正在修改 */> modifyMarkCache =
new ConcurrentHashMap<String, Boolean>();
private ServletContext servletContext;
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
public ServletContext getServletContext() {
return this.servletContext;
}
/**
* 单元测试用
*
* @return
*/
public ConcurrentHashMap<String, Boolean> getModifyMarkCache() {
return this.modifyMarkCache;
}
/**
* 获取配置文件路径, 单元测试用
*
* @param dataId
* @param group
* @return
* @throws FileNotFoundException
*/
public String getFilePath(String dataId, String group) throws FileNotFoundException {
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-server/src/main/java/com/taobao/diamond/server/service/DiskService.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletContext;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.util.WebUtils;
import com.taobao.diamond.common.Constants;
import com.taobao.diamond.domain.ConfigInfo;
import com.taobao.diamond.server.exception.ConfigServiceException;
package com.taobao.diamond.server.service;
/**
* 磁盘操作服务
*
* @author boyan
* @date 2010-5-4
*/
@Service
public class DiskService implements ServletContextAware {
private static final Log log = LogFactory.getLog(DiskService.class);
/**
* 修改标记缓存
*/
private final ConcurrentHashMap<String/* dataId + group */, Boolean/* 是否正在修改 */> modifyMarkCache =
new ConcurrentHashMap<String, Boolean>();
private ServletContext servletContext;
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
public ServletContext getServletContext() {
return this.servletContext;
}
/**
* 单元测试用
*
* @return
*/
public ConcurrentHashMap<String, Boolean> getModifyMarkCache() {
return this.modifyMarkCache;
}
/**
* 获取配置文件路径, 单元测试用
*
* @param dataId
* @param group
* @return
* @throws FileNotFoundException
*/
public String getFilePath(String dataId, String group) throws FileNotFoundException {
| return getFilePath(Constants.BASE_DIR + "/" + group + "/" + dataId);
|
5waynewang/diamond | diamond-utils/src/test/java/com/taobao/diamond/httpclient/HttpClientTest.java | // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
| import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.taobao.diamond.common.Constants;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
| /**
*
*/
package com.taobao.diamond.httpclient;
/**
* <pre>
*
* </pre>
*
* @author Wayne.Wang<5waynewang@gmail.com>
* @since 4:36:56 PM Jun 20, 2016
*/
public class HttpClientTest {
HttpClient httpClient;
@Before
public void before() {
this.httpClient = new HttpClient();
this.httpClient.start();
}
@After
public void after() {
this.httpClient.shutdown();
}
@Test
public void testInvoke() throws Exception {
final String host = "config.ixiaopu.com";
final int port = 54321;
// Prepare the HTTP request.
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
"/config.co?group=XIANGQU&dataId=GLOBAL");
request.headers().set(HttpHeaders.Names.HOST, host);
request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
final HttpInvokeResult result = this.httpClient.invokeSync(host + ":" + port, request, 5000);
System.out.println(result);
}
@Test
public void testPost() throws Exception {
final String host = "config.ixiaopu.com";
final int port = 54321;
Collection<Pair<String, ?>> parameters = new ArrayList<Pair<String, ?>>();
| // Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
//
// public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//
// public static final String BASE_DIR = "config-data";
//
// public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
//
// public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
//
// public static final int DEFAULT_PORT = 54321;
//
// public static final String NULL = "";
//
// public static final String DATAID = "dataId";
//
// public static final String GROUP = "group";
//
// public static final String LAST_MODIFIED = "Last-Modified";
//
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
//
// public static final String CONTENT_ENCODING = "Content-Encoding";
//
// public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
//
// public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
//
// public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
//
// public static final String CONTENT_MD5 = "Content-MD5";
//
// public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
//
// public static final String SPACING_INTERVAL = "client-spacing-interval";
//
// public static final String OPAQUE = "opaque";
//
// public static final int POLLING_INTERVAL_TIME = 15;// 秒
//
// public static final int ONCE_TIMEOUT = 5000;// 毫秒
//
// public static final int CONN_TIMEOUT = 5000;// 毫秒
//
// public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//
// public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//
// public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
//
// public static final String HTTP_URI_FILE = "/config.co";
//
// public static final String HTTP_PROTOCOL_PREFIX = "http://";
//
// public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
//
// public static final String ENCODE = "UTF-8";
//
// public static final String LINE_SEPARATOR = Character.toString((char) 1);
//
// public static final String WORD_SEPARATOR = Character.toString((char) 2);
//
// public static final int SC_OK = 200;
// public static final int SC_REQUEST_TIMEOUT = 408;
//
// /*
// * 批量操作时, 单条数据的状态码
// */
// // 发生异常
// public static final int BATCH_OP_ERROR = -1;
// // 查询成功, 数据存在
// public static final int BATCH_QUERY_EXISTS = 1;
// // 查询成功, 数据不存在
// public static final int BATCH_QUERY_NONEXISTS = 2;
// // 新增成功
// public static final int BATCH_ADD_SUCCESS = 3;
// // 更新成功
// public static final int BATCH_UPDATE_SUCCESS = 4;
//
// }
// Path: diamond-utils/src/test/java/com/taobao/diamond/httpclient/HttpClientTest.java
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.taobao.diamond.common.Constants;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
/**
*
*/
package com.taobao.diamond.httpclient;
/**
* <pre>
*
* </pre>
*
* @author Wayne.Wang<5waynewang@gmail.com>
* @since 4:36:56 PM Jun 20, 2016
*/
public class HttpClientTest {
HttpClient httpClient;
@Before
public void before() {
this.httpClient = new HttpClient();
this.httpClient.start();
}
@After
public void after() {
this.httpClient.shutdown();
}
@Test
public void testInvoke() throws Exception {
final String host = "config.ixiaopu.com";
final int port = 54321;
// Prepare the HTTP request.
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
"/config.co?group=XIANGQU&dataId=GLOBAL");
request.headers().set(HttpHeaders.Names.HOST, host);
request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
final HttpInvokeResult result = this.httpClient.invokeSync(host + ":" + port, request, 5000);
System.out.println(result);
}
@Test
public void testPost() throws Exception {
final String host = "config.ixiaopu.com";
final int port = 54321;
Collection<Pair<String, ?>> parameters = new ArrayList<Pair<String, ?>>();
| parameters.add(Pair.of(Constants.PROBE_MODIFY_REQUEST, "MEMCACHEDXIANGQU3e433623c8761a1903e2882afd52377c"));
|
Appendium/flatpack | flatpack/src/test/java/net/sf/flatpack/columninfile/DelimitedColumnNamesInFileTest.java | // Path: flatpack/src/main/java/net/sf/flatpack/DataSet.java
// public interface DataSet extends Record, RecordDataSet {
//
// /**
// * Goes to the top of the data set. This will put the pointer one record
// * before the first in the set. Next() will have to be called to get the
// * first record after this call.
// */
// void goTop();
//
// /**
// * Goes to the last record in the dataset
// */
// void goBottom();
//
// /**
// * Moves back to the previous record in the set return true if move was a
// * success, false if not
// *
// * @return boolean
// */
// boolean previous();
//
// /**
// * Removes a row from the dataset. Once the row is removed the pointer will
// * be sitting on the record previous to the deleted row.
// */
// void remove();
//
// /**
// * Returns the index the pointer is on for the array
// *
// * @return int
// */
// int getIndex();
//
// /**
// * Returns the total number of rows parsed in from the file
// *
// *
// * @return int - Row Count
// */
// int getRowCount();
//
// /**
// * Returns true or false as to whether or not the line number contains an
// * error. The import will skip the line if it contains an error and it will
// * not be processed
// *
// * @param lineNo -
// * int line number
// * @return boolean
// */
// boolean isAnError(int lineNo);
//
// /**
// * Orders the data by column(s) specified. This will reposition the cursor
// * to the top of the DataSet when executed. This is currently not supported
// * when specifying <RECORD> elements in the mapping. An exception will be
// * thrown if this situation occurs
// *
// * @param ob -
// * OrderBy object
// * @see net.sf.flatpack.ordering.OrderBy
// * @see net.sf.flatpack.ordering.OrderColumn
// */
// void orderRows(OrderBy ob);
//
// /**
// * Sets data in the DataSet to lowercase
// */
// void setLowerCase();
//
// /**
// * Sets data in the DataSet to uppercase
// */
// void setUpperCase();
//
// /**
// * Sets the absolute position of the record pointer
// *
// * @param localPointer -
// * int
// */
// void absolute(int localPointer);
//
// /**
// * Setting this to True will parse text as is and throw a
// * NumberFormatException. Setting to false, which is the default, will
// * remove any non numeric character from the field. The remaining numeric
// * chars's will be returned. If it is an empty string,or there are no
// * numeric chars, 0 will be returned for getInt() and getDouble()
// *
// * @param strictNumericParse
// * The strictNumericParse to set.
// */
// void setStrictNumericParse(boolean strictNumericParse);
//
// /**
// * Sets the properties from the pzconvert.properties file.
// * This file specifies the PZConverter implementation to use
// * for a particular class
// *
// * @param props
// * Property mapping for String to Object conversion
// */
// void setPZConvertProps(Properties props);
//
// /**
// * Changes the value of the given column only for the
// * given row which the pointer is currently sitting on.
// *
// * @param column
// * Column name to set the value for
// * @param value
// * Value to change the column to
// */
// void setValue(String column, String value);
//
// /**
// * Clears out the rows in memory from the last parse.
// *
// */
// void clearRows();
//
// /**
// * Clears out the parse errors from memory
// *
// */
// void clearErrors();
//
// /**
// * Clears both the errors and rows from memory
// *
// */
// void clearAll();
// }
| import junit.framework.TestCase;
import net.sf.flatpack.DataSet;
| /*
* Created on Feb 26, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.sf.flatpack.columninfile;
/**
* @author zepernick
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class DelimitedColumnNamesInFileTest extends TestCase {
public DelimitedColumnNamesInFileTest(final String name) {
super(name);
}
// tests to make sure we have 0 errors
public void testErrorCount() {
| // Path: flatpack/src/main/java/net/sf/flatpack/DataSet.java
// public interface DataSet extends Record, RecordDataSet {
//
// /**
// * Goes to the top of the data set. This will put the pointer one record
// * before the first in the set. Next() will have to be called to get the
// * first record after this call.
// */
// void goTop();
//
// /**
// * Goes to the last record in the dataset
// */
// void goBottom();
//
// /**
// * Moves back to the previous record in the set return true if move was a
// * success, false if not
// *
// * @return boolean
// */
// boolean previous();
//
// /**
// * Removes a row from the dataset. Once the row is removed the pointer will
// * be sitting on the record previous to the deleted row.
// */
// void remove();
//
// /**
// * Returns the index the pointer is on for the array
// *
// * @return int
// */
// int getIndex();
//
// /**
// * Returns the total number of rows parsed in from the file
// *
// *
// * @return int - Row Count
// */
// int getRowCount();
//
// /**
// * Returns true or false as to whether or not the line number contains an
// * error. The import will skip the line if it contains an error and it will
// * not be processed
// *
// * @param lineNo -
// * int line number
// * @return boolean
// */
// boolean isAnError(int lineNo);
//
// /**
// * Orders the data by column(s) specified. This will reposition the cursor
// * to the top of the DataSet when executed. This is currently not supported
// * when specifying <RECORD> elements in the mapping. An exception will be
// * thrown if this situation occurs
// *
// * @param ob -
// * OrderBy object
// * @see net.sf.flatpack.ordering.OrderBy
// * @see net.sf.flatpack.ordering.OrderColumn
// */
// void orderRows(OrderBy ob);
//
// /**
// * Sets data in the DataSet to lowercase
// */
// void setLowerCase();
//
// /**
// * Sets data in the DataSet to uppercase
// */
// void setUpperCase();
//
// /**
// * Sets the absolute position of the record pointer
// *
// * @param localPointer -
// * int
// */
// void absolute(int localPointer);
//
// /**
// * Setting this to True will parse text as is and throw a
// * NumberFormatException. Setting to false, which is the default, will
// * remove any non numeric character from the field. The remaining numeric
// * chars's will be returned. If it is an empty string,or there are no
// * numeric chars, 0 will be returned for getInt() and getDouble()
// *
// * @param strictNumericParse
// * The strictNumericParse to set.
// */
// void setStrictNumericParse(boolean strictNumericParse);
//
// /**
// * Sets the properties from the pzconvert.properties file.
// * This file specifies the PZConverter implementation to use
// * for a particular class
// *
// * @param props
// * Property mapping for String to Object conversion
// */
// void setPZConvertProps(Properties props);
//
// /**
// * Changes the value of the given column only for the
// * given row which the pointer is currently sitting on.
// *
// * @param column
// * Column name to set the value for
// * @param value
// * Value to change the column to
// */
// void setValue(String column, String value);
//
// /**
// * Clears out the rows in memory from the last parse.
// *
// */
// void clearRows();
//
// /**
// * Clears out the parse errors from memory
// *
// */
// void clearErrors();
//
// /**
// * Clears both the errors and rows from memory
// *
// */
// void clearAll();
// }
// Path: flatpack/src/test/java/net/sf/flatpack/columninfile/DelimitedColumnNamesInFileTest.java
import junit.framework.TestCase;
import net.sf.flatpack.DataSet;
/*
* Created on Feb 26, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.sf.flatpack.columninfile;
/**
* @author zepernick
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class DelimitedColumnNamesInFileTest extends TestCase {
public DelimitedColumnNamesInFileTest(final String name) {
super(name);
}
// tests to make sure we have 0 errors
public void testErrorCount() {
| DataSet ds = null;
|
Appendium/flatpack | flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
| import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
import net.sf.flatpack.util.FPConstants; | package net.sf.flatpack.writer;
/**
*
* @author Dirk Holmes and Holger Holger Hoffstatte
* @since 4.0 public methods are more fluent
*/
public class DelimiterWriter extends AbstractWriter {
private final char delimiter;
private final char qualifier;
private final String replaceCarriageReturnWith;
private List<String> columnTitles = null;
private boolean columnTitlesWritten = false;
protected DelimiterWriter(final Map columnMapping, final java.io.Writer output, final char delimiter, final char qualifier,
final WriterOptions options) throws IOException {
super(output);
this.delimiter = delimiter;
this.qualifier = qualifier;
this.lineSeparator = options.getLineSeparator();
this.replaceCarriageReturnWith = options.getReplaceCarriageReturnWith();
columnTitles = new ArrayList<>(); | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
// Path: flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
import net.sf.flatpack.util.FPConstants;
package net.sf.flatpack.writer;
/**
*
* @author Dirk Holmes and Holger Holger Hoffstatte
* @since 4.0 public methods are more fluent
*/
public class DelimiterWriter extends AbstractWriter {
private final char delimiter;
private final char qualifier;
private final String replaceCarriageReturnWith;
private List<String> columnTitles = null;
private boolean columnTitlesWritten = false;
protected DelimiterWriter(final Map columnMapping, final java.io.Writer output, final char delimiter, final char qualifier,
final WriterOptions options) throws IOException {
super(output);
this.delimiter = delimiter;
this.qualifier = qualifier;
this.lineSeparator = options.getLineSeparator();
this.replaceCarriageReturnWith = options.getReplaceCarriageReturnWith();
columnTitles = new ArrayList<>(); | final List<ColumnMetaData> columns = (List<ColumnMetaData>) columnMapping.get(FPConstants.DETAIL_ID); |
Appendium/flatpack | flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
| import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
import net.sf.flatpack.util.FPConstants; | * @since 4.0
*/
public DelimiterWriterFactory addColumnTitles(final Collection<String> columnTitles) {
if (columnTitles != null) {
for (final String columnTitle : columnTitles) {
addColumnTitle(columnTitle);
}
}
return this;
}
/**
* Convenience method to add a series of cols in one go.
*
* @param columnTitles
* @return this
* @since 4.0
*/
public DelimiterWriterFactory addColumnTitles(final String... columnTitles) {
if (columnTitles != null) {
for (final String columnTitle : columnTitles) {
addColumnTitle(columnTitle);
}
}
return this;
}
// TODO DO: check that no column titles can be added after first nextRecord
public DelimiterWriterFactory addColumnTitle(final String columnTitle) {
final Map<String, Object> columnMapping = this.getColumnMapping(); | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
// Path: flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
import net.sf.flatpack.util.FPConstants;
* @since 4.0
*/
public DelimiterWriterFactory addColumnTitles(final Collection<String> columnTitles) {
if (columnTitles != null) {
for (final String columnTitle : columnTitles) {
addColumnTitle(columnTitle);
}
}
return this;
}
/**
* Convenience method to add a series of cols in one go.
*
* @param columnTitles
* @return this
* @since 4.0
*/
public DelimiterWriterFactory addColumnTitles(final String... columnTitles) {
if (columnTitles != null) {
for (final String columnTitle : columnTitles) {
addColumnTitle(columnTitle);
}
}
return this;
}
// TODO DO: check that no column titles can be added after first nextRecord
public DelimiterWriterFactory addColumnTitle(final String columnTitle) {
final Map<String, Object> columnMapping = this.getColumnMapping(); | final List<ColumnMetaData> columnMetaDatas = (List<ColumnMetaData>) columnMapping.get(FPConstants.DETAIL_ID); |
Appendium/flatpack | flatpack/src/main/java/net/sf/flatpack/util/FlatpackWriterUtil.java | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
| import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData; | /**
*
*/
package net.sf.flatpack.util;
/**
* Helper class to create ColumnMetaData and Mapping for the Writer Factory.
* @author Benoit Xhenseval
*/
public final class FlatpackWriterUtil {
private FlatpackWriterUtil() {
}
/**
* Creates a Mapping for a WriterFactory for the given list of columns.
* @param colsAsCsv comma-separated column names
* @return a map to be used in, for instance, DelimiterWriterFactory
*/
public static Map<String, Object> buildParametersForColumns(final String colsAsCsv) {
final Map<String, Object> mapping = new HashMap<>();
mapping.put(FPConstants.DETAIL_ID, buildColumns(colsAsCsv));
return mapping;
}
/**
* Create a new list of ColumnMetaData based on a CSV list of column titles.
* @param colsAsCsv
* @return new list
*/ | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
// Path: flatpack/src/main/java/net/sf/flatpack/util/FlatpackWriterUtil.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
/**
*
*/
package net.sf.flatpack.util;
/**
* Helper class to create ColumnMetaData and Mapping for the Writer Factory.
* @author Benoit Xhenseval
*/
public final class FlatpackWriterUtil {
private FlatpackWriterUtil() {
}
/**
* Creates a Mapping for a WriterFactory for the given list of columns.
* @param colsAsCsv comma-separated column names
* @return a map to be used in, for instance, DelimiterWriterFactory
*/
public static Map<String, Object> buildParametersForColumns(final String colsAsCsv) {
final Map<String, Object> mapping = new HashMap<>();
mapping.put(FPConstants.DETAIL_ID, buildColumns(colsAsCsv));
return mapping;
}
/**
* Create a new list of ColumnMetaData based on a CSV list of column titles.
* @param colsAsCsv
* @return new list
*/ | public static List<ColumnMetaData> buildColumns(final String colsAsCsv) { |
Appendium/flatpack | flatpack/src/main/java/net/sf/flatpack/CsvParserFactory.java | // Path: flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderParseFactory.java
// public class BuffReaderParseFactory implements ParserFactory {
// private static final BuffReaderParseFactory INSTANCE = new BuffReaderParseFactory();
//
// public static ParserFactory getInstance() {
// return INSTANCE;
// }
//
// /**
// * Not supported at this time.
// */
// @Override
// public Parser newFixedLengthParser(final Connection con, final File dataSource, final String dataDefinition) {
// throw new UnsupportedOperationException("Not supported...");
// }
//
// /**
// * Not supported at this time.
// */
// @Override
// public Parser newFixedLengthParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition) {
// throw new UnsupportedOperationException("Not supported...");
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.File,
// * java.io.File)
// */
// @Override
// public Parser newFixedLengthParser(final File pzmapXML, final File dataSource) {
// return new BuffReaderFixedParser(pzmapXML, dataSource);
// }
//
// @Override
// public Parser newFixedLengthParser(final Connection con, final Reader dataSource, final String dataDefinition) {
// return new DBBuffReaderFixedParser(con, dataSource, dataDefinition);
// }
//
// @Override
// public Parser newFixedLengthParser(final Reader pzmapXMLStream, final Reader dataSource) {
// return new BuffReaderFixedParser(pzmapXMLStream, dataSource);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.InputStream,
// * java.io.InputStream)
// */
// @Override
// public Parser newFixedLengthParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream) {
// return new BuffReaderFixedParser(pzmapXMLStream, dataSourceStream);
// }
//
// @Override
// public Parser newDelimitedParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final char delimiter,
// final char qualifier, final boolean ignoreFirstRecord) {
// throw new UnsupportedOperationException("Not supported. Use 'Reader' Constructor Instead Of InputStream.");
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.File,
// * java.io.File, char, char, boolean)
// */
// @Override
// public Parser newDelimitedParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier,
// final boolean ignoreFirstRecord) {
// return new BuffReaderDelimParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.InputStream,
// * java.io.InputStream, char, char, boolean)
// */
// @Override
// public Parser newDelimitedParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final char delimiter, final char qualifier,
// final boolean ignoreFirstRecord) {
// return new BuffReaderDelimParser(pzmapXMLStream, dataSourceStream, delimiter, qualifier, ignoreFirstRecord);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.File, char,
// * char)
// */
// @Override
// public Parser newDelimitedParser(final File dataSource, final char delimiter, final char qualifier) {
// return new BuffReaderDelimParser(dataSource, delimiter, qualifier, false);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.InputStream,
// * char, char)
// */
// @Override
// public Parser newDelimitedParser(final InputStream dataSourceStream, final char delimiter, final char qualifier) {
// return new BuffReaderDelimParser(dataSourceStream, delimiter, qualifier, false);
// }
//
// /**
// * Not supported at this time.
// */
// @Override
// public Parser newDelimitedParser(final Connection con, final Reader dataSource, final String dataDefinition, final char delimiter,
// final char qualifier, final boolean ignoreFirstRecord) {
// return new DBBuffReaderDelimParser(con, dataSource, dataDefinition, delimiter, qualifier, ignoreFirstRecord);
// }
//
// @Override
// public Parser newDelimitedParser(final Reader dataSource, final char delimiter, final char qualifier) {
// return new BuffReaderDelimParser(dataSource, delimiter, qualifier, false);
// }
//
// @Override
// public Parser newDelimitedParser(final Reader pzmapXML, final Reader dataSource, final char delimiter, final char qualifier,
// final boolean ignoreFirstRecord) {
// return new BuffReaderDelimParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord);
// }
// }
| import java.io.Reader;
import lombok.experimental.UtilityClass;
import net.sf.flatpack.brparse.BuffReaderParseFactory; | package net.sf.flatpack;
/**
* Easy way to get a CSV Parser (separator , and qualifier ").
*
*/
@UtilityClass
public final class CsvParserFactory {
/**
* This should be your default mechanism, it does not keep previous records as you stream the results, so
* it is more memory efficient but the downside is that you cannot reset the parsing or restart it. It reads
* a line, parses it and returns a Record or the next entry in the DataSet.
* @param reader the data source
* @return a CSV Parser
*/
public static Parser newForwardParser(Reader reader) { | // Path: flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderParseFactory.java
// public class BuffReaderParseFactory implements ParserFactory {
// private static final BuffReaderParseFactory INSTANCE = new BuffReaderParseFactory();
//
// public static ParserFactory getInstance() {
// return INSTANCE;
// }
//
// /**
// * Not supported at this time.
// */
// @Override
// public Parser newFixedLengthParser(final Connection con, final File dataSource, final String dataDefinition) {
// throw new UnsupportedOperationException("Not supported...");
// }
//
// /**
// * Not supported at this time.
// */
// @Override
// public Parser newFixedLengthParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition) {
// throw new UnsupportedOperationException("Not supported...");
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.File,
// * java.io.File)
// */
// @Override
// public Parser newFixedLengthParser(final File pzmapXML, final File dataSource) {
// return new BuffReaderFixedParser(pzmapXML, dataSource);
// }
//
// @Override
// public Parser newFixedLengthParser(final Connection con, final Reader dataSource, final String dataDefinition) {
// return new DBBuffReaderFixedParser(con, dataSource, dataDefinition);
// }
//
// @Override
// public Parser newFixedLengthParser(final Reader pzmapXMLStream, final Reader dataSource) {
// return new BuffReaderFixedParser(pzmapXMLStream, dataSource);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.InputStream,
// * java.io.InputStream)
// */
// @Override
// public Parser newFixedLengthParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream) {
// return new BuffReaderFixedParser(pzmapXMLStream, dataSourceStream);
// }
//
// @Override
// public Parser newDelimitedParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final char delimiter,
// final char qualifier, final boolean ignoreFirstRecord) {
// throw new UnsupportedOperationException("Not supported. Use 'Reader' Constructor Instead Of InputStream.");
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.File,
// * java.io.File, char, char, boolean)
// */
// @Override
// public Parser newDelimitedParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier,
// final boolean ignoreFirstRecord) {
// return new BuffReaderDelimParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.InputStream,
// * java.io.InputStream, char, char, boolean)
// */
// @Override
// public Parser newDelimitedParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final char delimiter, final char qualifier,
// final boolean ignoreFirstRecord) {
// return new BuffReaderDelimParser(pzmapXMLStream, dataSourceStream, delimiter, qualifier, ignoreFirstRecord);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.File, char,
// * char)
// */
// @Override
// public Parser newDelimitedParser(final File dataSource, final char delimiter, final char qualifier) {
// return new BuffReaderDelimParser(dataSource, delimiter, qualifier, false);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see net.sf.flatpack.PZParserFactory#newParser(java.io.InputStream,
// * char, char)
// */
// @Override
// public Parser newDelimitedParser(final InputStream dataSourceStream, final char delimiter, final char qualifier) {
// return new BuffReaderDelimParser(dataSourceStream, delimiter, qualifier, false);
// }
//
// /**
// * Not supported at this time.
// */
// @Override
// public Parser newDelimitedParser(final Connection con, final Reader dataSource, final String dataDefinition, final char delimiter,
// final char qualifier, final boolean ignoreFirstRecord) {
// return new DBBuffReaderDelimParser(con, dataSource, dataDefinition, delimiter, qualifier, ignoreFirstRecord);
// }
//
// @Override
// public Parser newDelimitedParser(final Reader dataSource, final char delimiter, final char qualifier) {
// return new BuffReaderDelimParser(dataSource, delimiter, qualifier, false);
// }
//
// @Override
// public Parser newDelimitedParser(final Reader pzmapXML, final Reader dataSource, final char delimiter, final char qualifier,
// final boolean ignoreFirstRecord) {
// return new BuffReaderDelimParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord);
// }
// }
// Path: flatpack/src/main/java/net/sf/flatpack/CsvParserFactory.java
import java.io.Reader;
import lombok.experimental.UtilityClass;
import net.sf.flatpack.brparse.BuffReaderParseFactory;
package net.sf.flatpack;
/**
* Easy way to get a CSV Parser (separator , and qualifier ").
*
*/
@UtilityClass
public final class CsvParserFactory {
/**
* This should be your default mechanism, it does not keep previous records as you stream the results, so
* it is more memory efficient but the downside is that you cannot reset the parsing or restart it. It reads
* a line, parses it and returns a Record or the next entry in the DataSet.
* @param reader the data source
* @return a CSV Parser
*/
public static Parser newForwardParser(Reader reader) { | return BuffReaderParseFactory.getInstance().newDelimitedParser(reader, ',', '"'); |
Appendium/flatpack | flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
| import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
import net.sf.flatpack.util.FPConstants; | package net.sf.flatpack.writer;
/**
*
* @author Dirk Holmes and Holger Holger Hoffstatte
*/
public class FixedLengthWriter extends AbstractWriter {
private static final int MAX_CHAR_TO_USE_LOOP = 8;
private final Map<?, ?> columnMapping;
private final char padChar;
protected FixedLengthWriter(final Map parsedMapping, final java.io.Writer output, final char padChar) {
super(output);
this.columnMapping = parsedMapping;
this.padChar = padChar;
}
@Override
public Writer addRecordEntry(final String columnName, final Object value) {
if (value != null) { | // Path: flatpack/src/main/java/net/sf/flatpack/structure/ColumnMetaData.java
// public class ColumnMetaData {
//
// /** Column Name */
// private String colName = null;
//
// /** column length */
// private int colLength = 0;
//
// /** starting position */
// private int startPosition = 0;
//
// /** ending position */
// private int endPosition = 0;
//
// public ColumnMetaData() {
// super();
// }
//
// /**
// * @param colName column name
// */
// public ColumnMetaData(final String colName) {
// super();
// this.colName = colName;
// }
//
// /**
// * Returns the colLength.
// *
// * @return int
// */
// public int getColLength() {
// return colLength;
// }
//
// /**
// * Returns the colName.
// *
// * @return String
// */
// public String getColName() {
// return colName;
// }
//
// /**
// * Returns the endPosition.
// *
// * @return int
// */
// public int getEndPosition() {
// return endPosition;
// }
//
// /**
// * Returns the startPosition.
// *
// * @return int
// */
// public int getStartPosition() {
// return startPosition;
// }
//
// /**
// * Sets the colLength.
// *
// * @param colLength
// * The colLength to set
// */
// public void setColLength(final int colLength) {
// this.colLength = colLength;
// }
//
// /**
// * Sets the colName.
// *
// * @param colName
// * The colName to set
// */
// public void setColName(final String colName) {
// this.colName = colName;
// }
//
// /**
// * Sets the endPosition.
// *
// * @param endPosition
// * The endPosition to set
// */
// public void setEndPosition(final int endPosition) {
// this.endPosition = endPosition;
// }
//
// /**
// * Sets the startPosition.
// *
// * @param startPosition
// * The startPosition to set
// */
// public void setStartPosition(final int startPosition) {
// this.startPosition = startPosition;
// }
//
// @Override
// public String toString() {
// final StringBuilder buf = new StringBuilder();
// buf.append("Name:").append(colName).append(" Length:").append(colLength).append(" Start:").append(startPosition);
// buf.append(" End:").append(endPosition).append(System.getProperty("line.separator"));
// return buf.toString();
// }
// }
// Path: flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.sf.flatpack.structure.ColumnMetaData;
import net.sf.flatpack.util.FPConstants;
package net.sf.flatpack.writer;
/**
*
* @author Dirk Holmes and Holger Holger Hoffstatte
*/
public class FixedLengthWriter extends AbstractWriter {
private static final int MAX_CHAR_TO_USE_LOOP = 8;
private final Map<?, ?> columnMapping;
private final char padChar;
protected FixedLengthWriter(final Map parsedMapping, final java.io.Writer output, final char padChar) {
super(output);
this.columnMapping = parsedMapping;
this.padChar = padChar;
}
@Override
public Writer addRecordEntry(final String columnName, final Object value) {
if (value != null) { | final ColumnMetaData metaData = this.getColumnMetaData(columnName); |
mayanhui/ella | src/main/java/com/adintellig/ella/dao/RegionDaoImpl.java | // Path: src/main/java/com/adintellig/ella/model/Region.java
// public class Region {
// private String regionName;
// private Timestamp updateTime = null;
//
// public String getRegionName() {
// return regionName;
// }
//
// public void setRegionName(String regionName) {
// this.regionName = regionName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((regionName == null) ? 0 : regionName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Region other = (Region) obj;
// if (regionName == null) {
// if (other.regionName != null)
// return false;
// } else if (!regionName.equals(other.regionName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Region;
import com.adintellig.ella.util.JdbcUtil; | package com.adintellig.ella.dao;
public class RegionDaoImpl {
private static Logger logger = LoggerFactory.getLogger(RegionDaoImpl.class);
static final String insertSQL = "INSERT INTO hbase.regions(region_name, update_time) "
+ "VALUES(?, ?)";
| // Path: src/main/java/com/adintellig/ella/model/Region.java
// public class Region {
// private String regionName;
// private Timestamp updateTime = null;
//
// public String getRegionName() {
// return regionName;
// }
//
// public void setRegionName(String regionName) {
// this.regionName = regionName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((regionName == null) ? 0 : regionName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Region other = (Region) obj;
// if (regionName == null) {
// if (other.regionName != null)
// return false;
// } else if (!regionName.equals(other.regionName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
// Path: src/main/java/com/adintellig/ella/dao/RegionDaoImpl.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Region;
import com.adintellig.ella.util.JdbcUtil;
package com.adintellig.ella.dao;
public class RegionDaoImpl {
private static Logger logger = LoggerFactory.getLogger(RegionDaoImpl.class);
static final String insertSQL = "INSERT INTO hbase.regions(region_name, update_time) "
+ "VALUES(?, ?)";
| public void batchUpdate(List<Region> beans) throws Exception { |
mayanhui/ella | src/main/java/com/adintellig/ella/dao/RegionDaoImpl.java | // Path: src/main/java/com/adintellig/ella/model/Region.java
// public class Region {
// private String regionName;
// private Timestamp updateTime = null;
//
// public String getRegionName() {
// return regionName;
// }
//
// public void setRegionName(String regionName) {
// this.regionName = regionName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((regionName == null) ? 0 : regionName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Region other = (Region) obj;
// if (regionName == null) {
// if (other.regionName != null)
// return false;
// } else if (!regionName.equals(other.regionName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Region;
import com.adintellig.ella.util.JdbcUtil; | package com.adintellig.ella.dao;
public class RegionDaoImpl {
private static Logger logger = LoggerFactory.getLogger(RegionDaoImpl.class);
static final String insertSQL = "INSERT INTO hbase.regions(region_name, update_time) "
+ "VALUES(?, ?)";
public void batchUpdate(List<Region> beans) throws Exception { | // Path: src/main/java/com/adintellig/ella/model/Region.java
// public class Region {
// private String regionName;
// private Timestamp updateTime = null;
//
// public String getRegionName() {
// return regionName;
// }
//
// public void setRegionName(String regionName) {
// this.regionName = regionName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((regionName == null) ? 0 : regionName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Region other = (Region) obj;
// if (regionName == null) {
// if (other.regionName != null)
// return false;
// } else if (!regionName.equals(other.regionName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
// Path: src/main/java/com/adintellig/ella/dao/RegionDaoImpl.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Region;
import com.adintellig.ella.util.JdbcUtil;
package com.adintellig.ella.dao;
public class RegionDaoImpl {
private static Logger logger = LoggerFactory.getLogger(RegionDaoImpl.class);
static final String insertSQL = "INSERT INTO hbase.regions(region_name, update_time) "
+ "VALUES(?, ?)";
public void batchUpdate(List<Region> beans) throws Exception { | Connection con = JdbcUtil.getConnection(); |
mayanhui/ella | src/main/java/com/adintellig/ella/dao/UserDaoImpl.java | // Path: src/main/java/com/adintellig/ella/model/user/User.java
// public class User {
//
// private String username;
// private String password;
// private Timestamp update_time;
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public Timestamp getUpdate_time() {
// return update_time;
// }
//
// public void setUpdate_time(Timestamp update_time) {
// this.update_time = update_time;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.user.User;
import com.adintellig.ella.util.JdbcUtil; | package com.adintellig.ella.dao;
public class UserDaoImpl {
private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
| // Path: src/main/java/com/adintellig/ella/model/user/User.java
// public class User {
//
// private String username;
// private String password;
// private Timestamp update_time;
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public Timestamp getUpdate_time() {
// return update_time;
// }
//
// public void setUpdate_time(Timestamp update_time) {
// this.update_time = update_time;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
// Path: src/main/java/com/adintellig/ella/dao/UserDaoImpl.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.user.User;
import com.adintellig.ella.util.JdbcUtil;
package com.adintellig.ella.dao;
public class UserDaoImpl {
private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
| public User findByNameAndPassword(String username, String password) |
mayanhui/ella | src/main/java/com/adintellig/ella/dao/UserDaoImpl.java | // Path: src/main/java/com/adintellig/ella/model/user/User.java
// public class User {
//
// private String username;
// private String password;
// private Timestamp update_time;
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public Timestamp getUpdate_time() {
// return update_time;
// }
//
// public void setUpdate_time(Timestamp update_time) {
// this.update_time = update_time;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.user.User;
import com.adintellig.ella.util.JdbcUtil; | package com.adintellig.ella.dao;
public class UserDaoImpl {
private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public User findByNameAndPassword(String username, String password)
throws SQLException {
String sql = "select * from hbase.user where username=? and password=?";
| // Path: src/main/java/com/adintellig/ella/model/user/User.java
// public class User {
//
// private String username;
// private String password;
// private Timestamp update_time;
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public Timestamp getUpdate_time() {
// return update_time;
// }
//
// public void setUpdate_time(Timestamp update_time) {
// this.update_time = update_time;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
// Path: src/main/java/com/adintellig/ella/dao/UserDaoImpl.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.user.User;
import com.adintellig.ella.util.JdbcUtil;
package com.adintellig.ella.dao;
public class UserDaoImpl {
private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public User findByNameAndPassword(String username, String password)
throws SQLException {
String sql = "select * from hbase.user where username=? and password=?";
| Connection conn = JdbcUtil.getConnection(); |
mayanhui/ella | src/main/java/com/adintellig/ella/dao/TableDaoImpl.java | // Path: src/main/java/com/adintellig/ella/model/Table.java
// public class Table {
// private String tableName;
// private Timestamp updateTime = null;
//
// public String getTableName() {
// return tableName;
// }
//
// public void setTableName(String tableName) {
// this.tableName = tableName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((tableName == null) ? 0 : tableName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Table other = (Table) obj;
// if (tableName == null) {
// if (other.tableName != null)
// return false;
// } else if (!tableName.equals(other.tableName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Table;
import com.adintellig.ella.util.JdbcUtil; | package com.adintellig.ella.dao;
public class TableDaoImpl {
private static Logger logger = LoggerFactory.getLogger(TableDaoImpl.class);
static final String insertTablesSQL = "INSERT INTO hbase.tables(table_name, update_time) "
+ "VALUES(?, ?)";
| // Path: src/main/java/com/adintellig/ella/model/Table.java
// public class Table {
// private String tableName;
// private Timestamp updateTime = null;
//
// public String getTableName() {
// return tableName;
// }
//
// public void setTableName(String tableName) {
// this.tableName = tableName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((tableName == null) ? 0 : tableName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Table other = (Table) obj;
// if (tableName == null) {
// if (other.tableName != null)
// return false;
// } else if (!tableName.equals(other.tableName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
// Path: src/main/java/com/adintellig/ella/dao/TableDaoImpl.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Table;
import com.adintellig.ella.util.JdbcUtil;
package com.adintellig.ella.dao;
public class TableDaoImpl {
private static Logger logger = LoggerFactory.getLogger(TableDaoImpl.class);
static final String insertTablesSQL = "INSERT INTO hbase.tables(table_name, update_time) "
+ "VALUES(?, ?)";
| public void batchUpdate(List<Table> beans) throws Exception { |
mayanhui/ella | src/main/java/com/adintellig/ella/dao/TableDaoImpl.java | // Path: src/main/java/com/adintellig/ella/model/Table.java
// public class Table {
// private String tableName;
// private Timestamp updateTime = null;
//
// public String getTableName() {
// return tableName;
// }
//
// public void setTableName(String tableName) {
// this.tableName = tableName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((tableName == null) ? 0 : tableName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Table other = (Table) obj;
// if (tableName == null) {
// if (other.tableName != null)
// return false;
// } else if (!tableName.equals(other.tableName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Table;
import com.adintellig.ella.util.JdbcUtil; | package com.adintellig.ella.dao;
public class TableDaoImpl {
private static Logger logger = LoggerFactory.getLogger(TableDaoImpl.class);
static final String insertTablesSQL = "INSERT INTO hbase.tables(table_name, update_time) "
+ "VALUES(?, ?)";
public void batchUpdate(List<Table> beans) throws Exception { | // Path: src/main/java/com/adintellig/ella/model/Table.java
// public class Table {
// private String tableName;
// private Timestamp updateTime = null;
//
// public String getTableName() {
// return tableName;
// }
//
// public void setTableName(String tableName) {
// this.tableName = tableName;
// }
//
// public Timestamp getUpdateTime() {
// return updateTime;
// }
//
// public void setUpdateTime(Timestamp updateTime) {
// this.updateTime = updateTime;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result
// + ((tableName == null) ? 0 : tableName.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Table other = (Table) obj;
// if (tableName == null) {
// if (other.tableName != null)
// return false;
// } else if (!tableName.equals(other.tableName))
// return false;
// return true;
// }
//
// }
//
// Path: src/main/java/com/adintellig/ella/util/JdbcUtil.java
// public class JdbcUtil {
//
// private static String db_driver;
// private static String db_url;
// private static String db_userName;
// private static String db_passWord;
//
// static {
// ConfigProperties config = ConfigFactory.getInstance()
// .getConfigProperties(ConfigFactory.ELLA_CONFIG_PATH);
// db_driver = config.getProperty("mysql.db.driver");
// db_url = config.getProperty("mysql.db.url");
// db_userName = config.getProperty("mysql.db.user");
// db_passWord = config.getProperty("mysql.db.pwd");
// }
//
// public static Connection getConnection() {
// Connection con = null;
// try {
// Class.forName(db_driver);
// } catch (ClassNotFoundException e) {
// System.out.println("3-ClassNotFoundException");
// e.printStackTrace();
// return null;
// }
// try {
// con = DriverManager.getConnection(db_url, db_userName, db_passWord);
// } catch (SQLException e) {
// System.out.println("4-SQLException");
// e.printStackTrace();
// return null;
// }
// return con;
// }
//
// public static void close(Connection con, Statement stmt, ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("5--SQLException");
// e.printStackTrace();
// }
// }
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// System.out.println("6-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("7-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con, PreparedStatement pstmt,
// ResultSet rs) {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e) {
// System.out.println("8-SQLException");
// e.printStackTrace();
// }
// }
// if (pstmt != null) {
// try {
// pstmt.close();
// } catch (SQLException e) {
// System.out.println("9-SQLException");
// e.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("10-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// public static void close(Connection con) {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// System.out.println("11-closeSQLException");
// e.printStackTrace();
// }
// }
// }
//
// }
// Path: src/main/java/com/adintellig/ella/dao/TableDaoImpl.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adintellig.ella.model.Table;
import com.adintellig.ella.util.JdbcUtil;
package com.adintellig.ella.dao;
public class TableDaoImpl {
private static Logger logger = LoggerFactory.getLogger(TableDaoImpl.class);
static final String insertTablesSQL = "INSERT INTO hbase.tables(table_name, update_time) "
+ "VALUES(?, ?)";
public void batchUpdate(List<Table> beans) throws Exception { | Connection con = JdbcUtil.getConnection(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.