Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 363b4d6a9a11a4dd6f48953c19427bb467715078 (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
/*******************************************************************************
 * Copyright (c) 2007, 2008 Intel Corporation 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
 *
 * Contributors:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.settings.model;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

public abstract class ACPathEntry extends ACSettingEntry
		implements ICPathEntry {
//	IPath fFullPath;
//	IPath fLocation;
//	private IPath fPath;
	
	ACPathEntry(IResource rc, int flags) {
		super(rc.getFullPath().toString(), flags | RESOLVED | VALUE_WORKSPACE_PATH);
//		fFullPath = rc.getFullPath();
//		fPath = rc.getFullPath();
//		fLocation = rc.getLocation();
	}

/*	public ACLanguageSettingPathEntry(IPath fullPath, IPath location, int flags) {
		super(flags);
		fLocation = location;
		fFullPath = fullPath;
	}
*/
	ACPathEntry(String value, int flags) {
		super(value, flags);
	}
	
	ACPathEntry(IPath path, int flags) {
		super(path.toString(), flags /*| RESOLVED*/);
//		fPath = path;
//		if(isValueWorkspacePath())
//			fFullPath = path;
//		else
//			fLocation = path;
	}

	public IPath getFullPath() {
		if(isValueWorkspacePath())
			return new Path(getValue());
		if(isResolved()) {
			IPath path = new Path(getValue());
			return fullPathForLocation(path);
		}
		return null;
	}
	
	protected IPath fullPathForLocation(IPath location){
		IResource rcs[] = isFile() ?
				(IResource[])ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location)
				: (IResource[])ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(location);
		
		if(rcs.length > 0)
			return rcs[0].getFullPath();
		return null;
	}
	
	protected abstract boolean isFile();

	public IPath getLocation() {
		if(!isValueWorkspacePath())
			return new Path(getValue());
		if(isResolved()){
			IPath path = new Path(getValue());
			IResource rc = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
			if(rc != null)
				return rc.getLocation();
		}
		return null;
	}
	
	public boolean isValueWorkspacePath() {
		return checkFlags(VALUE_WORKSPACE_PATH);
	}

	@Override
	protected String contentsToString() {
		return fName;
	}
}

Back to the top