當前位置: 首頁>>代碼示例>>Java>>正文


Java IPackageFragment類代碼示例

本文整理匯總了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 "";
}
 
開發者ID:liaoziyang,項目名稱:ContentAssist,代碼行數:22,代碼來源:ResourceMacro.java

示例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;
}
 
開發者ID:liaoziyang,項目名稱:ContentAssist,代碼行數:34,代碼來源:WorkspaceUtilities.java

示例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; 
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:33,代碼來源:ResourceContext.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:23,代碼來源:JDTManager.java

示例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();
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:27,代碼來源:GraphWalkerContextManager.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:22,代碼來源:ResourceManager.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:27,代碼來源:ResourceManager.java

示例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();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:21,代碼來源:BuildExpressionEditorDataSturcture.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:25,代碼來源:UnresolvedMethodsQuickFixTest.java

示例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");
}
 
開發者ID:wpilibsuite,項目名稱:EclipsePlugins,代碼行數:21,代碼來源:FileTemplateWizard.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:27,代碼來源:UnresolvedMethodsQuickFixTest.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:25,代碼來源:JavadocQuickFixTest.java

示例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();
		}
	}
}
 
開發者ID:ioanaverebi,項目名稱:Sparrow,代碼行數:18,代碼來源:ModelVisitor.java

示例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<>();
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:OrganizeImportsOperation.java

示例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);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:22,代碼來源:JavaElementLabelComposer.java


注:本文中的org.eclipse.jdt.core.IPackageFragment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。