当前位置: 首页>>代码示例>>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;未经允许,请勿转载。