Java Code Examples for org.eclipse.jdt.core.dom.ImportDeclaration#isStatic()

The following examples show how to use org.eclipse.jdt.core.dom.ImportDeclaration#isStatic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaTypeHierarchyExtractor.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(final CompilationUnit node) {
	if (node.getPackage() != null) {
		currentPackageName = node.getPackage().getName()
				.getFullyQualifiedName();
	}
	for (final Object decl : node.imports()) {
		final ImportDeclaration imp = (ImportDeclaration) decl;
		if (!imp.isStatic()) {
			final String fqn = imp.getName().getFullyQualifiedName();
			importedNames.put(fqn.substring(fqn.lastIndexOf('.') + 1),
					fqn);
		}
	}
	return true;
}
 
Example 2
Source File: ASTVisitors.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(final ImportDeclaration node) {
	final String qName = node.getName().getFullyQualifiedName();
	final String imprt = node.toString().trim();
	if (!node.isStatic()) {
		if (!imprt.endsWith(".*;") && qName.matches(pattern))
			fqImports.add(qName);
	} else {
		if (!imprt.endsWith(".*;") && qName.matches(pattern)) {
			final String name = qName.substring(qName.lastIndexOf('.') + 1);
			if (Character.isLowerCase(name.charAt(0)))
				fqMethodImports.add(qName);
		}
	}
	return false;
}
 
Example 3
Source File: JavaTypeHierarchyExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean visit(final CompilationUnit node) {
	if (node.getPackage() != null) {
		currentPackageName = node.getPackage().getName()
				.getFullyQualifiedName();
	}
	for (final Object decl : node.imports()) {
		final ImportDeclaration imp = (ImportDeclaration) decl;
		if (!imp.isStatic()) {
			final String fqn = imp.getName().getFullyQualifiedName();
			importedNames.put(fqn.substring(fqn.lastIndexOf('.') + 1),
					fqn);
		}
	}
	return true;
}
 
Example 4
Source File: ScopeAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Collection<String> getUsedVariableNames(int offset, int length) {
	HashSet<String> result= new HashSet<String>();
	IBinding[] bindingsBefore= getDeclarationsInScope(offset, VARIABLES);
	for (int i= 0; i < bindingsBefore.length; i++) {
		result.add(bindingsBefore[i].getName());
	}
	IBinding[] bindingsAfter= getDeclarationsAfter(offset + length, VARIABLES);
	for (int i= 0; i < bindingsAfter.length; i++) {
		result.add(bindingsAfter[i].getName());
	}
	List<ImportDeclaration> imports= fRoot.imports();
	for (int i= 0; i < imports.size(); i++) {
		ImportDeclaration decl= imports.get(i);
		if (decl.isStatic() && !decl.isOnDemand()) {
			result.add(ASTNodes.getSimpleNameIdentifier(decl.getName()));
		}
	}
	return result;
}
 
Example 5
Source File: JavaTypeHierarchyExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean visit(final CompilationUnit node) {
	if (node.getPackage() != null) {
		currentPackageName = node.getPackage().getName()
				.getFullyQualifiedName();
	}
	for (final Object decl : node.imports()) {
		final ImportDeclaration imp = (ImportDeclaration) decl;
		if (!imp.isStatic()) {
			final String fqn = imp.getName().getFullyQualifiedName();
			importedNames.put(fqn.substring(fqn.lastIndexOf('.') + 1),
					fqn);
		}
	}
	return true;
}
 
Example 6
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final ImportDeclaration it) {
  this.appendToBuffer("import ");
  boolean _isStatic = it.isStatic();
  if (_isStatic) {
    this.appendToBuffer("static ");
  }
  it.getName().accept(this);
  boolean _isOnDemand = it.isOnDemand();
  if (_isOnDemand) {
    this.appendToBuffer(".*");
  }
  this.appendLineWrapToBuffer();
  return false;
}
 
Example 7
Source File: TypeResolver.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(final ImportDeclaration node) {
	if (!node.isStatic()) {
		final String qName = node.getName().getFullyQualifiedName();
		importedNames.put(qName.substring(qName.lastIndexOf('.') + 1),
				qName);
		importsDeclarationNode.put(node.getName(), qName);
	}
	return false;
}
 
Example 8
Source File: ASTVisitors.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final ImportDeclaration node) {
	final String qName = node.getName().getFullyQualifiedName();
	final String imprt = node.toString().trim();
	if (!node.isStatic()) {
		if (imprt.endsWith(".*;") && qName.matches(pattern))
			wildcardImports.add(qName);
	} else {
		if (imprt.endsWith(".*;") && qName.matches(pattern))
			wildcardMethodImports.add(qName);
	}
	return false;
}
 
Example 9
Source File: JavaApproximateTypeInferencer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final ImportDeclaration node) {
	if (!node.isStatic()) {
		final String qName = node.getName().getFullyQualifiedName();
		importedNames.put(qName.substring(qName.lastIndexOf('.') + 1), qName);
	}
	return false;
}
 
Example 10
Source File: APICallVisitor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final ImportDeclaration node) {
	final String qName = node.getName().getFullyQualifiedName();
	if (!node.isStatic()) {
		importedNames.put(qName.substring(qName.lastIndexOf('.') + 1), qName);
	} else {
		final String name = qName.substring(qName.lastIndexOf('.') + 1);
		if (Character.isLowerCase(name.charAt(0))) // ignore constants
			methodImports.put(name, qName.substring(0, qName.lastIndexOf('.')));
	}
	return false;
}
 
Example 11
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void updateReferenceInImport(ImportDeclaration enclosingImport, ASTNode node, CompilationUnitRewrite rewrite) {
	final IBinding binding= enclosingImport.resolveBinding();
	if (binding instanceof ITypeBinding) {
		final ITypeBinding type= (ITypeBinding) binding;
		final ImportRewrite rewriter= rewrite.getImportRewrite();
		if (enclosingImport.isStatic()) {
			final String oldImport= ASTNodes.asString(node);
			final StringBuffer buffer= new StringBuffer(oldImport);
			final String typeName= fType.getDeclaringType().getElementName();
			final int index= buffer.indexOf(typeName);
			if (index >= 0) {
				buffer.delete(index, index + typeName.length() + 1);
				final String newImport= buffer.toString();
				if (enclosingImport.isOnDemand()) {
					rewriter.removeStaticImport(oldImport + ".*"); //$NON-NLS-1$
					rewriter.addStaticImport(newImport, "*", false); //$NON-NLS-1$
				} else {
					rewriter.removeStaticImport(oldImport);
					final int offset= newImport.lastIndexOf('.');
					if (offset >= 0 && offset < newImport.length() - 1) {
						rewriter.addStaticImport(newImport.substring(0, offset), newImport.substring(offset + 1), false);
					}
				}
			}
		} else
			rewriter.removeImport(type.getQualifiedName());
	}
}