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


Java TypeDeclaration类代码示例

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


TypeDeclaration类属于org.eclipse.jdt.core.dom包,在下文中一共展示了TypeDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analyzeCompilationUnit

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
private void analyzeCompilationUnit(CompilationUnit unit, ICompilationUnit compilationUnit) {
	Set<String> filters = loadFilters();
	ASTVisitor importsVisitor = new ImportsVisitor(filters);
	unit.accept(importsVisitor);

	List types = unit.types();
	for (Iterator iter = types.iterator(); iter.hasNext();) {
		Object next = iter.next();
		if (next instanceof TypeDeclaration) {
			// declaration: Contains one file content at a time.
			TypeDeclaration declaration = (TypeDeclaration) next;
			// traverseType(declaration,true);

		}
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:GenerateDefaultMap.java

示例2: hasFieldInitializers

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
private static boolean hasFieldInitializers(TypeDeclaration typeDecl) {
	boolean returnFlag = false;
	for (FieldDeclaration fd : typeDecl.getFields()) {
		// Skip over primitive types
		if (fd.getType().isPrimitiveType() ) {
			continue;
		}
		if (fd.fragments().size() > 0)
			if (fd.fragments().get(0) instanceof VariableDeclarationFragment) {
				VariableDeclarationFragment vdf = (VariableDeclarationFragment) fd.fragments().get(0);
				if (vdf.getInitializer() != null)
					returnFlag = true;
			}
	}
	return returnFlag;
}
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:AuxJudgements.java

示例3: getBlockType

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
private BlockInfo.Type getBlockType(ASTNode node) {
	if(node instanceof TypeDeclaration)
		return BlockInfo.Type.TYPE;

	else if(node instanceof MethodDeclaration)
		return BlockInfo.Type.METHOD;

	else if(node instanceof WhileStatement)
		return BlockInfo.Type.WHILE;

	else if(node instanceof ForStatement)
		return BlockInfo.Type.FOR;

	else if(node instanceof IfStatement)
		return BlockInfo.Type.IF;
	else
		return BlockInfo.Type.OTHER;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:19,代码来源:VarParser.java

示例4: visit

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
@Override
public boolean visit(FieldDeclaration node) {
	List fragments = node.fragments();
	for(Object o : fragments) {
		VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
		String varName = frag.getName().getIdentifier();
		int line = cunit.getLineNumber(frag.getStartPosition());
		ASTNode parent = node.getParent();
		Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit));
		TypeDeclaration dec = (TypeDeclaration) node.getParent();
		String qName = dec.getName().getFullyQualifiedName();
		PackageDeclaration packageDec = cunit.getPackage();
		if(packageDec != null)
			qName = packageDec.getName().getFullyQualifiedName() + "." + qName;
		String type = !Modifier.isStatic(node.getModifiers()) ? qName : null; 
		VariableTags tags = new VariableTags(varName, type, line, scope, true);
		variables.add(tags);
	}
	return false;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:21,代码来源:TagParser.java

示例5: visit

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
@Override
public boolean visit(TypeDeclaration node) {
	System.out.println(node.getParent().getClass());
	if(info == null)
		info = new ClassInfo(node.resolveBinding().getQualifiedName(), VisibilityInfo.from(node));
	
	
	for(FieldDeclaration f : node.getFields()) {
		if(!Modifier.isStatic(f.getModifiers())) {
			for(Object o : f.fragments()) {
				VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
				info.addField(new FieldInfo(frag.getName().toString()));
			}
		}

	}

	return true;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:20,代码来源:Visitor.java

示例6: init

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
protected void init() throws JavaModelException {
    initMocks(this);
    DiContainer.clearDiContainer();

    // Override mock dependencies

    diContainerOverrides();

    // end of overrides

    DiContainer.initializeDiContainer();

    given(handlerUtilWrapper.getActivePartId(dummyExecutionEvent))
            .willReturn("org.eclipse.jdt.ui.CompilationUnitEditor");
    given(workingCopyManagerWrapper.getCurrentCompilationUnit(dummyExecutionEvent)).willReturn(iCompilationUnit);
    given(preferenceStoreProvider.providePreferenceStore()).willReturn(preferenceStore);
    given(iCompilationUnit.getBuffer()).willReturn(iBuffer);
    given(iTypeExtractor.extract(any(TypeDeclaration.class))).willReturn(empty());
    given(fullyQualifiedNameExtractor.getFullyQualifiedBaseTypeName(any(BuilderField.class))).willReturn(empty());
    setDefaultPreferenceStoreSettings();
    doNothing().when(iBuffer).setContents(outputCaptor.capture());

    DiContainer.initializeDiContainer();
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:25,代码来源:BaseBuilderGeneratorIT.java

示例7: hasConstructor

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
public static boolean hasConstructor(TypeDeclaration typeDecl, Map<ast.Type, TypeDeclaration> types,
		QualifiedClassName cThis) {
	boolean hasConstr = false;
	if (!hasFieldInitializers(typeDecl))
		hasConstr = true;
	else {
		for (MethodDeclaration md : typeDecl.getMethods()) {
			if (md.isConstructor())
				hasConstr = true;
		}
	}
	Type superclassType = typeDecl.getSuperclassType();
	if (superclassType == null)
		return hasConstr;
	if (superclassType.resolveBinding().getQualifiedName().equals(Utils.JAVA_LANG_OBJECT))
		return hasConstr;
	TypeDeclaration superTypeDecl = types.get(new QualifiedClassName(superclassType.resolveBinding(), cThis)
			.getType());
	if (superTypeDecl != null) {
		hasConstr = hasConstr && hasConstructor(superTypeDecl, types, cThis);
	}
	return hasConstr;

}
 
开发者ID:aroog,项目名称:code,代码行数:25,代码来源:AuxJudgements.java

示例8: mBody

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
/**
 * returns all method declarations in a type, and its supertype recursively.
 * call MethodDeclaration.getBody() to get the body of the method. TODO:
 * actual/formal substitution
 * */
public static Set<MethodDeclaration> mBody(TypeDeclaration typeDecl, TypeHierarchy hierarchy,
		Map<ast.Type, TypeDeclaration> types, QualifiedClassName cThis) {
	Set<MethodDeclaration> returnSet = new HashSet<MethodDeclaration>();
	for (MethodDeclaration md : typeDecl.getMethods()) {
		returnSet.add(md);
	}
	Type superclassType = typeDecl.getSuperclassType();
	if (superclassType == null)
		return returnSet;
	if (superclassType.resolveBinding().getQualifiedName().equals(Utils.JAVA_LANG_OBJECT))
		return returnSet;

	TypeDeclaration superTypeDecl = types.get(new QualifiedClassName(superclassType.resolveBinding(), cThis)
			.getType());
	if (superTypeDecl != null) {
		Set<MethodDeclaration> auxSet = mBody(superTypeDecl, hierarchy, types, cThis);
		returnSet.addAll(auxSet);
		// TODO: here you don't want to add OverrideMethod
		// TODO: find a way to uniquely identify methods: define mtype.
	}
	return returnSet;
}
 
开发者ID:aroog,项目名称:code,代码行数:28,代码来源:AuxJudgements.java

示例9: getMethodDeclaration

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
/***
 * Lookup an ast.MethodDeclaration based on className and methodName
 * 
 * @param qualifiedTypeName
 * @param methodName
 * @return ast.MethodDeclaration
 * 
 * HACK: XXX, also include in the search type of parameters. 
 * Currently the search does not distinguish between C.m and C.m(A)
 * class C{
 * 	 void m(){}
 * 	 void m(A a){}
 * }
 */
public static ast.MethodDeclaration getMethodDeclaration(String qualifiedTypeName, String methodName) {
	ast.MethodDeclaration methodDeclaration = Adapter.getInstance().getMethodDeclaration(qualifiedTypeName + methodName);
	if (methodDeclaration != null)
		return methodDeclaration;
	
	// If not found, it may not have been added yet?
	// XXX. But why not do this once?
	Collection<ast.MethodDeclaration> allNodes = Adapter.getInstance().getMethodDeclarations();
	for (ast.MethodDeclaration md : allNodes) {
		ast.TypeDeclaration td = md.enclosingType;
		if (td != null && td.type != null)
			if (td.type.getFullyQualifiedName().equals(qualifiedTypeName))
				if (md.methodName.equals(methodName)) {
					Adapter.getInstance().mapMethodDeclaration(md);
					return md;
				}
	}
	return null;		
}
 
开发者ID:aroog,项目名称:code,代码行数:34,代码来源:TraceabilityFactory.java

示例10: getClassAttributes

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
/**
 * Method to get class attributes and add them in a list.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param node
 */
@SuppressWarnings("unchecked")
private void getClassAttributes(CompilationUnit node){
	
	for (Object type : node.types()){
		if (type instanceof TypeDeclaration){
			
			FieldDeclaration [] attributes = ((TypeDeclaration) type).getFields();
			
			for (FieldDeclaration attribute: attributes){
				List<FieldDeclaration> fragments = attribute.fragments();
				Object obj = fragments.get(0);
				if (obj instanceof VariableDeclarationFragment){
					String str = ((VariableDeclarationFragment) obj).getName().toString();
					this.listOfAttributes.add(str);
				}
			}
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:26,代码来源:TightClassCohesionVisitor.java

示例11: testBuilderWithTwoSuperclassesShouldConcatenatesFieldsFromAll

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
@Test
public void testBuilderWithTwoSuperclassesShouldConcatenatesFieldsFromAll() throws Exception {
    // GIVEN
    given(iTypeExtractor.extract(any(TypeDeclaration.class)))
            .willReturn(of(firstSuperClassType))
            .willReturn(of(secondSuperClassType))
            .willReturn(empty());
    String superClassInput = readClasspathFile("superclass_test_superclass_input.tjava");
    super.setCompilationUnitInput(firstSuperClassICompilationUnit, superClassInput);

    String secondSuperClassInput = readClasspathFile("super_superclass_test_input.tjava");
    super.setCompilationUnitInput(secondSuperClassICompilationUnit, secondSuperClassInput);

    String input = readClasspathFile("superclass_test_extends_input.tjava");
    String expectedResult = readClasspathFile("superclass_with_two_superclasses_output.tjava");
    super.setInput(input);

    // WHEN
    underTest.execute(dummyExecutionEvent);

    // THEN
    super.assertEqualsJavaContents(outputCaptor.getValue(), expectedResult);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:24,代码来源:BuilderWithSuperClassFieldsE2ETest.java

示例12: beforeMethod

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
@BeforeMethod
public void beforeMethod() throws JavaModelException {
    super.init();
    underTest = new GenerateRegularBuilderHandler();

    given(firstSuperClassType.getCompilationUnit()).willReturn(firstSuperClassICompilationUnit);
    given(firstSuperClassType.getElementName()).willReturn("TestSuperClass");

    // When getting the superClass return the correct type
    typeExtractorAnswerProvider = new TypeExtractorAnswerProvider(Collections.singletonMap("TestClass", firstSuperClassType));
    given(iTypeExtractor.extract(any(TypeDeclaration.class)))
            .willAnswer(a -> typeExtractorAnswerProvider.provideAnswer(a));

    given(preferenceStore.getBoolean("org.helospark.builder.includeVisibleFieldsFromSuperclass")).willReturn(true);
    given(preferenceStore.getBoolean("org.helospark.builder.includeParametersFromSuperclassConstructor")).willReturn(true);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:17,代码来源:BuilderWithSuperConstructorE2ETest.java

示例13: generateBuilder

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
public void generateBuilder(CompilationUnitModificationDomain modificationDomain, List<StagedBuilderProperties> stagedBuilderStages) {
    AST ast = modificationDomain.getAst();
    TypeDeclaration originalType = modificationDomain.getOriginalType();
    ListRewrite listRewrite = modificationDomain.getListRewrite();

    builderRemover.removeExistingBuilderWhenNeeded(modificationDomain);

    // TODO: eventually have a better design to avoid nulls here
    List<TypeDeclaration> stageInterfaces = createStageInterfaces(modificationDomain, stagedBuilderStages);
    TypeDeclaration builderType = stagedBuilderClassCreator.createBuilderClass(modificationDomain, stagedBuilderStages, stageInterfaces);

    privateConstructorPopulator.addPrivateConstructorToCompilationUnit(ast, originalType, builderType, listRewrite, collectAllFieldsFromAllStages(stagedBuilderStages));
    stagedBuilderStaticBuilderCreatorMethodCreator.addBuilderMethodToCompilationUnit(modificationDomain, builderType, stagedBuilderStages);

    stageInterfaces.stream().forEach(stageInterface -> listRewrite.insertLast(stageInterface, null));
    listRewrite.insertLast(builderType, null);

    importPopulator.populateImports(modificationDomain);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:20,代码来源:StagedBuilderCompilationUnitGenerator.java

示例14: getTypeAnnotationParams

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration,
          String annotation) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) {
	StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
	newStringLiteral.setLiteralValue("p");

	ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);
	listRewrite.insertFirst(newStringLiteral, null);
}
SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:SaveAnnotations.java

示例15: getMethodDeclaration

import org.eclipse.jdt.core.dom.TypeDeclaration; //导入依赖的package包/类
public static MethodDeclaration getMethodDeclaration(String methodName) {
	IJavaElement javaElem = EditorUtility.getActiveEditorJavaInput();
	if (javaElem.getElementType() == IJavaElement.COMPILATION_UNIT) {
		ICompilationUnit iCompUnit = (ICompilationUnit) javaElem;
		ASTNode astNode = Crystal.getInstance()
				.getASTNodeFromCompilationUnit(iCompUnit);
		if (astNode != null
				&& astNode.getNodeType() == ASTNode.COMPILATION_UNIT) {
			CompilationUnit compUnit = (CompilationUnit) astNode;
			for (Object declaration : compUnit.types()) {
				if (declaration instanceof TypeDeclaration) {
					for (MethodDeclaration method : ((TypeDeclaration) declaration)
							.getMethods()) {
						if (methodName.contentEquals(method.getName()
								.getFullyQualifiedName())) {
							return method;
						}
					}
				}
			}
		}
	}
	return null;
}
 
开发者ID:aroog,项目名称:code,代码行数:25,代码来源:ASTUtils.java


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