Java Code Examples for org.eclipse.debug.core.ILaunchConfiguration#getAdapter()

The following examples show how to use org.eclipse.debug.core.ILaunchConfiguration#getAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TLCSpec.java    From tlaplus with MIT License 6 votes vote down vote up
public Map<String, Model> getModels(final String regexp, final boolean include) {
	final ILaunchConfiguration[] launchConfigurations = getAllLaunchConfigurations();
   	
	final Map<String, Model> res = new HashMap<String, Model>();

   	final IPath location = getProject().getLocation();
	for (int i = 0; i < launchConfigurations.length; i++) {
		final ILaunchConfiguration aConfiguration = launchConfigurations[i];
		if (location.isPrefixOf(aConfiguration.getFile().getLocation())) {
			final Model model = aConfiguration.getAdapter(Model.class);
			if (model.getName().matches(regexp) != include) {
				continue;
			}
			res.put(model.getName(), model);
		}
	}
   	
   	return res;
}
 
Example 2
Source File: TLCModelFactory.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * @see Model#getByName(String)
 */
public static Model getByName(final String fullQualifiedModelName) {
	Assert.isNotNull(fullQualifiedModelName);
	Assert.isLegal(fullQualifiedModelName.contains(Model.SPEC_MODEL_DELIM), "Not a full-qualified model name.");
	
       final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
       final ILaunchConfigurationType launchConfigurationType = launchManager
               .getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);

	try {
		final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType);
		for (int i = 0; i < launchConfigurations.length; i++) {
			// Can do equals here because of full qualified name.
			final ILaunchConfiguration launchConfiguration = launchConfigurations[i];
			if (fullQualifiedModelName.equals(launchConfiguration.getName())) {
				return launchConfiguration.getAdapter(Model.class);
			}
		}
	} catch (CoreException shouldNeverHappen) {
		shouldNeverHappen.printStackTrace();
	}
	
	return null;
}
 
Example 3
Source File: TLCModelFactory.java    From tlaplus with MIT License 6 votes vote down vote up
public static Model getBy(final IFile aFile) {
	Assert.isNotNull(aFile);
	
       final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
       final ILaunchConfigurationType launchConfigurationType = launchManager
               .getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);

	try {
		final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType);
		for (int i = 0; i < launchConfigurations.length; i++) {
			final ILaunchConfiguration launchConfiguration = launchConfigurations[i];
			if (aFile.equals(launchConfiguration.getFile())) {
				return launchConfiguration.getAdapter(Model.class);
			}
		}
	} catch (CoreException shouldNeverHappen) {
		shouldNeverHappen.printStackTrace();
	}
	
	return null;
}
 
Example 4
Source File: CloneForeignModelHandler.java    From tlaplus with MIT License 4 votes vote down vote up
private TreeMap<String, TreeSet<Model>> buildMap() {
       final Spec currentSpec = ToolboxHandle.getCurrentSpec();
       if (currentSpec == null) {
       	return null;
       }
       
	final IProject specProject = currentSpec.getProject();
	final TreeMap<String, TreeSet<Model>> projectModelMap = new TreeMap<>();
	
	try {
		final IWorkspace iws = ResourcesPlugin.getWorkspace();
		final IWorkspaceRoot root = iws.getRoot();
		final IProject[] projects = root.getProjects();
		
		for (final IProject project : projects) {
			if (!specProject.equals(project)) {
				projectModelMap.put(project.getName(), new TreeSet<>(MODEL_SORTER));
			}
		}
		
		final String currentProjectName = specProject.getName();
		final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
		final ILaunchConfigurationType launchConfigurationType
				= launchManager.getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);
		final ILaunchConfiguration[] launchConfigurations
				= launchManager.getLaunchConfigurations(launchConfigurationType);
		for (final ILaunchConfiguration launchConfiguration : launchConfigurations) {
			final String projectName = launchConfiguration.getAttribute(IConfigurationConstants.SPEC_NAME, "-l!D!q_-l!D!q_-l!D!q_");
			if (!projectName.equals(currentProjectName)) {
				final TreeSet<Model> models = projectModelMap.get(projectName);
				
				if (models != null) {
					final Model model = launchConfiguration.getAdapter(Model.class);
					
					if (!model.isSnapshot()) {
						models.add(model);
					}
				} else {
					TLCUIActivator.getDefault().logError("Could not generate model map for [" + projectName + "]!");
				}
			}
		}
	} catch (final CoreException e) {
		TLCUIActivator.getDefault().logError("Building foreign model map.", e);
		
		return null;
	}
	
	return projectModelMap;
}
 
Example 5
Source File: TLCModelLaunchDelegate.java    From tlaplus with MIT License 4 votes vote down vote up
/**
   * Launch the module parser on the root module and handle the errors
   *   
   * 
   * <br>4. method called on launch
   * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate2#finalLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
   */
  public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
          throws CoreException
  {
      monitor.beginTask("Verifying model files", 4);

      final Model model = configuration.getAdapter(Model.class);
      final IFile rootModule = model.getTLAFile();

      monitor.worked(1);
      // parse the MC file
      IParseResult parseResult = ToolboxHandle.parseModule(rootModule, SubMonitor.convert(monitor).split(1), false,
              false);
      final Vector<TLAMarkerInformationHolder> detectedErrors = parseResult.getDetectedErrors();
      boolean status = !AdapterFactory.isProblemStatus(parseResult.getStatus());

      monitor.worked(1);
      // remove existing markers
      
      model.removeMarkers(Model.TLC_MODEL_ERROR_MARKER_SANY);
      monitor.worked(1);

      if (!detectedErrors.isEmpty())
      {
          TLCActivator.logDebug("Errors in model file found " + rootModule.getLocation());
      }

final Map<TLAMarkerInformationHolder, Hashtable<String, Object>> props = sany2ToolboxErrors(monitor, rootModule,
		detectedErrors);
props.values().forEach(marker -> model.setMarker(marker, Model.TLC_MODEL_ERROR_MARKER_SANY));

      if (MODE_GENERATE.equals(mode))
      {
          // generation is done
          // nothing to do more
          return false;
      } else
      {
          return status;
      }
  }