org.eclipse.core.internal.resources.projectvariables.ParentVariableResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aspectjtools Show documentation
Show all versions of aspectjtools Show documentation
AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during
compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based
@AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step.
This library is a superset of AspectJ weaver and hence also of AspectJ runtime.
/*******************************************************************************
* Copyright (c) 2008, 2014 Freescale Semiconductor 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:
* Freescale Semiconductor - initial API and implementation
* IBM Corporation - ongoing development
*******************************************************************************/
package org.eclipse.core.internal.resources.projectvariables;
import java.net.URI;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.variableresolvers.PathVariableResolver;
/**
* Path Variable representing the parent directory of the variable provided
* in argument, following the syntax:
*
* "${PARENT-COUNT-MyVariable}"
*
*/
public class ParentVariableResolver extends PathVariableResolver {
final public static String NAME = "PARENT"; //$NON-NLS-1$
public ParentVariableResolver() {
// nothing
}
@Override
public String getValue(String variable, IResource resource) {
int index = variable.indexOf('-');
if (index == -1 || index == (variable.length() - 1))
return null;
String countRemaining = variable.substring(index + 1);
index = countRemaining.indexOf('-');
if (index == -1 || index == (variable.length() - 1))
return null;
String countString = countRemaining.substring(0, index);
int count = 0;
try {
count = Integer.parseInt(countString);
if (count < 0)
return null;
} catch (NumberFormatException e) {
return null;
}
String argument = countRemaining.substring(index + 1);
URI value = resource.getPathVariableManager().getURIValue(argument);
if (value == null)
return null;
value = resource.getPathVariableManager().resolveURI(value);
value = URIUtil.toURI(URIUtil.toPath(value).removeLastSegments(count));
return value.toASCIIString();
}
}