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


Java FieldDeclaration類代碼示例

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


FieldDeclaration類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了FieldDeclaration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getField

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
/**
 * @param methodname
 * @return
 */
public FieldDeclaration getField(   ) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	String s = getStaticVariable ( );
	if (s==null) return null;
	parser.setSource(s.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final  CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(FieldDeclaration node) {
			field = node;
			return true;
		}
	});		 
	return field;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:ClassExtension.java

示例2: visit

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
    Type fieldType = fieldDeclaration.getType();
    int fieldModifiers = fieldDeclaration.getModifiers();
    Visibility visibility = getVisibility(fieldModifiers);
    // boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
    boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
    List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        String fieldName = fragment.getName().getIdentifier();
        final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
        attribute.setStatic(isStatic);
        attribute.setVisibility(visibility);
        attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));

        Expression expression = fragment.getInitializer();
        if (expression != null) {
            //attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
            addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
        }
        attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
    }
    return true;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:25,代碼來源:BindingsRecoveryAstVisitor.java

示例3: rewriteAST

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:57,代碼來源:AbstractSerialVersionOperation.java

示例4: visit

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration node) {

	int modifiers = node.getModifiers();
	if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
		List<VariableDeclarationFragment> fragments = node.fragments();
		for (VariableDeclarationFragment varDeclFrag : fragments) {
			IVariableBinding varBinding = varDeclFrag.resolveBinding();
			String enclosingClass = varBinding.getDeclaringClass().getQualifiedName();
			if(!varBinding.getType().isPrimitive() && !varBinding.getType().getQualifiedName().equals("java.lang.String")){
				final TACVariable fieldVar = new TACVariable(varBinding);
				if(!enclosingClass.equals(Config.MAINCLASS)){
					context.addEncapsulatedVariable(fieldVar);
				}
			}
		}
	}
	return super.visit(node);
}
 
開發者ID:aroog,項目名稱:code,代碼行數:20,代碼來源:HeuristicOwnedVisitor.java

示例5: hasFieldInitializers

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的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

示例6: createNewFieldDeclaration

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
  AST ast = getAST();
  VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
  SimpleName variableName = ast.newSimpleName(fFieldName);
  fragment.setName(variableName);
  addLinkedName(rewrite, variableName, false);
  List<Dimension> extraDimensions =
      DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
  fragment.extraDimensions().addAll(extraDimensions);
  if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()) {
    Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
    fragment.setInitializer(initializer);
  }
  FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);

  VariableDeclarationStatement vds = getTempDeclarationStatement();
  Type type = (Type) rewrite.createCopyTarget(vds.getType());
  fieldDeclaration.setType(type);
  fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
  return fieldDeclaration;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:22,代碼來源:PromoteTempToFieldRefactoring.java

