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


Java ICompilationUnit.getAllTypes方法代碼示例

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


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

示例1: isGraphWalkerExecutionContextClass

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * @param testInterface
 * @return
 * @throws JavaModelException
 */
public static boolean isGraphWalkerExecutionContextClass(ICompilationUnit unit) throws JavaModelException {
	IType[] types = unit.getAllTypes();

	if (types == null || types.length == 0) {
		ResourceManager.logInfo(unit.getJavaProject().getProject().getName(),
				"getAllTypes return null" + unit.getPath());
		return false;
	}
	IType execContextType = unit.getJavaProject().findType(ExecutionContext.class.getName());

	for (int i = 0; i < types.length; i++) {
		IType type = types[i];
		String typeNname = type.getFullyQualifiedName();
		String compilationUnitName = JDTManager.getJavaFullyQualifiedName(unit);
		if (typeNname.equals(compilationUnitName)) {
			try {
				ITypeHierarchy th = types[0].newTypeHierarchy(new NullProgressMonitor());
				return th.contains(execContextType);
			} catch (Exception e) {
				ResourceManager.logException(e);
			}
		}
	}
	return false;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:31,代碼來源:JDTManager.java

示例2: containsMethod

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
public static boolean containsMethod (String path, String[] requiredMethods) throws JavaModelException {
	IResource resource = ResourceManager.getResource(path);
	IFile file = (IFile) resource;
	ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
	IType[] types = cu.getAllTypes();
	List<String> list = new ArrayList<String>();
	for (int i = 0; i < types.length; i++) {
		IMethod[] methods = types[i].getMethods();
		for (int j = 0; j < methods.length; j++) {
			list.add(methods[j].getElementName());
		}
	} 
	for (int i = 0; i < requiredMethods.length; i++) {
		String method = requiredMethods[i];
		if (!list.contains(method)) return false;
	}     
	return true;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:19,代碼來源:JDTHelper.java

示例3: createServiceFile

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Parse un fichier candidat de service métier.
 * 
 * @param document Document du service métier.
 * @param javaProject Projet Java du service.
 * @return Le service, <code>null</code> sinon.
 */
private ServiceFile createServiceFile(IFile file, IJavaProject javaProject) {
	/* Charge l'AST du fichier Java. */
	ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
	if (compilationUnit == null) {
		return null;
	}
	List<ServiceImplementation> serviceImplementations = new ArrayList<>();
	try {
		/* Parcourt les types du fichier Java. */
		for (IType type : compilationUnit.getAllTypes()) {
			handleType(type, file, serviceImplementations);
		}
	} catch (JavaModelException e) {
		ErrorUtils.handle(e);
	}

	/* Créé le fichier de service. */
	return new ServiceFile(serviceImplementations);
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:27,代碼來源:ServiceManager.java

示例4: createWsFile

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Parse un fichier candidat de webservice.
 * 
 * @param file Fichier du webservice.
 * @param javaProject Projet Java du fichier.
 * @return Le webservice, <code>null</code> sinon.
 */
private WsFile createWsFile(IFile file, IJavaProject javaProject) {
	/* Charge l'AST du fichier Java. */
	ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
	if (compilationUnit == null) {
		return null;
	}
	List<WsRoute> wsRoutes = new ArrayList<>();
	try {
		/* Parcourt les types du fichier Java. */
		for (IType type : compilationUnit.getAllTypes()) {
			handleType(type, file, wsRoutes);
		}
	} catch (JavaModelException e) {
		ErrorUtils.handle(e);
	}

	/* Créé le fichier de webservice. */
	return new WsFile(file, wsRoutes);
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:27,代碼來源:WsRouteManager.java

示例5: createDaoFile

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Parse un fichier candidat de DAO/PAO.
 * 
 * @param file Fichier.
 * @param javaProject Projet Java du fichier.
 * @return Le DAO, <code>null</code> sinon.
 */
private DaoFile createDaoFile(IFile file, IJavaProject javaProject) {
	/* Charge l'AST du fichier Java. */
	ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
	if (compilationUnit == null) {
		return null;
	}
	List<DaoImplementation> daoImplementations = new ArrayList<>();
	try {
		/* Parcourt les types du fichier Java. */
		for (IType type : compilationUnit.getAllTypes()) {
			handleType(type, file, daoImplementations);
		}
	} catch (JavaModelException e) {
		ErrorUtils.handle(e);
	}

	/* Créé le fichier de DAO/PAO. */
	String daoName = StringUtils.removeExtension(compilationUnit.getElementName());
	return new DaoFile(daoName, file, daoImplementations);
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:28,代碼來源:DaoManager.java

示例6: calculateValue

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * @see IJavaModel#calculateValue
 */
@Override
public void calculateValue(ICompilationUnit unit) {
	
	int length = 0;
	
	try {
		IType[] types = unit.getAllTypes();
		for (IType type : types) {
			IJavaProject ancestor = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT);
			ITypeHierarchy th= type.newTypeHierarchy(ancestor, null);
			
			if (th != null) superclassesList = th.getAllSuperclasses(type);
			
			if (superclassesList != null) length = superclassesList.length;
			
			Double value = new BigDecimal(length, new MathContext(2, RoundingMode.UP)).doubleValue();
			setDitValue(value);
		}
		
	}catch (JavaModelException javaException) {
		logger.error(javaException);
	}catch (NullPointerException nullPointerException){
		logger.error(nullPointerException);
	}
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:29,代碼來源:DepthOfInheritanceTreeJavaModel.java

示例7: calculateValue

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * @see IJavaModel#calculateValue
 */
@Override
public void calculateValue(ICompilationUnit unit) {
	
	try {
		int length = 0;
		
		IType[] types = unit.getAllTypes();
		for (IType type : types) {
			ITypeHierarchy th= type.newTypeHierarchy((IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT), null);
			
			if (th != null) subtypesList = th.getAllSubtypes(type);
			
			if (subtypesList != null) length = subtypesList.length;
			
			Double value = new BigDecimal(length, new MathContext(2, RoundingMode.UP)).doubleValue();
			setNocValue(value);
		}
		
	}catch (JavaModelException exception1) {
		logger.error(exception1);
	}catch (NullPointerException exception2){
		logger.error(exception2);
	}
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:28,代碼來源:NumberOfChildrenJavaModel.java

示例8: testFindSetPathGeneratorInvocation

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
@Test
public void testFindSetPathGeneratorInvocation() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	IType type = compilationUnit.getAllTypes()[0];
	Map<String, List<String>> map = JDTManager.findSetPathGeneratorInvocation(project.getProject(), type);
	List<String> list = map.get("SimpleImpl");
	assertTrue (list.size()==1);
	String value = list.get(0);
	assertEquals("new RandomPath(new EdgeCoverage(100))", value);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:14,代碼來源:JDTManagerTest.java

示例9: createDtoFile

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Parse un fichier candidat de DTO.
 * 
 * @param file Fichier.
 * @param javaProject Projet Java du fichier.
 * @return Le DTO, <code>null</code> sinon.
 */
private DtoFile createDtoFile(IFile file, IJavaProject javaProject) {

	/* Charge l'AST du fichier Java. */
	ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
	if (compilationUnit == null) {
		return null;
	}
	List<String> dtoParentClassesList = LegacyManager.getInstance().getDtoParentsClasseList(javaProject.getProject());
	try {
		LegacyStrategy strategy = LegacyManager.getInstance().getStrategy(file);
		/* Parcourt les types du fichier Java. */
		for (IType type : compilationUnit.getAllTypes()) {

			/* Vérifie que c'est un Dto */
			boolean isDtoType = strategy.isDtoType(type) || JdtUtils.isSubclass(type, dtoParentClassesList);

			if (!isDtoType) {
				continue;
			}

			/* Parse les champs. */
			List<DtoField> fields = strategy.parseDtoFields(type);

			/* Créé le DtoFile. */
			String javaName = type.getElementName();
			String packageName = type.getPackageFragment().getElementName();
			ISourceRange nameRange = type.getNameRange();
			FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
			return new DtoFile(fileRegion, javaName, packageName, fields);
		}
	} catch (JavaModelException e) {
		ErrorUtils.handle(e);
	}

	return null;
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:44,代碼來源:DtoManager.java

示例10: createJavaClassFile

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Parse un fichier de classe Java.
 * 
 * @param file Fichier.
 * @param javaProject Projet Java du fichier.
 * @return Le fichier de classe Java, <code>null</code> sinon.
 */
private JavaClassFile createJavaClassFile(IFile file, IJavaProject javaProject) {

	/* Charge l'AST du fichier Java. */
	ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
	if (compilationUnit == null) {
		return null;
	}
	try {
		/* Parcourt les types du fichier Java. */
		for (IType type : compilationUnit.getAllTypes()) {

			if (!type.isClass()) {
				continue;
			}

			/* Créé le JavaClassFile. */
			String javaName = type.getElementName();
			String packageName = type.getPackageFragment().getElementName();
			ISourceRange nameRange = type.getNameRange();
			FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
			return new JavaClassFile(fileRegion, javaName, packageName);
		}
	} catch (JavaModelException e) {
		ErrorUtils.handle(e);
	}

	return null;
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:36,代碼來源:JavaClassManager.java

示例11: isUnitInProjectBuildPath

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Indique si une unité de compilation Java se trouve dans le build path de son projet.
 * 
 * @param unit Unité de compilation.
 * @return <ocde>true</code> si dans le build path de son projet.
 */
private static boolean isUnitInProjectBuildPath(ICompilationUnit unit) {
	try {
		/* Si le fichier Java n'est pas dans le buildpath de son projet, lancera une JavaModelException */
		unit.getAllTypes();
		/* Pas d'exception : le fichier est dans le build path. */
		return true;
	} catch (JavaModelException jme) { // NOSONAR
		/* Exception : le fichier n'est pas dans le build path. */
		return false;
	}
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:18,代碼來源:JdtUtils.java

示例12: visitITypes

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
private String visitITypes(ICompilationUnit unit, OutCodeVisitor visitor, Set<String> unresolvedTypes) throws JavaModelException {
	IType[] allTypes = unit.getAllTypes();
	String content = "";
	for (int i = 0; i < allTypes.length; i++) {
		IType type = allTypes[i];
		content += serializeType(unit, type, i, unresolvedTypes);
		int indentation = 1;
		content += visitIFields(unit, type, visitor, indentation, unresolvedTypes);
		content += visitIMethods(unit, type, visitor, indentation, unresolvedTypes);
		indentation -= 1;
	}
	return content;
}
 
開發者ID:ioanaverebi,項目名稱:Sparrow,代碼行數:14,代碼來源:ModelVisitor.java


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