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


Java IPackageFragment.getCompilationUnits方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.IPackageFragment.getCompilationUnits方法的典型用法代碼示例。如果您正苦於以下問題:Java IPackageFragment.getCompilationUnits方法的具體用法?Java IPackageFragment.getCompilationUnits怎麽用?Java IPackageFragment.getCompilationUnits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.IPackageFragment的用法示例。


在下文中一共展示了IPackageFragment.getCompilationUnits方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: findType

import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
public static IType findType(IJavaProject javaProject, String qualifiedName) throws JavaModelException {
	if(qualifiedName == null || qualifiedName.length() == 0) return null;
	IType type = javaProject.findType(qualifiedName);
	if(type != null) return type;
	int dot = qualifiedName.lastIndexOf('.');
	String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot);
	String shortName = qualifiedName.substring(dot + 1);
	IPackageFragmentRoot[] rs = javaProject.getPackageFragmentRoots();
	for (int i = 0; i < rs.length; i++) {
		IPackageFragment f = rs[i].getPackageFragment(packageName);
		if(f == null || !f.exists()) continue;
		ICompilationUnit[] us = f.getCompilationUnits();

		for (int j = 0; j < us.length; j++) {
			IType t = us[j].getType(shortName);
			if(t != null && t.exists()) return t;
		}
	}
	return null;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:EclipseJavaUtil.java

示例3: 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

示例4: getFiles

