当前位置: 首页>>代码示例>>Java>>正文


Java ICompilationUnit.getTypes方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.getTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getTypes方法的具体用法?Java ICompilationUnit.getTypes怎么用?Java ICompilationUnit.getTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.ICompilationUnit的用法示例。


在下文中一共展示了ICompilationUnit.getTypes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {

	final IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
	final ICompilationUnit icu = JavaUI.getWorkingCopyManager().getWorkingCopy(editorPart.getEditorInput());

	try {
		final IType type = icu.getTypes()[0];
		final List<Field> fields = new ArrayList<>();
		for (final IField field : type.getFields()) {
			final String fieldName = field.getElementName();
			final String fieldType = Signature.getSignatureSimpleName(field.getTypeSignature());
			fields.add(new Field(fieldName, fieldType));
		}

		new WizardDialog(HandlerUtil.getActiveShell(event), new BuilderGeneratorWizard(icu, fields)).open();

	}
	catch (final JavaModelException e) {
		e.printStackTrace();
	}

	return null;
}
 
开发者ID:khabali,项目名称:java-builders-generator,代码行数:25,代码来源:GenerateBuildersHandler.java

示例2: getTypeOfOpenJavaEditor

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static IType getTypeOfOpenJavaEditor() {
	IJavaElement activeEditorJavaInput = EditorUtility.getActiveEditorJavaInput();
	if (activeEditorJavaInput != null) {
		if (activeEditorJavaInput.getElementType() == IJavaElement.COMPILATION_UNIT) {
			try {
				ICompilationUnit iCompilationUnit = (ICompilationUnit) activeEditorJavaInput;
				String elementName = iCompilationUnit.getElementName();
				elementName = elementName.substring(0,
						elementName.lastIndexOf('.'));
				IType[] types = iCompilationUnit.getTypes();
				for (IType type : types) {
					String fullyQualifiedName = type
							.getFullyQualifiedName();
					if (fullyQualifiedName.contains(elementName)) {
						return type;
					}
				}
			} catch (JavaModelException e1) {
				e1.printStackTrace();
			}
		}
	} else {
		System.err.println("Java Editor is not open");
	}
	return null;
}
 
开发者ID:aroog,项目名称:code,代码行数:27,代码来源:ASTUtils.java

示例3: findReferences

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public Map<ClassInfo, List<CodeReference>> findReferences(ICompilationUnit compilationUnit) throws CoreException {
	Map<ClassInfo, List<CodeReference>> references = new HashMap<>();
	for (IType type : compilationUnit.getTypes()) {
		findReferences(type, references);
	}
	return references;
}
 
开发者ID:CenterDevice,项目名称:ClassCleaner,代码行数:8,代码来源:JavaReferenceFinder.java

示例4: setup

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
  javaProject = new JavaProjectKit();
  javaProject.enableJava5();
  final IPackageFragmentRoot root = javaProject.createSourceFolder("src");
  final ICompilationUnit compilationUnit = javaProject.createCompilationUnit(
      root, "testdata/src", "methodlocator/Samples.java");
  JavaProjectKit.waitForBuild();
  javaProject.assertNoErrors();
  methodLocator = new MethodLocator(compilationUnit.getTypes()[0]);
}
 
开发者ID:eclipse,项目名称:eclemma,代码行数:12,代码来源:MethodLocatorTest.java

示例5: setup

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
  javaProject = new JavaProjectKit();
  javaProject.enableJava5();
  final IPackageFragmentRoot root = javaProject.createSourceFolder("src");
  final ICompilationUnit compilationUnit = javaProject.createCompilationUnit(
      root, "testdata/src", "signatureresolver/Samples.java");
  JavaProjectKit.waitForBuild();
  javaProject.assertNoErrors();
  type = compilationUnit.getTypes()[0];
  createMethodIndex();
}
 
开发者ID:eclipse,项目名称:eclemma,代码行数:13,代码来源:SourceSignatureResolverTest.java

示例6: processCompilationUnit

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void processCompilationUnit(ITypeVisitor visitor,
    ICompilationUnit unit, IProgressMonitor monitor)
    throws JavaModelException {
  visitor.visit(unit);
  for (final IType type : unit.getTypes()) {
    if (monitor.isCanceled()) {
      break;
    }
    processType(visitor, new BinaryTypeName(type), type, monitor);
  }
}
 
开发者ID:eclipse,项目名称:eclemma,代码行数:12,代码来源:TypeTraverser.java

示例7: calculateValue

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
 * @see IJavaModel#calculateValue
 */
