/** Add the specified list any external resource for this EReference feature */ protected void processReferenceValue( final Resource eResource, final EObject eObject, final EReference eReference, final EObject value, final List externalResources, final Set unresolvedResourceURIs) { if (value == null) { return; } // Check if the object is an EMF proxy ... if (value.eIsProxy()) { if (value instanceof InternalEObject) { final InternalEObject iObject = (InternalEObject) value; final URI proxyUri = iObject.eProxyURI(); CoreArgCheck.isNotNull(proxyUri); // Get the URI of the resource ... URI resourceUri = proxyUri.trimFragment(); // Make the relative URI absolute if necessary URI baseLocationUri = eResource.getURI(); URI proxyLocationUri = UriHelper.makeAbsoluteUri(baseLocationUri, resourceUri); // URI proxyLocationUri = resourceUri; // if (baseLocationUri.isHierarchical() && !baseLocationUri.isRelative() && // proxyUri.isRelative()) { // proxyLocationUri = proxyLocationUri.resolve(baseLocationUri); // } Resource rsrc = findByURI(proxyLocationUri, true); // If the resource URI is a workspace relative path (e.g. "/project/.../model.xmi") if (rsrc == null && baseLocationUri.isFile() && resourceUri.toString().charAt(0) == '/') { String baseLocation = URI.decode(baseLocationUri.toFileString()); String projectName = resourceUri.segment(0); String proxyLocation = URI.decode(resourceUri.toString()); int index = baseLocation.indexOf(projectName); if (index != -1) { proxyLocation = baseLocation.substring(0, index - 1) + proxyLocation; rsrc = findByURI(URI.createFileURI(proxyLocation), true); } } if (rsrc != null && eResource != rsrc && !externalResources.contains(rsrc)) { externalResources.add(rsrc); } else if (rsrc == null) { unresolvedResourceURIs.add(resourceUri); } } } else { Resource rsrc = value.eResource(); if (eResource != rsrc && !externalResources.contains(rsrc)) { externalResources.add(rsrc); } } }
/** @generated */ private static File getFile(Resource resource) { URI resourceUri = resource.getURI(); if (resourceUri != null && resourceUri.isFile()) { File file = new File(resourceUri.toFileString()); if (!file.isDirectory()) { return file; } } return null; }
@Override public URI normalize(URI uri) { if (uri.isFile()) { return uri; } String[] segments = uri.segments(); String fileName = segments[0] + "_" + segments[1] + "." + getFileExtension(); // $NON-NLS-1$ //$NON-NLS-2$ String dir = getTemporaryDirectoryPath(); return URI.createFileURI(dir + File.separator + fileName); }
private String relative(String path) { path = substitute(path); URI sourceURI = source.eResource().getURI(); URI result = URI.createURI(path).resolve(sourceURI); if (result.isFile()) { return result.path(); } else if (result.isPlatformResource()) { return getFileFromProjectPath(result.toPlatformString(true)); } return ""; }
/* @NonNull */ @Override public Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri) { List<Pair<IStorage, IProject>> result = newArrayListWithCapacity(1); List<PackageFragmentRootData> packageFragmentRootDatas; synchronized (cachedPackageFragmentRootData) { packageFragmentRootDatas = newArrayList(cachedPackageFragmentRootData.values()); } Iterator<PackageFragmentRootData> iterator = packageFragmentRootDatas.iterator(); while (iterator.hasNext()) { PackageFragmentRootData data = iterator.next(); if (data.exists()) { if (data.uriPrefix == null || uri.toString().startsWith(data.uriPrefix.toString())) { IStorage storage = data.uri2Storage.get(uri); if (storage != null) { for (IPackageFragmentRoot root : data.associatedRoots.values()) { result.add(Tuples.create(storage, root.getJavaProject().getProject())); } } } } else { iterator.remove(); } } if (result.isEmpty() && uri.isArchive()) { String authority = uri.authority(); authority = authority.substring(0, authority.length() - 1); URI archiveURI = URI.createURI(authority); if (archiveURI.isFile() || archiveURI.isPlatformResource()) { IPath archivePath = new Path( archiveURI.isPlatformResource() ? archiveURI.toPlatformString(true) : archiveURI.toFileString()); for (PackageFragmentRootData data : packageFragmentRootDatas) { if (data.uriPrefix != null && archivePath.equals(data.getPath())) { // prefixes have an empty last segment. URI prefix = data.uriPrefix.lastSegment().length() == 0 ? data.uriPrefix.trimSegments(1) : data.uriPrefix; URI expectedURI = prefix.appendSegments(uri.segments()); IStorage storage = data.uri2Storage.get(expectedURI); if (storage != null) { for (IPackageFragmentRoot root : data.associatedRoots.values()) { result.add(Tuples.create(storage, root.getJavaProject().getProject())); } } } } } } return result; }
/** * @param uri * @return */ protected void refreshPath(URI uri) { try { if (uri.isFile()) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath path = Path.fromOSString(uri.toFileString()); IFile file = workspace.getRoot().getFileForLocation(path); file.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } } catch (Exception ex) { out("Error refreshing project path " + uri + ": " + ex); } }
/** * Checks whether the managed method library is read only. * * @return <code>true</code> if the method library is read only */ public boolean isMethodLibraryReadOnly() { if (debug) { DebugTrace.print(this, "isMethodLibraryReadOnly"); // $NON-NLS-1$ } URI libraryURI = library.eResource().getURI(); if (libraryURI.isFile()) { File libraryXMIFile = new File(libraryURI.toFileString()); return libraryXMIFile.exists() && !libraryXMIFile.canWrite(); } return false; }
public static String createBuildPathRelativeReference(URI sourceURI, URI targetURI) { if (sourceURI == null || targetURI == null) throw new IllegalArgumentException(); // BaseURI source = new BaseURI(sourceURI); // return source.getRelativeURI(targetURI); // TODO: this is probably bogus. if (targetURI.isFile()) { return targetURI.lastSegment(); } String result = targetURI.deresolve(sourceURI, true, true, true).toFileString(); // When absolute URLs return (result == null ? targetURI.toString() : result); }
/** @generated */ public StateMachine_MAVONewDiagramFileWizard( URI domainModelURI, EObject diagramRoot, TransactionalEditingDomain editingDomain) { assert domainModelURI != null : "Domain model uri must be specified"; // $NON-NLS-1$ assert diagramRoot != null : "Doagram root element must be specified"; // $NON-NLS-1$ assert editingDomain != null : "Editing domain must be specified"; // $NON-NLS-1$ myFileCreationPage = new WizardNewFileCreationPage( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_CreationPageName, StructuredSelection.EMPTY); myFileCreationPage.setTitle( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_CreationPageTitle); myFileCreationPage.setDescription( NLS.bind( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_CreationPageDescription, edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts.StateMachineEditPart .MODEL_ID)); IPath filePath; String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment()); if (domainModelURI.isPlatformResource()) { filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true)); } else if (domainModelURI.isFile()) { filePath = new Path(domainModelURI.trimSegments(1).toFileString()); } else { // TODO : use some default path throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); // $NON-NLS-1$ } myFileCreationPage.setContainerFullPath(filePath); myFileCreationPage.setFileName( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part .StateMachine_MAVODiagramEditorUtil.getUniqueFileName( filePath, fileName, "statemachinediag_mavo")); // $NON-NLS-1$ diagramRootElementSelectionPage = new DiagramRootElementSelectionPage( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageName); diagramRootElementSelectionPage.setTitle( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageTitle); diagramRootElementSelectionPage.setDescription( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageDescription); diagramRootElementSelectionPage.setModelElement(diagramRoot); myEditingDomain = editingDomain; }
public boolean loadResource(ModelSet modelSet, URI uri) { // pathmap resource are always loaded boolean result = !uri.isPlatform() && !uri.isFile(); if (!result) { URI lastInitialURI = SashModelUtils.getInitialURI(modelSet).trimFileExtension(); if (!lastInitialURI.equals(initialURI)) { clear(); initialURI = lastInitialURI; } URI uritrimFragment = uri.trimFragment().trimFileExtension(); Set<String> extensions = mappingURIExtensions.get(uritrimFragment); if (extensions == null) { extensions = new HashSet<String>(); mappingURIExtensions.put(uritrimFragment, extensions); } extensions.add(uri.fileExtension()); result = lastInitialURI.equals(uritrimFragment); if (!result) { result = alreadyValidated.contains(uritrimFragment); if (!result) { if (!alreadyGuessed.contains(uritrimFragment)) { String message = new StringBuffer("<form><p>Your model is linked to an external resource (") .append(uritrimFragment.toString()) .append(").</p><p>Do you want to load it ?</p></form>") .toString(); NotificationBuilder builder = getNotification(message, uritrimFragment, modelSet); builder.run(); alreadyGuessed.add(uritrimFragment); // notification } } } } return result; }
public static void dumpURI(URI uri, Logger logger) { logger.debug("URI: " + uri); logger.debug("authority: " + uri.authority()); logger.debug("device: " + uri.device()); logger.debug("devicePath: " + uri.devicePath()); logger.debug("fileExtension: " + uri.fileExtension()); logger.debug("fragment: " + uri.fragment()); logger.debug("host: " + uri.host()); logger.debug("lastSegment: " + uri.lastSegment()); logger.debug("opaquePart: " + uri.opaquePart()); logger.debug("path: " + uri.path()); logger.debug("port: " + uri.port()); logger.debug("query: " + uri.query()); logger.debug("scheme: " + uri.scheme()); logger.debug("segmentCount: " + uri.segmentCount()); logger.debug("toFileString: " + uri.toFileString()); logger.debug("userInfo: " + uri.userInfo()); logger.debug("hasAbsolutePath: " + uri.hasAbsolutePath()); logger.debug("schemehasAbsolutePath: " + uri.hasAbsolutePath()); logger.debug("hasAuthority: " + uri.hasAuthority()); logger.debug("hasDevice: " + uri.hasDevice()); logger.debug("hasEmptyPath: " + uri.hasEmptyPath()); logger.debug("hasFragment: " + uri.hasFragment()); logger.debug("hasOpaquePart: " + uri.hasOpaquePart()); logger.debug("hasPath: " + uri.hasPath()); logger.debug("hasQuery: " + uri.hasQuery()); logger.debug("hasRelativePath: " + uri.hasRelativePath()); logger.debug("hasTrailingPathSeparator: " + uri.hasTrailingPathSeparator()); logger.debug("isCurrentDocumentReference: " + uri.isCurrentDocumentReference()); logger.debug("isEmpty: " + uri.isEmpty()); logger.debug("isFile: " + uri.isFile()); logger.debug("isHierarchical: " + uri.isHierarchical()); logger.debug("isPrefix: " + uri.isPrefix()); logger.debug("isRelative: " + uri.isRelative()); logger.debug("segments: " + uri.segments()); }
@Override public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException { if (!context.getBuiltProject().hasNature(KarelNature.NATURE_ID)) return; for (Delta delta : context.getDeltas()) { IResourceDescription newRes = delta.getNew(); if (newRes == null) continue; try { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); URI uri = CommonPlugin.resolve(newRes.getURI()); if (!uri.isFile()) continue; IPath path = new Path(uri.toFileString()); IFile file = workspaceRoot.getFileForLocation(path); if (file == null) continue; generate(context.getBuiltProject(), file, monitor); } catch (Exception e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); Activator.getDefault().getLog().log(status); } } context.getResourceSet(); }
public void propagateEOperations(JavaResource resource, GenClass genClass) { GenPackage genPackage = genClass.getGenPackage(); EPackage ePackage = genPackage.getEcorePackage(); if (resource.getContents().isEmpty() || !(resource.getContents().get(0) instanceof CompilationUnit)) { return; } CompilationUnit cu = (CompilationUnit) resource.getContents().get(0); Class customClass = (Class) cu.getClassifiers().get(0); EClass eClass = genClass.getEcoreClass(); if (eClass == null) { return; } Set<Method> annotatedMethods = getAnnotatedMethods(customClass); for (Method method : annotatedMethods) { for (AnnotationInstanceOrModifier modifier : method.getAnnotationsAndModifiers()) { if (modifier instanceof Public) { EOperation newEOperation = EcoreFactory.eINSTANCE.createEOperation(); newEOperation.setName(method.getName()); Type opType = method.getTypeReference().getTarget(); newEOperation.setEType( eClassifierForCustomClass(opType, method.getTypeReference(), ePackage)); if (isMulti(opType)) { newEOperation.setUpperBound(-1); } for (Parameter parameter : method.getParameters()) { EParameter newEParameter = EcoreFactory.eINSTANCE.createEParameter(); newEParameter.setName(parameter.getName()); Type paramType = parameter.getTypeReference().getTarget(); newEParameter.setEType( eClassifierForCustomClass(paramType, parameter.getTypeReference(), ePackage)); // TODO generics, ... newEOperation.getEParameters().add(newEParameter); } // TODO @jendrik: why is that needed? // for (AnnotationInstanceOrModifier annotationInstance : // method.getAnnotationsAndModifiers()) { // if (annotationInstance instanceof AnnotationInstance) { // Classifier javaAnnotation = ((AnnotationInstance) // annotationInstance).getAnnotation(); // if (javaAnnotation.eIsProxy()) { // continue; // } // EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); // eAnnotation.setSource(javaAnnotation.getContainingCompilationUnit( // ).getNamespacesAsString() + javaAnnotation.getName()); // newEOperation.getEAnnotations().add(eAnnotation); // } // } boolean operationAlreadyExists = false; List<EOperation> operations = eClass.getEOperations(); List<EOperation> existingOperations = new ArrayList<EOperation>(operations); // must be done here already for ensuring that compared operations have the same parent eClass.getEOperations().add(newEOperation); for (EOperation existingOperation : existingOperations) { boolean removed = removeAnnotation(existingOperation); if (EcoreUtil.equals(existingOperation, newEOperation)) { operationAlreadyExists = true; removeAnnotation(existingOperation); annotateAsGenerated(existingOperation); break; } if (removed) { annotateAsGenerated(existingOperation); } } if (!operationAlreadyExists) { annotateAsGenerated(newEOperation); } else { eClass.getEOperations().remove(newEOperation); } break; } } } try { Resource ecoreResource = ePackage.eResource(); URI originalURI = ecoreResource.getURI(); if (originalURI.isFile()) { String workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); URI platformURI = URI.createPlatformResourceURI( originalURI.toFileString().substring(workspacePath.length()), true); ecoreResource.setURI(platformURI); } new ResourceSaver().saveResource(ecoreResource); ecoreResource.setURI(originalURI); } catch (IOException e) { e.printStackTrace(); } }