import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
private static Set<ICompilationUnit> getFiles(String projname) throws CoreException {
	IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();
	IProject proj = ws.getProject(projname);
	IJavaProject javaProject = JavaCore.create(proj);
	Set<ICompilationUnit> files = new HashSet<ICompilationUnit>();
	javaProject.open(new NullProgressMonitor());
	for( IPackageFragment packFrag : javaProject.getPackageFragments()) {
		for (ICompilationUnit icu : packFrag.getCompilationUnits()) {
			files.add(icu);
		}
	}
	javaProject.close();
	return files;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:15,代碼來源:LSDiffRunner.java

示例5: processPackageFragment

import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
private void processPackageFragment(ITypeVisitor visitor,
    IPackageFragment fragment, IProgressMonitor monitor)
    throws JavaModelException {
  switch (fragment.getKind()) {
  case IPackageFragmentRoot.K_SOURCE:
    final ICompilationUnit[] units = fragment.getCompilationUnits();
    monitor.beginTask("", units.length); //$NON-NLS-1$
    for (final ICompilationUnit unit : units) {
      if (monitor.isCanceled()) {
        break;
      }
      processCompilationUnit(visitor, unit, monitor);
      monitor.worked(1);
    }
    break;
  case IPackageFragmentRoot.K_BINARY:
    final IClassFile[] classfiles = fragment.getClassFiles();
    monitor.beginTask("", classfiles.length); //$NON-NLS-1$
    for (final IClassFile classfile : classfiles) {
      if (monitor.isCanceled()) {
        break;
      }
      processClassFile(visitor, classfile, monitor);
      monitor.worked(1);
    }
    break;
  }
  monitor.done();
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:30,代碼來源:TypeTraverser.java

示例6: setFrameworkPackageTypes

import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
private void setFrameworkPackageTypes() throws JavaModelException {
	String className = null;

	// To append the packageName - get the fullyQualified type name
	StringBuilder typeName = new StringBuilder();

	// Current project open
	IProject currentProject = WorkspaceUtilities.getCurrentProject(window);
	
	Set<String> frameworkPackages = defaultingModel.getFrameworkPackages();

	// Get a IcompilationUnit of the current project
	IPackageFragment[] packages = JavaCore.create(currentProject).getPackageFragments();
	for (IPackageFragment mypackage : packages) {
		// Hard-coded package names for now - Until we get logic for the
		// distinguishing Framework Types and ApplicationDefault types
		// Only for MD_Summary for now
		// TOSUM: TODO: Get a logic to distinguish between
		// Added in the package names for CDB, AFS and DL

		if (frameworkPackages.contains(mypackage.getElementName())) {
			for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
				IPackageDeclaration[] pck = unit.getPackageDeclarations();
				for (IPackageDeclaration ipack : pck) {
					IResource resource = ipack.getResource();

					// Get the type Name
					className = resource.getName();
					// Remove the extensions from the typeName
					int indexOf = className.indexOf(".java");
					typeName.append(mypackage.getElementName());
					typeName.append(".");
					typeName.append(className.substring(0, indexOf));

					// XXX. Fix this. No point in storing the package name and the fully qualified type
					model.addFrameworkPackageType(new PackageType(mypackage.getElementName(), typeName.toString()));
				}
				// Clean up StringBuilder
				typeName.setLength(0);
			}
			typeName.setLength(0);
		}
		typeName.setLength(0);
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:46,代碼來源:GenerateDefaultMap.java

示例7: setApplicationTypes

import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
private void setApplicationTypes() throws JavaModelException {
	String className = null;

	// To append the packageName - get the fullyQualified type name
	StringBuilder typeName = new StringBuilder();

	// Current project open
	IProject currentProject = WorkspaceUtilities.getCurrentProject(window);

	HashSet<String> appPackages = defaultingModel.getApplicationPackages();
	
	// Get a IcompilationUnit of the current project
	IPackageFragment[] packages = JavaCore.create(currentProject).getPackageFragments();
	for (IPackageFragment mypackage : packages) {
		// Hard-coded package names for now - Until we get logic for the
		// distinguishing Framework Types and ApplicationDefault types
		// Only for MD_Summary for now
		// TODO: Get a logic to distinguish between
		// Added in the package names for CDB
		
		// TOSUM: XXX. What the HELL is this? Get the Element name, remove .java, add .java?!?!?
		// Surely, there has to be a MUCH cleaner way of doing this
		// the package declaration has the fully qualified name!!!
		if (appPackages.contains(mypackage.getElementName())) {
			for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
				IPackageDeclaration[] pck = unit.getPackageDeclarations();
				for (IPackageDeclaration ipack : pck) {
					IResource resource = ipack.getResource();
					// Get the type Name
					className = resource.getName();
					// Remove the extensions from the typeName
					int indexOf = className.indexOf(".java");
					typeName.append(mypackage.getElementName());
					typeName.append(".");
					typeName.append(className.substring(0, indexOf));

					// XXX. Fix this. No point in storing the package name and the fully qualified type
					model.addApplicationPackageType(new PackageType(mypackage.getElementName(), typeName.toString()));
				}
				typeName.setLength(0);
			}
			typeName.setLength(0);
		}
		typeName.setLength(0);
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:47,代碼來源:GenerateDefaultMap.java

示例8: parse

import org.eclipse.jdt.core.IPackageFragment; //導入方法依賴的package包/類
public static PackageBean parse(IPackageFragment pPackage) throws JavaModelException {
    PackageBean packageBean = new PackageBean();
    CodeParser codeParser = new CodeParser();
    String textualContent = "";

    ArrayList<ClassBean> classes = new ArrayList<>();

    packageBean.setName(pPackage.getElementName());

    for (ICompilationUnit cu : pPackage.getCompilationUnits()) {

        textualContent += cu.getSource();

        CompilationUnit parsed = codeParser.createParser(cu.getSource());
        TypeDeclaration typeDeclaration = (TypeDeclaration) parsed.types().get(0);

        ArrayList<String> imported = new ArrayList<>();

        for (IImportDeclaration importedResource : cu.getImports()) {
            imported.add(importedResource.getElementName());
        }

        classes.add(ClassParser.parse(typeDeclaration, packageBean.getName(), imported));
    }

    packageBean.setTextContent(textualContent);

    return packageBean;
}
 
開發者ID:fpalomba,項目名稱:aDoctor,代碼行數:30,代碼來源:PackageParser.java


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