Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0632f26fc855fc37f1637fc67ac8dbf266b6c63e (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
/*******************************************************************************
 * Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
 * 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 org.eclipse.lsp4e.cpp.language.cquery;

import java.lang.reflect.Type;

import org.eclipse.lsp4j.SymbolKind;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.annotations.JsonAdapter;

@JsonAdapter(ExtendedSymbolKindParsers.class)
public class ExtendedSymbolKindType {
	int value;
	transient boolean isProtocolSymbol;

	public ExtendedSymbolKindType(int _v) {
		try {
			SymbolKind.forValue(_v);
			value = _v;
			isProtocolSymbol = true;
		} catch (IllegalArgumentException e) {
			try {
				CquerySymbolKind.forValue(_v);
				value = _v;
				isProtocolSymbol = false;
			} catch (IllegalArgumentException y) {
				throw new IllegalArgumentException("Illegal value for SymbolKind"); //$NON-NLS-1$
			}
		}
	}

	public int getValue() {
		return value;
	}
}

class ExtendedSymbolKindParsers
		implements JsonDeserializer<ExtendedSymbolKindType>, JsonSerializer<ExtendedSymbolKindType> {
	@Override
	public ExtendedSymbolKindType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
			throws JsonParseException {

		int symbolKindValue = json.getAsInt();
		return new ExtendedSymbolKindType(symbolKindValue);
	}

	@Override
	public JsonElement serialize(ExtendedSymbolKindType src, Type typeOfSrc, JsonSerializationContext context) {
		return new JsonPrimitive(src.getValue());
	}
}

Back to the top