@Override
public void calculateValue(ICompilationUnit unit) {
	
	IMethod[] iMethods = null;
	IField[] iFields = null;
	try {
		IType[] iTypes = unit.getTypes();
		
		for (IType iType : iTypes){
			iMethods = iType.getMethods();
			iFields = iType.getFields();
		}
		
		if ((iFields != null && iMethods != null) && (iFields.length > 1 && iMethods.length > 1)) {
			for (IField field: iFields){
				sharedAttributesPerMethods.put(field.getElementName(), new HashSet<String>());
				nonSharedAttributesPerMethods.put(field.getElementName(), new HashSet<String>());
			}
			for (IMethod method: iMethods){
				connectedComponents.put(method.getElementName(), new HashSet<String>());
			}
			checkMethodsWithSharedAttributes(iMethods);
			
			if (LCOMType.LCOM.toString() == getLcomType()){
				setLcomValue(calculateLCOMValue());
			}else if (LCOMType.LCOM2.toString() == getLcomType()){
				setLcom2Value(calculateLCOM2Value());
			}else{
				setLcom4Value(calculateLCOM4Value());
			}
		}
	} catch (JavaModelException exception) {
		logger.error(exception);
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:39,代码来源:LackCohesionMethodsJavaModel.java

示例8: _beforeAllCompilationUnits_setRootClass

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void _beforeAllCompilationUnits_setRootClass(List<ICompilationUnit> allCompilationUnits) {
	// XXX. getReporter() still null here
	
	IType mainType = null;
	
	for (ICompilationUnit compUnit : allCompilationUnits) {
		IType[] compUnitTypes = null;

		try {
			compUnitTypes = compUnit.getTypes();
		}
		catch (JavaModelException e) {
			e.printStackTrace();
		}
		for (IType iType : compUnitTypes) {
			String typeName = iType.getFullyQualifiedName();
			// XXX. MainClass not fully qualified?
			if (typeName.endsWith(Config.MAINCLASS)) {
				mainType = iType;
				break;
			}
		}
	}
	
	if (mainType == null) {
		// XXX. Use getReporter(); but here, still null. So using System.err
		// getReporter().reportUserProblem("Cannot find main type. Specify main type in properties file", null,
		// getName());
		System.err.println("Cannot find main type. Specify main type in properties file");
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:32,代码来源:RefinementAnalysis.java

示例9: getAllClassesAndInterfaces

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void getAllClassesAndInterfaces() throws JavaModelException {
	Crystal crystal = Crystal.getInstance();
	TypeInfo typeInfo = TypeInfo.getInstance();
	if (typeInfo == null)
		return;
	
	Iterator<ICompilationUnit> compilationUnitIterator = crystal.getCompilationUnitIterator();
	if (compilationUnitIterator == null )
		return;
	
	while(compilationUnitIterator.hasNext()){
		ICompilationUnit cu = compilationUnitIterator.next();
		for(IType type :cu.getTypes()){
			String fullyQualifiedName = type.getFullyQualifiedName();
			
			Type archSumType = typeInfo.getType(fullyQualifiedName);
			// Because the OGraph will contain types for things that are created, used, etc. 
			// Some Type objects may not be already created.
			// This could cause problems when trying to use Type.getSubClasses(), etc.
			// Here, we traverse the types in the project rather than the OGraph to create the Type objects 
			
			// If this Type object was not already created then create it!
			// Make sure that initTypeStructures has been done by now
			if(archSumType == null ) {
				// archSumType = new Type(fullQualifiedName);
				ITypeBinding typeBinding = crystal.getTypeBindingFromName(fullyQualifiedName);
				if (typeBinding != null ) {
					archSumType = Type.createFrom(typeBinding);
				}
				else {
					System.err.println("Unexpected null");
				}
			}
			
			// TODO: HIGH. The rest of this work is not necessary, is it? Could cut. 
			
			if(type.isInterface()){
				allInterfaces.add(fullyQualifiedName);
				//Interfaces only
			}else if(Flags.isAbstract(type.getFlags())){
				//Abstract Classes added to interfaces set and classes set
				// XXX. This is fishy.
				allInterfaces.add(fullyQualifiedName);
				allClasses.add(fullyQualifiedName);

			}else{
				//Classes added to classes set
				allClasses.add(fullyQualifiedName);
			}
		}
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:53,代码来源:SummaryBase.java

示例10: initProjectTypes

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
 * get all types of current project 
 */
public static void initProjectTypes() {
	//This time, the way to get all types of a project is correct
	//TODO: may extend to get all inner types if possible and necessary in future study
	Crystal instance = Crystal.getInstance();
	Iterator<ICompilationUnit> compilationUnitIterator = instance
			.getCompilationUnitIterator();
	if (compilationUnitIterator != null) {
		while (compilationUnitIterator.hasNext()) {
			ICompilationUnit cu = compilationUnitIterator.next();
			try {
				for (IType type : cu.getTypes()) {
					String key = type.getFullyQualifiedName();
					// System.out.println(key);
					projectTypes.add(key);
				}
			} catch (JavaModelException e) {
				throw new RuntimeException(
						"Unexpected problem: No nodes in " + instance);
			}
		}
	}
	/*
	IWorkbenchWindow window = LoadUtils.getWindow();
	if(window!=null){
		IProject currentProject = WorkspaceUtilities.getCurrentProject(window);
		if (currentProject != null) {
			try {
				IPackageFragment[] myPackages = JavaCore.create(currentProject).getPackageFragments();
				for (IPackageFragment myPackage : myPackages) {
					for (ICompilationUnit unit : myPackage.getCompilationUnits()) {
						IPackageDeclaration[] pck = unit.getPackageDeclarations();
						for (IPackageDeclaration pack : pck) {
							String packName = pack.getElementName();
							projectPacks.add(packName+".");
						}
					}
				}
			} catch (JavaModelException e) {
				e.printStackTrace();
			}
		}
	}*/
}
 
开发者ID:aroog,项目名称:code,代码行数:47,代码来源:LogWriter.java


注:本文中的org.eclipse.jdt.core.ICompilationUnit.getTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。