本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragment类的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragment类的具体用法?Java IPackageFragment怎么用?Java IPackageFragment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IPackageFragment类属于org.eclipse.jdt.core包,在下文中一共展示了IPackageFragment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: collectAllCompilationUnits
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
/**
* Collects all compilation units within the project.
* @return the collection of the compilation units
*/
public static List<ICompilationUnit> collectAllCompilationUnits() {
List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
try {
IProject[] projects = getWorkspace().getRoot().getProjects();
for (int i = 0; i < projects.length; i++) {
IJavaProject project = (IJavaProject)JavaCore.create((IProject)projects[i]);
IPackageFragment[] packages = project.getPackageFragments();
for (int j = 0; j < packages.length; j++) {
ICompilationUnit[] cus = packages[j].getCompilationUnits();
for (int k = 0; k < cus.length; k++) {
IResource res = cus[k].getResource();
if (res.getType() == IResource.FILE) {
String name = cus[k].getPath().toString();
if (name.endsWith(".java")) {
units.add(cus[k]);
}
}
}
}
}
} catch (JavaModelException e) {
e.printStackTrace();
}
return units;
}
示例3: ResourceContext
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
/**
* @param containerFullPath
* @param packageFragmentRoot
* @param targetPkg
* @param selectedFilename
* @param selectedFile
* @param openEditor
* @param ce
* @throws CoreException
*/
public ResourceContext(
IPath containerFullPath,
IPackageFragmentRoot packageFragmentRoot,
IPackageFragment targetPkg,
String selectedFilename,
String extendedClassname,
IFile selectedFile,
GENERATION_MODE mode,
ClassExtension ce) throws CoreException {
this.selectedFile=selectedFile;
this.packageFragmentRoot = packageFragmentRoot;
this.targetPkg = targetPkg;
this.interfaceName = selectedFile.getName().split("\\.")[0] + ".java";
this.selectedFilename = selectedFilename;
this.containerFullPath = containerFullPath;
this.mode=mode;
this.classExtension=ce;
this.generateOnlyInterface = false;
this.openEditor = false;
this.erase = true;
this.extendedClassname=extendedClassname;
}
示例4: findClassesWithAnnotation
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
/**
* @param projectName
* @return
* @throws JavaModelException
*/
private static List<IType> findClassesWithAnnotation(String projectName, Class annotationClass, String attributName,
boolean valued) throws JavaModelException {
List<IType> classList = new ArrayList<IType>();
IProject project = ResourceManager.getProject(projectName);
IJavaProject javaProject = JavaCore.create(project);
IPackageFragment[] packages = javaProject.getPackageFragments();
for (IPackageFragment packageFragment : packages) {
for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
if (compilationUnit.exists()) {
IType type = getClassesWithAnnotation(compilationUnit, annotationClass, attributName, valued);
if (type != null)
classList.add(type);
}
}
}
return classList;
}
示例5: generateOffline
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
public static void generateOffline(final IResource resource, IPackageFragment pkg, String classfile , BuildPolicy[] generators, int timeout, IWorkbenchWindow aww) {
Job job = new Job("GW4E Offline Generation Source Job") {
@Override
public IStatus run(IProgressMonitor monitor) {
try {
if (resource instanceof IFile) {
SubMonitor subMonitor = SubMonitor.convert(monitor, 120);
IFile file = (IFile) resource;
if (PreferenceManager.isGraphModelFile(file)) {
AbstractPostConversion converter = getOfflineConversion(file,pkg,classfile,generators,timeout);
ConversionRunnable runnable = converter.createConversionRunnable(aww);
subMonitor.subTask("Processing converter ");
SubMonitor child = subMonitor.split(1);
runnable.run(child);
}
}
} catch (Exception e) {
e.printStackTrace();
ResourceManager.logException(e);
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
示例6: getIFileFromQualifiedName
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
/**
* @param project
* @param qualifiedName
* @return
* @throws CoreException
*/
public static IFile getIFileFromQualifiedName(String projectname, String qualifiedName) throws CoreException {
IProject project = getProject(projectname);
IJavaProject jproject = JavaCore.create(project);
IPackageFragment[] pkgs = jproject.getPackageFragments();
String spath = qualifiedName.replace(".", "/");
for (int i = 0; i < pkgs.length; i++) {
if (pkgs[i].getKind() != IPackageFragmentRoot.K_SOURCE)
continue;
IPath path = pkgs[i].getPath().append(spath);
IFile iFile = (IFile) ResourceManager.getResource(path.toString() + ".java");
if (iFile != null && iFile.exists())
return iFile;
}
return null;
}
示例7: getPathWithinPackageFragment
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
/**
* Return a path relative to its package fragment root
*
* @param project
* @param path
* @return
* @throws JavaModelException
*/
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
IProject project = ifile.getProject();
IPath path = ifile.getFullPath();
String[] segments = path.segments();
IJavaProject jproject = JavaCore.create(project);
IPackageFragment[] pkgs = jproject.getPackageFragments();
IPath p = new Path("/");
for (int i = 0; i < segments.length; i++) {
for (int j = 0; j < pkgs.length; j++) {
if (pkgs[j].getPath().equals(p)) {
IPath ret = path.makeRelativeTo(pkgs[j].getPath());
return ret;
}
}
p = p.append(segments[i]);
}
return null;
}
示例8: createClassRepo
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
public void createClassRepo(String jarFileName, String Package) {
ClassRepo.INSTANCE.flusRepo();
try {
IPackageFragmentRoot iPackageFragmentRoot = getIPackageFragment(jarFileName);
if (iPackageFragmentRoot != null) {
IPackageFragment fragment = iPackageFragmentRoot.getPackageFragment(Package);
if (fragment != null) {
for (IClassFile element : fragment.getClassFiles()) {
ClassRepo.INSTANCE.addClass(element,"","",false);
}
} else {
new CustomMessageBox(SWT.ERROR, Package + " Package not found in jar "
+ iPackageFragmentRoot.getElementName(), "ERROR").open();
}
}
} catch (JavaModelException e) {
LOGGER.error("Error occurred while loading class from jar {}", jarFileName, e);
}
loadClassesFromSettingsFolder();
}
示例9: testMissingCastParents1
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
@Test
public void testMissingCastParents1() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Object o) {\n");
buf.append(" String x= (String) o.substring(1);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Object o) {\n");
buf.append(" String x= ((String) o).substring(1);\n");
buf.append(" }\n");
buf.append("}\n");
Expected e1 = new Expected("Add parentheses around cast", buf.toString());
assertCodeActionExists(cu, e1);
}
示例10: init
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
/**
* We will accept the selection in the workbench to see if
* we can initialize from it.
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.selection = selection;
WPILibJavaPlugin.logInfo(selection.toString());
Object element = ((StructuredSelection) selection).getFirstElement();
if (element != null) WPILibJavaPlugin.logInfo(element.getClass().toString());
if (element instanceof IResource) {
project = ((IResource) element).getProject();
} else if (element instanceof IPackageFragment) {
project = ((IPackageFragment) element).getJavaProject().getProject();
} else if (element instanceof IPackageFragmentRoot) {
project = ((IPackageFragmentRoot) element).getJavaProject().getProject();
} else if (element instanceof ICompilationUnit) {
project = ((ICompilationUnit) element).getJavaProject().getProject();
} else WPILibJavaPlugin.logInfo("Element not instance of IResource");
}
示例11: testMethodInInfixExpression2
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
@Test
public void testMethodInInfixExpression2() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private boolean foo() {\n");
buf.append(" return f(1) == f(2);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private boolean foo() {\n");
buf.append(" return f(1) == f(2);\n");
buf.append(" }\n");
buf.append("\n");
buf.append(" private Object f(int i) {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
Expected e1 = new Expected("Create method 'f(int)'", buf.toString());
assertCodeActionExists(cu, e1);
}
示例12: testMissingParam5
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
@Test
public void testMissingParam5() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("/**\n");
buf.append(" * @param <B> Hello\n");
buf.append(" */\n");
buf.append("public class E<A, B> {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("/**\n");
buf.append(" * @param <A> \n");
buf.append(" * @param <B> Hello\n");
buf.append(" */\n");
buf.append("public class E<A, B> {\n");
buf.append("}\n");
Expected e1 = new Expected("Add '@param' tag", buf.toString());
Expected e2 = new Expected("Add all missing tags", buf.toString());
assertCodeActions(cu, e1, e2);
}
示例13: visitICompilationUnits
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
private void visitICompilationUnits(SubMonitor subMonitor, IPackageFragment packageFragment, IFolder folder, Set<String> unresolvedTypes) throws JavaModelException {
for (ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
try {
theParser.setSource(compilationUnit);
theParser.setResolveBindings(true);
ASTNode entireAST = theParser.createAST(new NullProgressMonitor());
OutCodeVisitor visitor = new OutCodeVisitor();
entireAST.accept(visitor);
String fileName = compilationUnit.getElementName().replace(".java", ".rfm");
String mappedFile = visitITypes(compilationUnit, visitor, unresolvedTypes);
createFile(fileName, mappedFile, folder);
subMonitor.worked(1);
} catch (JavaModelException e) {
e.printStackTrace();
}
}
}
示例14: TypeReferenceProcessor
import org.eclipse.jdt.core.IPackageFragment; //导入依赖的package包/类
public TypeReferenceProcessor(Set<String> oldSingleImports, Set<String> oldDemandImports, CompilationUnit root, ImportRewrite impStructure, boolean ignoreLowerCaseNames, UnresolvableImportMatcher unresolvableImportMatcher) {
fOldSingleImports= oldSingleImports;
fOldDemandImports= oldDemandImports;
fImpStructure= impStructure;
fDoIgnoreLowerCaseNames= ignoreLowerCaseNames;
fUnresolvableImportMatcher= unresolvableImportMatcher;
ICompilationUnit cu= impStructure.getCompilationUnit();
fImplicitImports= new HashSet<>(3);
fImplicitImports.add(""); //$NON-NLS-1$
fImplicitImports.add("java.lang"); //$NON-NLS-1$
fImplicitImports.add(cu.getParent().getElementName());
fAnalyzer= new ScopeAnalyzer(root);
fCurrPackage= (IPackageFragment) cu.getParent();
fAllowDefaultPackageImports= cu.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true).equals(JavaCore.VERSION_1_3);
fImportsAdded= new HashSet<>();
fUnresolvedTypes= new HashMap<>();
}
示例15: 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);
}
}