Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0812c7e8c2d6c991e9fcd5b30e23000a24591578 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
 * Copyright (c) 2015 QNX Software Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.qt.core.qmldir;

import java.io.InputStream;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.eclipse.cdt.internal.qt.core.Activator;

public class QMLDirectoryInfo {
	public static class Module {
		private final String name;
		private final String initialVersion;

		public Module(String name, String ver) {
			this.name = name;
			this.initialVersion = ver;
		}

		public String getName() {
			return name;
		}

		public String getInitialVersion() {
			return initialVersion;
		}
	}

	public static class Plugin {
		private final String name;
		private final Path path;

		private Plugin(String name, String path) {
			this.name = name;
			Path p = null;
			if (path != null) {
				try {
					p = Paths.get(path);
				} catch (InvalidPathException e) {
					Activator.log(e);
				}
			}
			this.path = p;
		}

		public String getName() {
			return name;
		}

		public Path getRelativePath() {
			return path;
		}
	}

	public static class ResourceFile {
		private final String name;
		private final boolean internal;
		private final boolean singleton;
		private final String initialVersion;

		private ResourceFile(String name, String ver, boolean internal, boolean singleton) {
			this.name = name;
			this.initialVersion = ver;
			this.internal = internal;
			this.singleton = singleton;
		}

		public String getName() {
			return name;
		}

		public String getInitialVersion() {
			return initialVersion;
		}

		public boolean isSingleton() {
			return singleton;
		}

		public boolean isInternal() {
			return internal;
		}
	}

	private String moduleIdentifier;
	private Plugin plugin;
	private String classname;
	private String typeInfo;
	private final Collection<Module> depends;
	private final Collection<ResourceFile> resources;
	private boolean designersupported;

	public QMLDirectoryInfo(InputStream input) {
		this.depends = new LinkedList<>();
		this.resources = new LinkedList<>();

		IQDirAST ast = new QMLDirectoryParser().parse(input);
		for (IQDirCommand c : ast.getCommands()) {
			if (c instanceof IQDirModuleCommand) {
				if (moduleIdentifier == null) {
					moduleIdentifier = ((IQDirModuleCommand) c).getModuleIdentifier().getText();
				}
			} else if (c instanceof IQDirPluginCommand) {
				if (plugin == null) {
					IQDirPluginCommand pc = (IQDirPluginCommand) c;
					plugin = new Plugin(pc.getName().getText(), pc.getPath() != null ? pc.getPath().getText() : null);
				}
			} else if (c instanceof IQDirTypeInfoCommand) {
				if (typeInfo == null) {
					typeInfo = ((IQDirTypeInfoCommand) c).getFile().getText();
				}
			} else if (c instanceof IQDirResourceCommand) {
				IQDirResourceCommand rc = (IQDirResourceCommand) c;
				resources.add(new ResourceFile(rc.getFile().getText(),
						rc.getInitialVersion().getVersionString(),
						false, false));
			} else if (c instanceof IQDirInternalCommand) {
				IQDirInternalCommand rc = (IQDirInternalCommand) c;
				resources.add(new ResourceFile(rc.getFile().getText(),
						null, true, false));
			} else if (c instanceof IQDirSingletonCommand) {
				IQDirSingletonCommand rc = (IQDirSingletonCommand) c;
				resources.add(new ResourceFile(rc.getFile().getText(),
						rc.getInitialVersion().getVersionString(),
						false, true));
			} else if (c instanceof IQDirDependsCommand) {
				IQDirDependsCommand dc = (IQDirDependsCommand) c;
				depends.add(new Module(dc.getModuleIdentifier().getText(),
						dc.getInitialVersion().getVersionString()));
			} else if (c instanceof IQDirClassnameCommand) {
				if (classname == null) {
					classname = ((IQDirClassnameCommand) c).getIdentifier().getText();
				}
			} else if (c instanceof IQDirDesignerSupportedCommand) {
				designersupported = true;
			}
		}
	}

	public String getModuleIdentifier() {
		return moduleIdentifier;
	}

	public Plugin getPlugin() {
		return plugin;
	}

	public String getClassname() {
		return classname;
	}

	public String getTypesFileName() {
		return typeInfo;
	}

	public Collection<Module> getDependentModules() {
		return Collections.unmodifiableCollection(depends);
	}

	public Collection<ResourceFile> getResources() {
		return Collections.unmodifiableCollection(resources);
	}

	public boolean isDesignersupported() {
		return designersupported;
	}
}

Back to the top