本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragment.isDefaultPackage方法的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragment.isDefaultPackage方法的具体用法?Java IPackageFragment.isDefaultPackage怎么用?Java IPackageFragment.isDefaultPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IPackageFragment
的用法示例。
在下文中一共展示了IPackageFragment.isDefaultPackage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: getTopLevelPackages
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
public static Collection<IPackageFragment> getTopLevelPackages(IJavaProject javaProject) {
Set<IPackageFragment> packages = new LinkedHashSet<>();
try {
if (javaProject == null || !javaProject.getProject().isAccessible()) {
return packages;
}
for (IPackageFragment f : javaProject.getPackageFragments()){
if (f.getKind() != IPackageFragmentRoot.K_SOURCE || f.isDefaultPackage() ) {
continue;
}
if (f.containsJavaResources() || f.getChildren().length > 1) {
packages.add(f);
}
}
} catch (CoreException e) {
e.printStackTrace();
}
return packages;
}
示例3: appendClassFileLabel
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Appends the label for a class file. Considers the CF_* flags.
*
* @param classFile the element to render
* @param flags the rendering flags. Flags with names starting with 'CF_' are considered.
*/
public void appendClassFileLabel(IClassFile classFile, long flags) {
if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) {
IPackageFragment pack= (IPackageFragment) classFile.getParent();
if (!pack.isDefaultPackage()) {
appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
fBuilder.append('.');
}
}
fBuilder.append(classFile.getElementName());
if (getFlag(flags, JavaElementLabels.CF_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentLabel((IPackageFragment) classFile.getParent(), flags & QUALIFIER_FLAGS);
}
}
示例4: appendCompilationUnitLabel
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Appends the label for a compilation unit. Considers the CU_* flags.
*
* @param cu the element to render
* @param flags the rendering flags. Flags with names starting with 'CU_' are considered.
*/
public void appendCompilationUnitLabel(ICompilationUnit cu, long flags) {
if (getFlag(flags, JavaElementLabels.CU_QUALIFIED)) {
IPackageFragment pack= (IPackageFragment) cu.getParent();
if (!pack.isDefaultPackage()) {
appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
fBuilder.append('.');
}
}
fBuilder.append(cu.getElementName());
if (getFlag(flags, JavaElementLabels.CU_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentLabel((IPackageFragment) cu.getParent(), flags & QUALIFIER_FLAGS);
}
}
示例5: appendPackageFragmentLabel
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* Appends the label for a package fragment. Considers the P_* flags.
*
* @param pack the element to render
* @param flags the rendering flags. Flags with names starting with P_' are considered.
*/
public void appendPackageFragmentLabel(IPackageFragment pack, long flags) {
if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) {
appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
fBuilder.append('/');
}
if (pack.isDefaultPackage()) {
fBuilder.append(JavaElementLabels.DEFAULT_PACKAGE);
} else if (getFlag(flags, JavaElementLabels.P_COMPRESSED)) {
appendCompressedPackageFragment(pack);
} else {
fBuilder.append(getElementName(pack));
}
if (getFlag(flags, JavaElementLabels.P_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
}
}
示例6: 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()));
}
示例7: getName
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
@Override
public String getName() {
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
try {
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
} catch(JavaModelException e) {
JavaLanguageServerPlugin.log(e);
}
return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
示例8: 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 + "\"");
}
}