本文整理匯總了Java中org.eclipse.jdt.core.IPackageFragment.getElementName方法的典型用法代碼示例。如果您正苦於以下問題:Java IPackageFragment.getElementName方法的具體用法?Java IPackageFragment.getElementName怎麽用?Java IPackageFragment.getElementName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.IPackageFragment
的用法示例。
在下文中一共展示了IPackageFragment.getElementName方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getName
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Obtains the name of the specified element.
* @param elem the element
* @param type the type of the element
* @return the name string
*/
public static String getName(IJavaElement elem) {
int type = elem.getElementType();
if (type == IJavaElement.JAVA_PROJECT) {
return elem.getResource().getName();
} else if (type == IJavaElement.PACKAGE_DECLARATION) {
IPackageFragment jpackage = (IPackageFragment)elem;
return jpackage.getElementName();
} else if (type == IJavaElement.COMPILATION_UNIT) {
return elem.getResource().getName();
}
return "";
}
示例2: build
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* @see IBuilder#build
*/
@Override
public void build(Measure measure, ItemMeasured item) {
IPackageFragment[] packages;
ItemMeasured packageMeasured;
String packageName = "";
try {
packages = project.getPackageFragments();
for (IPackageFragment myPackage : packages) {
if ((myPackage.getKind() == IPackageFragmentRoot.K_SOURCE) && myPackage.hasChildren()) {
packageName = myPackage.isDefaultPackage() ? "(default)" : myPackage.getElementName();
packageMeasured = new ItemMeasured(packageName, item);
addClassBuilder(measure, myPackage, packageMeasured);
item.addChild(packageMeasured);
item.setMax(packageMeasured.getMax());
item.setClassWithMax(packageMeasured.getClassWithMax());
item.addValue(packageMeasured.getValue());
item.addMean(packageMeasured.getMean());
}
}
} catch (JavaModelException exception) {
logger.error(exception);
}
}
示例3: addEdits
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i= 0; i < decls.length; i++) {
ISourceRange range= decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = "\n";
String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
示例4: getNameOfContainingPackage
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Gets the name of containing package.
*
* @param xtextDocument
* the xtext document
* @return the name of containing package
*/
public String getNameOfContainingPackage(final IXtextDocument xtextDocument) {
IFile file = xtextDocument.getAdapter(IFile.class);
if (file != null && file.getParent() instanceof IFolder) {
IJavaProject javaProject = JavaCore.create(file.getProject());
try {
IPackageFragment myFragment = javaProject.findPackageFragment(file.getParent().getFullPath());
return myFragment.getElementName();
} catch (JavaModelException e) {
LOGGER.error("Could not determine package for file of given document");
}
}
return null;
}
示例5: getCatalogQualifiedName
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Gets the catalog qualified name. Instead of using the qualified name provider, which is based
* on the object attribute values, this method uses the resource properties for determining the
* fully qualified name. This is legitimate, because the check catalog FQN consists of the Java
* package name concatenated with the file name (which must be equal to the model name).
*
* @param catalog
* the catalog
* @return the catalog qualified name
*/
public String getCatalogQualifiedName(final CheckCatalog catalog) {
final URI uri = EcoreUtil.getURI(catalog);
IFile file = RuntimeProjectUtil.findFileStorage(uri, mapper);
IJavaProject project = JavaCore.create(file.getProject());
try {
IPackageFragment packageFragment = project.findPackageFragment(file.getParent().getFullPath());
final String fileNameWithoutExtension = file.getName().substring(0, file.getName().length() - (file.getFileExtension().length() + 1));
return packageFragment.getElementName() + '.' + fileNameWithoutExtension;
} catch (JavaModelException e) {
LOGGER.error("Could not determine plugin path for catalog " + catalog.getName(), e);
}
return null;
}
示例6: getQualifiedName
import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
/**
* Returns the qualified name of the given file, i.e. qualified.name.of.File
* for <code>/project/sourceFolder/qualified/name/of/File.fileExt</code> or
* <code>/project/outputFolder/qualified/name/of/File.fileExt</code>.
*
* @param file
* a file
* @return a qualified name source folder
* @throws TurnusException
*/
public static String getQualifiedName(IFile file) throws TurnusException {
try {
IProject project = file.getProject();
IJavaProject javaProject = JavaCore.create(project);
if (!javaProject.exists()) {
throw new TurnusException(
"Impossible to obtainthe qualified name of \"" + file + "\": the project does not exist");
}
IPath path = file.getParent().getFullPath();
IPackageFragment fragment = null;
if (javaProject.getOutputLocation().isPrefixOf(path)) {
// create relative path
int count = path.matchingFirstSegments(javaProject.getOutputLocation());
IPath relPath = path.removeFirstSegments(count);
// creates full path to source
for (IFolder folder : EcoreUtils.getSourceFolders(project)) {
path = folder.getFullPath().append(relPath);
fragment = javaProject.findPackageFragment(path);
if (fragment != null) {
break;
}
}
} else {
fragment = javaProject.findPackageFragment(path);
}
if (fragment == null) {
throw new TurnusException("Impossible to obtainthe qualified name of \"" + file
+ "\": the package fragment is not valid");
}
String name = file.getFullPath().removeFileExtension().lastSegment();
if (fragment.isDefaultPackage()) {
// handles the default package case
return name;
}
return fragment.getElementName() + "." + name;
} catch (Exception e) {
throw new TurnusException("Impossible to obtainthe qualified name of \"" + file + "\"");
}
}