當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。