示例7: visit

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
@Override
public boolean visit(VariableDeclarationFragment node) {
  boolean result = super.visit(node);
  if (isFirstSelectedNode(node)) {
    if (node.getParent() instanceof FieldDeclaration) {
      invalidSelection(
          RefactoringCoreMessages
              .ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment_from_field,
          JavaStatusContext.create(fCUnit, node));
    } else {
      invalidSelection(
          RefactoringCoreMessages
              .ExtractMethodAnalyzer_cannot_extract_variable_declaration_fragment,
          JavaStatusContext.create(fCUnit, node));
    }
    return false;
  }
  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:20,代碼來源:ExtractMethodAnalyzer.java

示例8: visit

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
	if (Modifier.isStatic(fieldDeclaration.getModifiers())) {
		testCase.setCurrentScope(TestScope.STATICFIELDS);
	}
	VariableDeclarationFragment varDeclFrgmnt = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
	Expression expression = varDeclFrgmnt.getInitializer();
	VariableReference varRef;
	if (expression == null) {
		varRef = retrieveDefaultValueAssignment(retrieveTypeClass(varDeclFrgmnt));
	} else {
		varRef = retrieveVariableReference(expression, null);
	}
	varRef.setOriginalCode(fieldDeclaration.toString());
	// TODO Use the name here as well?
	// String name = varDeclFrgmt.getName().getIdentifier();
	// new BoundVariableReferenceImpl(testCase, varType, name);
	testCase.addVariable(varDeclFrgmnt.resolveBinding(), varRef);
	testCase.setCurrentScope(TestScope.FIELDS);
	return true;
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:23,代碼來源:TestExtractingVisitor.java

示例9: visitFragment

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
private void visitFragment(VariableDeclarationFragment fragment, FieldDeclaration field) {
	Attribute attribute = importer.ensureAttributeForFragment(fragment, field);
	importer.createSourceAnchor(attribute, fragment, (CompilationUnit) field.getRoot());
	importer.ensureCommentFromBodyDeclaration(attribute, field);

	/* only the last fragment of a field contains the initializer code.
	 * thus, to create the access to each variable in the fragment we need to ask that last fragment
	 * we do not have to check the existence of that last fragment, because we already know that the field has at least one fragment */
	VariableDeclarationFragment lastFragment = (VariableDeclarationFragment) field.fragments().get(field.fragments().size() - 1);
	if (lastFragment.getInitializer() != null) {
		Access access = importer.createAccessFromExpression(fragment.getName());
		access.setIsWrite(true);
		importer.createAccessFromExpression((Expression) lastFragment.getInitializer());
	}
	attribute.setIsStub(false);
}
 
開發者ID:feenkcom,項目名稱:jdt2famix,代碼行數:17,代碼來源:AstVisitor.java

示例10: ClassModel

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
           List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
           List<TypeModel> innerTypes, List<ASTNode> modifiers) {
    groovism = provide();

    this.className = className;
    this.packageDeclaration = packageDeclaration;
    this.fields = fieldDeclarations(fields);
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
    this.imports = imports;
    this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
    if (isTestClass(methods)) {
        this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
        imports.add(0, astNodeFactory.importDeclaration(Specification.class));
    } else {
        this.superClassType = Optional.ofNullable(superClassType);
    }
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:20,代碼來源:ClassModel.java

示例11: InterfaceModel

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
InterfaceModel(String typeName, Type superClassType, PackageDeclaration packageDeclaration,
               List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
               List<ASTNode> modifiers) {
    groovism = provide();

    LinkedList<ImportDeclaration> importDeclarations = new LinkedList<>(imports);

    this.superClassType = Optional.ofNullable(superClassType).map(Object::toString);

    this.typeName = typeName;
    this.packageDeclaration = packageDeclaration;
    this.fields = unmodifiableList(new LinkedList<>(fields));
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.imports = unmodifiableList(importDeclarations);
    this.modifiers = unmodifiableList(modifiers);
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:17,代碼來源:InterfaceModel.java

示例12: visit

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的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

示例13: visit

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的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

示例14: getVisibilityModifier

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static String getVisibilityModifier(FieldDeclaration pInstanceVariableNode) {

    Iterator<Object> it = pInstanceVariableNode.modifiers().iterator();

    // Find the visibility in the modifiers
    while (it.hasNext()) {
        String modifier = it.next().toString();
        switch (modifier) {
            case "private":
                return "private";
            case "protected":
                return "protected";
            case "public":
                return "public";
            default:
                break;
        }
    }

    // No visibility found
    return null;

}
 
開發者ID:fpalomba,項目名稱:aDoctor,代碼行數:25,代碼來源:InstanceVariableParser.java

示例15: createFieldInfos

import org.eclipse.jdt.core.dom.FieldDeclaration; //導入依賴的package包/類
private List<FieldInfo> createFieldInfos(FieldDeclaration node, String belongTo) {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    Type type = node.getType();
    Set<String> types = getTypes(type);
    String typeString = type.toString();
    String visibility = getVisibility(node);
    boolean isStatic = isStatic(node);
    boolean isFinal = isFinal(node);
    String comment = "";
    if (node.getJavadoc() != null)
        comment = sourceContent.substring(node.getJavadoc().getStartPosition(), node.getJavadoc().getStartPosition() + node.getJavadoc().getLength());
    List<VariableDeclarationFragment> fragments = node.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        FieldInfo fieldInfo = new FieldInfo();
        fieldInfo.belongTo = belongTo;
        fieldInfo.name = fragment.getName().getFullyQualifiedName();
        fieldInfo.typeString = typeString;
        fieldInfo.types = types;
        fieldInfo.visibility = visibility;
        fieldInfo.isFinal = isFinal;
        fieldInfo.isStatic = isStatic;
        fieldInfo.comment = comment;
        fieldInfos.add(fieldInfo);
    }
    return fieldInfos;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:27,代碼來源:JavaASTVisitor.java


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